{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Synthetics.Types.CanaryCodeInput where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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'
  { -- | 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 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 225 Kb.
    --
    -- For large canary scripts, we recommend that you use an S3 location
    -- instead of inputting it directly with this parameter.
    CanaryCodeInput -> Maybe Base64
zipFile :: Prelude.Maybe Data.Base64,
    -- | The entry point to use for the source code when running the canary. For
    -- canaries that use the @syn-python-selenium-1.0@ runtime or a
    -- @syn-nodejs.puppeteer@ runtime earlier than @syn-nodejs.puppeteer-3.4@,
    -- the handler must be specified as @ @/@fileName@/@.handler@. For
    -- @syn-python-selenium-1.1@, @syn-nodejs.puppeteer-3.4@, and later
    -- runtimes, the handler can be specified as
    -- @ @/@fileName@/@.@/@functionName@/@ @, or you can specify a folder where
    -- canary scripts reside as
    -- @ @/@folder@/@\/@/@fileName@/@.@/@functionName@/@ @.
    CanaryCodeInput -> Text
handler :: Prelude.Text
  }
  deriving (CanaryCodeInput -> CanaryCodeInput -> Bool
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]
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
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. 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:
--
-- '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.
--
-- '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 225 Kb.
--
-- For large canary scripts, we recommend that you use an S3 location
-- instead of inputting it directly with this parameter.--
-- -- /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.
--
-- 'handler', 'canaryCodeInput_handler' - The entry point to use for the source code when running the canary. For
-- canaries that use the @syn-python-selenium-1.0@ runtime or a
-- @syn-nodejs.puppeteer@ runtime earlier than @syn-nodejs.puppeteer-3.4@,
-- the handler must be specified as @ @/@fileName@/@.handler@. For
-- @syn-python-selenium-1.1@, @syn-nodejs.puppeteer-3.4@, and later
-- runtimes, the handler can be specified as
-- @ @/@fileName@/@.@/@functionName@/@ @, or you can specify a folder where
-- canary scripts reside as
-- @ @/@folder@/@\/@/@fileName@/@.@/@functionName@/@ @.
newCanaryCodeInput ::
  -- | 'handler'
  Prelude.Text ->
  CanaryCodeInput
newCanaryCodeInput :: Text -> CanaryCodeInput
newCanaryCodeInput Text
pHandler_ =
  CanaryCodeInput'
    { $sel:s3Bucket:CanaryCodeInput' :: Maybe Text
s3Bucket = forall a. Maybe a
Prelude.Nothing,
      $sel:s3Key:CanaryCodeInput' :: Maybe Text
s3Key = forall a. Maybe a
Prelude.Nothing,
      $sel:s3Version:CanaryCodeInput' :: Maybe Text
s3Version = forall a. Maybe a
Prelude.Nothing,
      $sel:zipFile:CanaryCodeInput' :: Maybe Base64
zipFile = forall a. Maybe a
Prelude.Nothing,
      $sel:handler:CanaryCodeInput' :: Text
handler = Text
pHandler_
    }

-- | 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 :: Lens' CanaryCodeInput (Maybe Text)
canaryCodeInput_s3Bucket = 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 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 :: Lens' CanaryCodeInput (Maybe Text)
canaryCodeInput_s3Key = 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 :: Lens' CanaryCodeInput (Maybe Text)
canaryCodeInput_s3Version = 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 225 Kb.
--
-- For large canary scripts, we recommend that you use an S3 location
-- instead of inputting it directly with this parameter.--
-- -- /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 :: Lens' CanaryCodeInput (Maybe ByteString)
canaryCodeInput_zipFile = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 Iso' Base64 ByteString
Data._Base64

-- | The entry point to use for the source code when running the canary. For
-- canaries that use the @syn-python-selenium-1.0@ runtime or a
-- @syn-nodejs.puppeteer@ runtime earlier than @syn-nodejs.puppeteer-3.4@,
-- the handler must be specified as @ @/@fileName@/@.handler@. For
-- @syn-python-selenium-1.1@, @syn-nodejs.puppeteer-3.4@, and later
-- runtimes, the handler can be specified as
-- @ @/@fileName@/@.@/@functionName@/@ @, or you can specify a folder where
-- canary scripts reside as
-- @ @/@folder@/@\/@/@fileName@/@.@/@functionName@/@ @.
canaryCodeInput_handler :: Lens.Lens' CanaryCodeInput Prelude.Text
canaryCodeInput_handler :: Lens' CanaryCodeInput Text
canaryCodeInput_handler = 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 where
  hashWithSalt :: Int -> CanaryCodeInput -> Int
hashWithSalt Int
_salt CanaryCodeInput' {Maybe Text
Maybe Base64
Text
handler :: Text
zipFile :: Maybe Base64
s3Version :: Maybe Text
s3Key :: Maybe Text
s3Bucket :: Maybe Text
$sel:handler:CanaryCodeInput' :: CanaryCodeInput -> Text
$sel:zipFile:CanaryCodeInput' :: CanaryCodeInput -> Maybe Base64
$sel:s3Version:CanaryCodeInput' :: CanaryCodeInput -> Maybe Text
$sel:s3Key:CanaryCodeInput' :: CanaryCodeInput -> Maybe Text
$sel:s3Bucket:CanaryCodeInput' :: CanaryCodeInput -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
s3Bucket
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
s3Key
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
s3Version
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Base64
zipFile
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
handler

instance Prelude.NFData CanaryCodeInput where
  rnf :: CanaryCodeInput -> ()
rnf CanaryCodeInput' {Maybe Text
Maybe Base64
Text
handler :: Text
zipFile :: Maybe Base64
s3Version :: Maybe Text
s3Key :: Maybe Text
s3Bucket :: Maybe Text
$sel:handler:CanaryCodeInput' :: CanaryCodeInput -> Text
$sel:zipFile:CanaryCodeInput' :: CanaryCodeInput -> Maybe Base64
$sel:s3Version:CanaryCodeInput' :: CanaryCodeInput -> Maybe Text
$sel:s3Key:CanaryCodeInput' :: CanaryCodeInput -> Maybe Text
$sel:s3Bucket:CanaryCodeInput' :: CanaryCodeInput -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
s3Bucket
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
s3Key
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
s3Version
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Base64
zipFile
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
handler

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