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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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/batch/latest/userguide/specifying-sensitive-data.html Specifying sensitive data>
-- in the /Batch User 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 Amazon Web Services Systems Manager Parameter Store.
    --
    -- If the Amazon Web Services Systems Manager Parameter Store parameter
    -- exists in the same Region as the job 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
(Secret -> Secret -> Bool)
-> (Secret -> Secret -> Bool) -> Eq Secret
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]
(Int -> ReadS Secret)
-> ReadS [Secret]
-> ReadPrec Secret
-> ReadPrec [Secret]
-> Read 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
(Int -> Secret -> ShowS)
-> (Secret -> String) -> ([Secret] -> ShowS) -> Show Secret
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. Secret -> Rep Secret x)
-> (forall x. Rep Secret x -> Secret) -> Generic Secret
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 Amazon Web Services Systems Manager Parameter Store.
--
-- If the Amazon Web Services Systems Manager Parameter Store parameter
-- exists in the same Region as the job 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' :: Text -> Text -> Secret
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 :: (Text -> f Text) -> Secret -> f Secret
secret_name = (Secret -> Text)
-> (Secret -> Text -> Secret) -> Lens Secret Secret Text Text
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 Amazon Web Services Systems Manager Parameter Store.
--
-- If the Amazon Web Services Systems Manager Parameter Store parameter
-- exists in the same Region as the job 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 :: (Text -> f Text) -> Secret -> f Secret
secret_valueFrom = (Secret -> Text)
-> (Secret -> Text -> Secret) -> Lens Secret Secret Text Text
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 Core.FromJSON Secret where
  parseJSON :: Value -> Parser Secret
parseJSON =
    String -> (Object -> Parser Secret) -> Value -> Parser Secret
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Secret"
      ( \Object
x ->
          Text -> Text -> Secret
Secret'
            (Text -> Text -> Secret) -> Parser Text -> Parser (Text -> Secret)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"name")
            Parser (Text -> Secret) -> Parser Text -> Parser Secret
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"valueFrom")
      )

instance Prelude.Hashable Secret

instance Prelude.NFData Secret

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"valueFrom" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
valueFrom)
          ]
      )