{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Synthetics.Types.CanaryCodeInput
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Synthetics.Types.CanaryCodeInput where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Use this structure to input your script code for the canary. This
-- structure contains the Lambda handler with the location where the canary
-- should start running the script. If the script is stored in an S3
-- bucket, the bucket name, key, and version are also included. If the
-- script was passed into the canary directly, the script code is contained
-- in the value of @Zipfile@.
--
-- /See:/ 'newCanaryCodeInput' smart constructor.
data CanaryCodeInput = CanaryCodeInput'
  { -- | The S3 key of your script. For more information, see
    -- <https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingObjects.html Working with Amazon S3 Objects>.
    CanaryCodeInput -> Maybe Text
s3Key :: Prelude.Maybe Prelude.Text,
    -- | The S3 version ID of your script.
    CanaryCodeInput -> Maybe Text
s3Version :: Prelude.Maybe Prelude.Text,
    -- | If you input your canary script directly into the canary instead of
    -- referring to an S3 location, the value of this parameter is the
    -- base64-encoded contents of the .zip file that contains the script. It
    -- must be smaller than 256 Kb.
    CanaryCodeInput -> Maybe Base64
zipFile :: Prelude.Maybe Core.Base64,
    -- | If your canary script is located in S3, specify the bucket name here. Do
    -- not include @s3:\/\/@ as the start of the bucket name.
    CanaryCodeInput -> Maybe Text
s3Bucket :: Prelude.Maybe Prelude.Text,
    -- | The entry point to use for the source code when running the canary. This
    -- value must end with the string @.handler@. The string is limited to 29
    -- characters or fewer.
    CanaryCodeInput -> Text
handler :: Prelude.Text
  }
  deriving (CanaryCodeInput -> CanaryCodeInput -> Bool
(CanaryCodeInput -> CanaryCodeInput -> Bool)
-> (CanaryCodeInput -> CanaryCodeInput -> Bool)
-> Eq CanaryCodeInput
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CanaryCodeInput -> CanaryCodeInput -> Bool
$c/= :: CanaryCodeInput -> CanaryCodeInput -> Bool
== :: CanaryCodeInput -> CanaryCodeInput -> Bool
$c== :: CanaryCodeInput -> CanaryCodeInput -> Bool
Prelude.Eq, ReadPrec [CanaryCodeInput]
ReadPrec CanaryCodeInput
Int -> ReadS CanaryCodeInput
ReadS [CanaryCodeInput]
(Int -> ReadS CanaryCodeInput)
-> ReadS [CanaryCodeInput]
-> ReadPrec CanaryCodeInput
-> ReadPrec [CanaryCodeInput]
-> Read CanaryCodeInput
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CanaryCodeInput]
$creadListPrec :: ReadPrec [CanaryCodeInput]
readPrec :: ReadPrec CanaryCodeInput
$creadPrec :: ReadPrec CanaryCodeInput
readList :: ReadS [CanaryCodeInput]
$creadList :: ReadS [CanaryCodeInput]
readsPrec :: Int -> ReadS CanaryCodeInput
$creadsPrec :: Int -> ReadS CanaryCodeInput
Prelude.Read, Int -> CanaryCodeInput -> ShowS
[CanaryCodeInput] -> ShowS
CanaryCodeInput -> String
(Int -> CanaryCodeInput -> ShowS)
-> (CanaryCodeInput -> String)
-> ([CanaryCodeInput] -> ShowS)
-> Show CanaryCodeInput
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CanaryCodeInput] -> ShowS
$cshowList :: [CanaryCodeInput] -> ShowS
show :: CanaryCodeInput -> String
$cshow :: CanaryCodeInput -> String
showsPrec :: Int -> CanaryCodeInput -> ShowS
$cshowsPrec :: Int -> CanaryCodeInput -> ShowS
Prelude.Show, (forall x. CanaryCodeInput -> Rep CanaryCodeInput x)
-> (forall x. Rep CanaryCodeInput x -> CanaryCodeInput)
-> Generic CanaryCodeInput
forall x. Rep CanaryCodeInput x -> CanaryCodeInput
forall x. CanaryCodeInput -> Rep CanaryCodeInput x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CanaryCodeInput x -> CanaryCodeInput
$cfrom :: forall x. CanaryCodeInput -> Rep CanaryCodeInput x
Prelude.Generic)

-- |
-- Create a value of 'CanaryCodeInput' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 's3Key', 'canaryCodeInput_s3Key' - The S3 key of your script. For more information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingObjects.html Working with Amazon S3 Objects>.
--
-- 's3Version', 'canaryCodeInput_s3Version' - The S3 version ID of your script.
--
-- 'zipFile', 'canaryCodeInput_zipFile' - If you input your canary script directly into the canary instead of
-- referring to an S3 location, the value of this parameter is the
-- base64-encoded contents of the .zip file that contains the script. It
-- must be smaller than 256 Kb.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
--
-- 's3Bucket', 'canaryCodeInput_s3Bucket' - If your canary script is located in S3, specify the bucket name here. Do
-- not include @s3:\/\/@ as the start of the bucket name.
--
-- 'handler', 'canaryCodeInput_handler' - The entry point to use for the source code when running the canary. This
-- value must end with the string @.handler@. The string is limited to 29
-- characters or fewer.
newCanaryCodeInput ::
  -- | 'handler'
  Prelude.Text ->
  CanaryCodeInput
newCanaryCodeInput :: Text -> CanaryCodeInput
newCanaryCodeInput Text
pHandler_ =
  CanaryCodeInput' :: Maybe Text
-> Maybe Text
-> Maybe Base64
-> Maybe Text
-> Text
-> CanaryCodeInput
CanaryCodeInput'
    { $sel:s3Key:CanaryCodeInput' :: Maybe Text
s3Key = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:s3Version:CanaryCodeInput' :: Maybe Text
s3Version = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:zipFile:CanaryCodeInput' :: Maybe Base64
zipFile = Maybe Base64
forall a. Maybe a
Prelude.Nothing,
      $sel:s3Bucket:CanaryCodeInput' :: Maybe Text
s3Bucket = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:handler:CanaryCodeInput' :: Text
handler = Text
pHandler_
    }

-- | The S3 key of your script. For more information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingObjects.html Working with Amazon S3 Objects>.
canaryCodeInput_s3Key :: Lens.Lens' CanaryCodeInput (Prelude.Maybe Prelude.Text)
canaryCodeInput_s3Key :: (Maybe Text -> f (Maybe Text))
-> CanaryCodeInput -> f CanaryCodeInput
canaryCodeInput_s3Key = (CanaryCodeInput -> Maybe Text)
-> (CanaryCodeInput -> Maybe Text -> CanaryCodeInput)
-> Lens CanaryCodeInput CanaryCodeInput (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CanaryCodeInput' {Maybe Text
s3Key :: Maybe Text
$sel:s3Key:CanaryCodeInput' :: CanaryCodeInput -> Maybe Text
s3Key} -> Maybe Text
s3Key) (\s :: CanaryCodeInput
s@CanaryCodeInput' {} Maybe Text
a -> CanaryCodeInput
s {$sel:s3Key:CanaryCodeInput' :: Maybe Text
s3Key = Maybe Text
a} :: CanaryCodeInput)

-- | The S3 version ID of your script.
canaryCodeInput_s3Version :: Lens.Lens' CanaryCodeInput (Prelude.Maybe Prelude.Text)
canaryCodeInput_s3Version :: (Maybe Text -> f (Maybe Text))
-> CanaryCodeInput -> f CanaryCodeInput
canaryCodeInput_s3Version = (CanaryCodeInput -> Maybe Text)
-> (CanaryCodeInput -> Maybe Text -> CanaryCodeInput)
-> Lens CanaryCodeInput CanaryCodeInput (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CanaryCodeInput' {Maybe Text
s3Version :: Maybe Text
$sel:s3Version:CanaryCodeInput' :: CanaryCodeInput -> Maybe Text
s3Version} -> Maybe Text
s3Version) (\s :: CanaryCodeInput
s@CanaryCodeInput' {} Maybe Text
a -> CanaryCodeInput
s {$sel:s3Version:CanaryCodeInput' :: Maybe Text
s3Version = Maybe Text
a} :: CanaryCodeInput)

-- | If you input your canary script directly into the canary instead of
-- referring to an S3 location, the value of this parameter is the
-- base64-encoded contents of the .zip file that contains the script. It
-- must be smaller than 256 Kb.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
canaryCodeInput_zipFile :: Lens.Lens' CanaryCodeInput (Prelude.Maybe Prelude.ByteString)
canaryCodeInput_zipFile :: (Maybe ByteString -> f (Maybe ByteString))
-> CanaryCodeInput -> f CanaryCodeInput
canaryCodeInput_zipFile = (CanaryCodeInput -> Maybe Base64)
-> (CanaryCodeInput -> Maybe Base64 -> CanaryCodeInput)
-> Lens
     CanaryCodeInput CanaryCodeInput (Maybe Base64) (Maybe Base64)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CanaryCodeInput' {Maybe Base64
zipFile :: Maybe Base64
$sel:zipFile:CanaryCodeInput' :: CanaryCodeInput -> Maybe Base64
zipFile} -> Maybe Base64
zipFile) (\s :: CanaryCodeInput
s@CanaryCodeInput' {} Maybe Base64
a -> CanaryCodeInput
s {$sel:zipFile:CanaryCodeInput' :: Maybe Base64
zipFile = Maybe Base64
a} :: CanaryCodeInput) ((Maybe Base64 -> f (Maybe Base64))
 -> CanaryCodeInput -> f CanaryCodeInput)
-> ((Maybe ByteString -> f (Maybe ByteString))
    -> Maybe Base64 -> f (Maybe Base64))
-> (Maybe ByteString -> f (Maybe ByteString))
-> CanaryCodeInput
-> f CanaryCodeInput
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso Base64 Base64 ByteString ByteString
-> Iso
     (Maybe Base64) (Maybe Base64) (Maybe ByteString) (Maybe ByteString)
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso Base64 Base64 ByteString ByteString
Iso' Base64 ByteString
Core._Base64

-- | If your canary script is located in S3, specify the bucket name here. Do
-- not include @s3:\/\/@ as the start of the bucket name.
canaryCodeInput_s3Bucket :: Lens.Lens' CanaryCodeInput (Prelude.Maybe Prelude.Text)
canaryCodeInput_s3Bucket :: (Maybe Text -> f (Maybe Text))
-> CanaryCodeInput -> f CanaryCodeInput
canaryCodeInput_s3Bucket = (CanaryCodeInput -> Maybe Text)
-> (CanaryCodeInput -> Maybe Text -> CanaryCodeInput)
-> Lens CanaryCodeInput CanaryCodeInput (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CanaryCodeInput' {Maybe Text
s3Bucket :: Maybe Text
$sel:s3Bucket:CanaryCodeInput' :: CanaryCodeInput -> Maybe Text
s3Bucket} -> Maybe Text
s3Bucket) (\s :: CanaryCodeInput
s@CanaryCodeInput' {} Maybe Text
a -> CanaryCodeInput
s {$sel:s3Bucket:CanaryCodeInput' :: Maybe Text
s3Bucket = Maybe Text
a} :: CanaryCodeInput)

-- | The entry point to use for the source code when running the canary. This
-- value must end with the string @.handler@. The string is limited to 29
-- characters or fewer.
canaryCodeInput_handler :: Lens.Lens' CanaryCodeInput Prelude.Text
canaryCodeInput_handler :: (Text -> f Text) -> CanaryCodeInput -> f CanaryCodeInput
canaryCodeInput_handler = (CanaryCodeInput -> Text)
-> (CanaryCodeInput -> Text -> CanaryCodeInput)
-> Lens CanaryCodeInput CanaryCodeInput Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CanaryCodeInput' {Text
handler :: Text
$sel:handler:CanaryCodeInput' :: CanaryCodeInput -> Text
handler} -> Text
handler) (\s :: CanaryCodeInput
s@CanaryCodeInput' {} Text
a -> CanaryCodeInput
s {$sel:handler:CanaryCodeInput' :: Text
handler = Text
a} :: CanaryCodeInput)

instance Prelude.Hashable CanaryCodeInput

instance Prelude.NFData CanaryCodeInput

instance Core.ToJSON CanaryCodeInput where
  toJSON :: CanaryCodeInput -> Value
toJSON CanaryCodeInput' {Maybe Text
Maybe Base64
Text
handler :: Text
s3Bucket :: Maybe Text
zipFile :: Maybe Base64
s3Version :: Maybe Text
s3Key :: Maybe Text
$sel:handler:CanaryCodeInput' :: CanaryCodeInput -> Text
$sel:s3Bucket:CanaryCodeInput' :: CanaryCodeInput -> Maybe Text
$sel:zipFile:CanaryCodeInput' :: CanaryCodeInput -> Maybe Base64
$sel:s3Version:CanaryCodeInput' :: CanaryCodeInput -> Maybe Text
$sel:s3Key:CanaryCodeInput' :: CanaryCodeInput -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"S3Key" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
s3Key,
            (Text
"S3Version" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
s3Version,
            (Text
"ZipFile" Text -> Base64 -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Base64 -> Pair) -> Maybe Base64 -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Base64
zipFile,
            (Text
"S3Bucket" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
s3Bucket,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Handler" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
handler)
          ]
      )