{-# 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.ECS.Types.Secret
-- 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.ECS.Types.Secret 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

-- | An object representing the secret to expose to your container. Secrets
-- can be exposed to a container in the following ways:
--
-- -   To inject sensitive data into your containers as environment
--     variables, use the @secrets@ container definition parameter.
--
-- -   To reference sensitive information in the log configuration of a
--     container, use the @secretOptions@ container definition parameter.
--
-- For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data.html Specifying sensitive data>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- /See:/ 'newSecret' smart constructor.
data Secret = Secret'
  { -- | The name of the secret.
    Secret -> Text
name :: Prelude.Text,
    -- | The secret to expose to the container. The supported values are either
    -- the full ARN of the Secrets Manager secret or the full ARN of the
    -- parameter in the SSM Parameter Store.
    --
    -- For information about the require Identity and Access Management
    -- permissions, see
    -- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data-secrets.html#secrets-iam Required IAM permissions for Amazon ECS secrets>
    -- (for Secrets Manager) or
    -- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data-parameters.html Required IAM permissions for Amazon ECS secrets>
    -- (for Systems Manager Parameter store) in the /Amazon Elastic Container
    -- Service Developer Guide/.
    --
    -- If the SSM Parameter Store parameter exists in the same Region as the
    -- task you\'re launching, then you can use either the full ARN or name of
    -- the parameter. If the parameter exists in a different Region, then the
    -- full ARN must be specified.
    Secret -> Text
valueFrom :: Prelude.Text
  }
  deriving (Secret -> Secret -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Secret -> Secret -> Bool
$c/= :: Secret -> Secret -> Bool
== :: Secret -> Secret -> Bool
$c== :: Secret -> Secret -> Bool
Prelude.Eq, ReadPrec [Secret]
ReadPrec Secret
Int -> ReadS Secret
ReadS [Secret]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Secret]
$creadListPrec :: ReadPrec [Secret]
readPrec :: ReadPrec Secret
$creadPrec :: ReadPrec Secret
readList :: ReadS [Secret]
$creadList :: ReadS [Secret]
readsPrec :: Int -> ReadS Secret
$creadsPrec :: Int -> ReadS Secret
Prelude.Read, Int -> Secret -> ShowS
[Secret] -> ShowS
Secret -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Secret] -> ShowS
$cshowList :: [Secret] -> ShowS
show :: Secret -> String
$cshow :: Secret -> String
showsPrec :: Int -> Secret -> ShowS
$cshowsPrec :: Int -> Secret -> ShowS
Prelude.Show, forall x. Rep Secret x -> Secret
forall x. Secret -> Rep Secret x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Secret x -> Secret
$cfrom :: forall x. Secret -> Rep Secret x
Prelude.Generic)

-- |
-- Create a value of 'Secret' 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:
--
-- 'name', 'secret_name' - The name of the secret.
--
-- 'valueFrom', 'secret_valueFrom' - The secret to expose to the container. The supported values are either
-- the full ARN of the Secrets Manager secret or the full ARN of the
-- parameter in the SSM Parameter Store.
--
-- For information about the require Identity and Access Management
-- permissions, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data-secrets.html#secrets-iam Required IAM permissions for Amazon ECS secrets>
-- (for Secrets Manager) or
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data-parameters.html Required IAM permissions for Amazon ECS secrets>
-- (for Systems Manager Parameter store) in the /Amazon Elastic Container
-- Service Developer Guide/.
--
-- If the SSM Parameter Store parameter exists in the same Region as the
-- task you\'re launching, then you can use either the full ARN or name of
-- the parameter. If the parameter exists in a different Region, then the
-- full ARN must be specified.
newSecret ::
  -- | 'name'
  Prelude.Text ->
  -- | 'valueFrom'
  Prelude.Text ->
  Secret
newSecret :: Text -> Text -> Secret
newSecret Text
pName_ Text
pValueFrom_ =
  Secret' {$sel:name:Secret' :: Text
name = Text
pName_, $sel:valueFrom:Secret' :: Text
valueFrom = Text
pValueFrom_}

-- | The name of the secret.
secret_name :: Lens.Lens' Secret Prelude.Text
secret_name :: Lens' Secret Text
secret_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Secret' {Text
name :: Text
$sel:name:Secret' :: Secret -> Text
name} -> Text
name) (\s :: Secret
s@Secret' {} Text
a -> Secret
s {$sel:name:Secret' :: Text
name = Text
a} :: Secret)

-- | The secret to expose to the container. The supported values are either
-- the full ARN of the Secrets Manager secret or the full ARN of the
-- parameter in the SSM Parameter Store.
--
-- For information about the require Identity and Access Management
-- permissions, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data-secrets.html#secrets-iam Required IAM permissions for Amazon ECS secrets>
-- (for Secrets Manager) or
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data-parameters.html Required IAM permissions for Amazon ECS secrets>
-- (for Systems Manager Parameter store) in the /Amazon Elastic Container
-- Service Developer Guide/.
--
-- If the SSM Parameter Store parameter exists in the same Region as the
-- task you\'re launching, then you can use either the full ARN or name of
-- the parameter. If the parameter exists in a different Region, then the
-- full ARN must be specified.
secret_valueFrom :: Lens.Lens' Secret Prelude.Text
secret_valueFrom :: Lens' Secret Text
secret_valueFrom = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Secret' {Text
valueFrom :: Text
$sel:valueFrom:Secret' :: Secret -> Text
valueFrom} -> Text
valueFrom) (\s :: Secret
s@Secret' {} Text
a -> Secret
s {$sel:valueFrom:Secret' :: Text
valueFrom = Text
a} :: Secret)

instance Data.FromJSON Secret where
  parseJSON :: Value -> Parser Secret
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Secret"
      ( \Object
x ->
          Text -> Text -> Secret
Secret'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"valueFrom")
      )

instance Prelude.Hashable Secret where
  hashWithSalt :: Int -> Secret -> Int
hashWithSalt Int
_salt Secret' {Text
valueFrom :: Text
name :: Text
$sel:valueFrom:Secret' :: Secret -> Text
$sel:name:Secret' :: Secret -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
valueFrom

instance Prelude.NFData Secret where
  rnf :: Secret -> ()
rnf Secret' {Text
valueFrom :: Text
name :: Text
$sel:valueFrom:Secret' :: Secret -> Text
$sel:name:Secret' :: Secret -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
valueFrom

instance Data.ToJSON Secret where
  toJSON :: Secret -> Value
toJSON Secret' {Text
valueFrom :: Text
name :: Text
$sel:valueFrom:Secret' :: Secret -> Text
$sel:name:Secret' :: Secret -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"valueFrom" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
valueFrom)
          ]
      )