{-# 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.CodeBuild.Types.EnvironmentVariable
-- 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.CodeBuild.Types.EnvironmentVariable where

import Amazonka.CodeBuild.Types.EnvironmentVariableType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about an environment variable for a build project or a
-- build.
--
-- /See:/ 'newEnvironmentVariable' smart constructor.
data EnvironmentVariable = EnvironmentVariable'
  { -- | The type of environment variable. Valid values include:
    --
    -- -   @PARAMETER_STORE@: An environment variable stored in Systems Manager
    --     Parameter Store. To learn how to specify a parameter store
    --     environment variable, see
    --     <https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec.env.parameter-store env\/parameter-store>
    --     in the /CodeBuild User Guide/.
    --
    -- -   @PLAINTEXT@: An environment variable in plain text format. This is
    --     the default value.
    --
    -- -   @SECRETS_MANAGER@: An environment variable stored in Secrets
    --     Manager. To learn how to specify a secrets manager environment
    --     variable, see
    --     <https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec.env.secrets-manager env\/secrets-manager>
    --     in the /CodeBuild User Guide/.
    EnvironmentVariable -> Maybe EnvironmentVariableType
type' :: Prelude.Maybe EnvironmentVariableType,
    -- | The name or key of the environment variable.
    EnvironmentVariable -> Text
name :: Prelude.Text,
    -- | The value of the environment variable.
    --
    -- We strongly discourage the use of @PLAINTEXT@ environment variables to
    -- store sensitive values, especially Amazon Web Services secret key IDs
    -- and secret access keys. @PLAINTEXT@ environment variables can be
    -- displayed in plain text using the CodeBuild console and the CLI. For
    -- sensitive values, we recommend you use an environment variable of type
    -- @PARAMETER_STORE@ or @SECRETS_MANAGER@.
    EnvironmentVariable -> Text
value :: Prelude.Text
  }
  deriving (EnvironmentVariable -> EnvironmentVariable -> Bool
(EnvironmentVariable -> EnvironmentVariable -> Bool)
-> (EnvironmentVariable -> EnvironmentVariable -> Bool)
-> Eq EnvironmentVariable
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnvironmentVariable -> EnvironmentVariable -> Bool
$c/= :: EnvironmentVariable -> EnvironmentVariable -> Bool
== :: EnvironmentVariable -> EnvironmentVariable -> Bool
$c== :: EnvironmentVariable -> EnvironmentVariable -> Bool
Prelude.Eq, ReadPrec [EnvironmentVariable]
ReadPrec EnvironmentVariable
Int -> ReadS EnvironmentVariable
ReadS [EnvironmentVariable]
(Int -> ReadS EnvironmentVariable)
-> ReadS [EnvironmentVariable]
-> ReadPrec EnvironmentVariable
-> ReadPrec [EnvironmentVariable]
-> Read EnvironmentVariable
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EnvironmentVariable]
$creadListPrec :: ReadPrec [EnvironmentVariable]
readPrec :: ReadPrec EnvironmentVariable
$creadPrec :: ReadPrec EnvironmentVariable
readList :: ReadS [EnvironmentVariable]
$creadList :: ReadS [EnvironmentVariable]
readsPrec :: Int -> ReadS EnvironmentVariable
$creadsPrec :: Int -> ReadS EnvironmentVariable
Prelude.Read, Int -> EnvironmentVariable -> ShowS
[EnvironmentVariable] -> ShowS
EnvironmentVariable -> String
(Int -> EnvironmentVariable -> ShowS)
-> (EnvironmentVariable -> String)
-> ([EnvironmentVariable] -> ShowS)
-> Show EnvironmentVariable
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EnvironmentVariable] -> ShowS
$cshowList :: [EnvironmentVariable] -> ShowS
show :: EnvironmentVariable -> String
$cshow :: EnvironmentVariable -> String
showsPrec :: Int -> EnvironmentVariable -> ShowS
$cshowsPrec :: Int -> EnvironmentVariable -> ShowS
Prelude.Show, (forall x. EnvironmentVariable -> Rep EnvironmentVariable x)
-> (forall x. Rep EnvironmentVariable x -> EnvironmentVariable)
-> Generic EnvironmentVariable
forall x. Rep EnvironmentVariable x -> EnvironmentVariable
forall x. EnvironmentVariable -> Rep EnvironmentVariable x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EnvironmentVariable x -> EnvironmentVariable
$cfrom :: forall x. EnvironmentVariable -> Rep EnvironmentVariable x
Prelude.Generic)

-- |
-- Create a value of 'EnvironmentVariable' 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:
--
-- 'type'', 'environmentVariable_type' - The type of environment variable. Valid values include:
--
-- -   @PARAMETER_STORE@: An environment variable stored in Systems Manager
--     Parameter Store. To learn how to specify a parameter store
--     environment variable, see
--     <https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec.env.parameter-store env\/parameter-store>
--     in the /CodeBuild User Guide/.
--
-- -   @PLAINTEXT@: An environment variable in plain text format. This is
--     the default value.
--
-- -   @SECRETS_MANAGER@: An environment variable stored in Secrets
--     Manager. To learn how to specify a secrets manager environment
--     variable, see
--     <https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec.env.secrets-manager env\/secrets-manager>
--     in the /CodeBuild User Guide/.
--
-- 'name', 'environmentVariable_name' - The name or key of the environment variable.
--
-- 'value', 'environmentVariable_value' - The value of the environment variable.
--
-- We strongly discourage the use of @PLAINTEXT@ environment variables to
-- store sensitive values, especially Amazon Web Services secret key IDs
-- and secret access keys. @PLAINTEXT@ environment variables can be
-- displayed in plain text using the CodeBuild console and the CLI. For
-- sensitive values, we recommend you use an environment variable of type
-- @PARAMETER_STORE@ or @SECRETS_MANAGER@.
newEnvironmentVariable ::
  -- | 'name'
  Prelude.Text ->
  -- | 'value'
  Prelude.Text ->
  EnvironmentVariable
newEnvironmentVariable :: Text -> Text -> EnvironmentVariable
newEnvironmentVariable Text
pName_ Text
pValue_ =
  EnvironmentVariable' :: Maybe EnvironmentVariableType
-> Text -> Text -> EnvironmentVariable
EnvironmentVariable'
    { $sel:type':EnvironmentVariable' :: Maybe EnvironmentVariableType
type' = Maybe EnvironmentVariableType
forall a. Maybe a
Prelude.Nothing,
      $sel:name:EnvironmentVariable' :: Text
name = Text
pName_,
      $sel:value:EnvironmentVariable' :: Text
value = Text
pValue_
    }

-- | The type of environment variable. Valid values include:
--
-- -   @PARAMETER_STORE@: An environment variable stored in Systems Manager
--     Parameter Store. To learn how to specify a parameter store
--     environment variable, see
--     <https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec.env.parameter-store env\/parameter-store>
--     in the /CodeBuild User Guide/.
--
-- -   @PLAINTEXT@: An environment variable in plain text format. This is
--     the default value.
--
-- -   @SECRETS_MANAGER@: An environment variable stored in Secrets
--     Manager. To learn how to specify a secrets manager environment
--     variable, see
--     <https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec.env.secrets-manager env\/secrets-manager>
--     in the /CodeBuild User Guide/.
environmentVariable_type :: Lens.Lens' EnvironmentVariable (Prelude.Maybe EnvironmentVariableType)
environmentVariable_type :: (Maybe EnvironmentVariableType
 -> f (Maybe EnvironmentVariableType))
-> EnvironmentVariable -> f EnvironmentVariable
environmentVariable_type = (EnvironmentVariable -> Maybe EnvironmentVariableType)
-> (EnvironmentVariable
    -> Maybe EnvironmentVariableType -> EnvironmentVariable)
-> Lens
     EnvironmentVariable
     EnvironmentVariable
     (Maybe EnvironmentVariableType)
     (Maybe EnvironmentVariableType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnvironmentVariable' {Maybe EnvironmentVariableType
type' :: Maybe EnvironmentVariableType
$sel:type':EnvironmentVariable' :: EnvironmentVariable -> Maybe EnvironmentVariableType
type'} -> Maybe EnvironmentVariableType
type') (\s :: EnvironmentVariable
s@EnvironmentVariable' {} Maybe EnvironmentVariableType
a -> EnvironmentVariable
s {$sel:type':EnvironmentVariable' :: Maybe EnvironmentVariableType
type' = Maybe EnvironmentVariableType
a} :: EnvironmentVariable)

-- | The name or key of the environment variable.
environmentVariable_name :: Lens.Lens' EnvironmentVariable Prelude.Text
environmentVariable_name :: (Text -> f Text) -> EnvironmentVariable -> f EnvironmentVariable
environmentVariable_name = (EnvironmentVariable -> Text)
-> (EnvironmentVariable -> Text -> EnvironmentVariable)
-> Lens EnvironmentVariable EnvironmentVariable Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnvironmentVariable' {Text
name :: Text
$sel:name:EnvironmentVariable' :: EnvironmentVariable -> Text
name} -> Text
name) (\s :: EnvironmentVariable
s@EnvironmentVariable' {} Text
a -> EnvironmentVariable
s {$sel:name:EnvironmentVariable' :: Text
name = Text
a} :: EnvironmentVariable)

-- | The value of the environment variable.
--
-- We strongly discourage the use of @PLAINTEXT@ environment variables to
-- store sensitive values, especially Amazon Web Services secret key IDs
-- and secret access keys. @PLAINTEXT@ environment variables can be
-- displayed in plain text using the CodeBuild console and the CLI. For
-- sensitive values, we recommend you use an environment variable of type
-- @PARAMETER_STORE@ or @SECRETS_MANAGER@.
environmentVariable_value :: Lens.Lens' EnvironmentVariable Prelude.Text
environmentVariable_value :: (Text -> f Text) -> EnvironmentVariable -> f EnvironmentVariable
environmentVariable_value = (EnvironmentVariable -> Text)
-> (EnvironmentVariable -> Text -> EnvironmentVariable)
-> Lens EnvironmentVariable EnvironmentVariable Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnvironmentVariable' {Text
value :: Text
$sel:value:EnvironmentVariable' :: EnvironmentVariable -> Text
value} -> Text
value) (\s :: EnvironmentVariable
s@EnvironmentVariable' {} Text
a -> EnvironmentVariable
s {$sel:value:EnvironmentVariable' :: Text
value = Text
a} :: EnvironmentVariable)

instance Core.FromJSON EnvironmentVariable where
  parseJSON :: Value -> Parser EnvironmentVariable
parseJSON =
    String
-> (Object -> Parser EnvironmentVariable)
-> Value
-> Parser EnvironmentVariable
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EnvironmentVariable"
      ( \Object
x ->
          Maybe EnvironmentVariableType
-> Text -> Text -> EnvironmentVariable
EnvironmentVariable'
            (Maybe EnvironmentVariableType
 -> Text -> Text -> EnvironmentVariable)
-> Parser (Maybe EnvironmentVariableType)
-> Parser (Text -> Text -> EnvironmentVariable)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe EnvironmentVariableType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"type")
            Parser (Text -> Text -> EnvironmentVariable)
-> Parser Text -> Parser (Text -> EnvironmentVariable)
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
"name")
            Parser (Text -> EnvironmentVariable)
-> Parser Text -> Parser EnvironmentVariable
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
"value")
      )

instance Prelude.Hashable EnvironmentVariable

instance Prelude.NFData EnvironmentVariable

instance Core.ToJSON EnvironmentVariable where
  toJSON :: EnvironmentVariable -> Value
toJSON EnvironmentVariable' {Maybe EnvironmentVariableType
Text
value :: Text
name :: Text
type' :: Maybe EnvironmentVariableType
$sel:value:EnvironmentVariable' :: EnvironmentVariable -> Text
$sel:name:EnvironmentVariable' :: EnvironmentVariable -> Text
$sel:type':EnvironmentVariable' :: EnvironmentVariable -> Maybe EnvironmentVariableType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"type" Text -> EnvironmentVariableType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (EnvironmentVariableType -> Pair)
-> Maybe EnvironmentVariableType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EnvironmentVariableType
type',
            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
"value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
value)
          ]
      )