{-# 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.RegistryCredential
-- 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.RegistryCredential where

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

-- | Information about credentials that provide access to a private Docker
-- registry. When this is set:
--
-- -   @imagePullCredentialsType@ must be set to @SERVICE_ROLE@.
--
-- -   images cannot be curated or an Amazon ECR image.
--
-- For more information, see
-- <https://docs.aws.amazon.com/codebuild/latest/userguide/sample-private-registry.html Private Registry with Secrets Manager Sample for CodeBuild>.
--
-- /See:/ 'newRegistryCredential' smart constructor.
data RegistryCredential = RegistryCredential'
  { -- | The Amazon Resource Name (ARN) or name of credentials created using
    -- Secrets Manager.
    --
    -- The @credential@ can use the name of the credentials only if they exist
    -- in your current Amazon Web Services Region.
    RegistryCredential -> Text
credential :: Prelude.Text,
    -- | The service that created the credentials to access a private Docker
    -- registry. The valid value, SECRETS_MANAGER, is for Secrets Manager.
    RegistryCredential -> CredentialProviderType
credentialProvider :: CredentialProviderType
  }
  deriving (RegistryCredential -> RegistryCredential -> Bool
(RegistryCredential -> RegistryCredential -> Bool)
-> (RegistryCredential -> RegistryCredential -> Bool)
-> Eq RegistryCredential
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegistryCredential -> RegistryCredential -> Bool
$c/= :: RegistryCredential -> RegistryCredential -> Bool
== :: RegistryCredential -> RegistryCredential -> Bool
$c== :: RegistryCredential -> RegistryCredential -> Bool
Prelude.Eq, ReadPrec [RegistryCredential]
ReadPrec RegistryCredential
Int -> ReadS RegistryCredential
ReadS [RegistryCredential]
(Int -> ReadS RegistryCredential)
-> ReadS [RegistryCredential]
-> ReadPrec RegistryCredential
-> ReadPrec [RegistryCredential]
-> Read RegistryCredential
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegistryCredential]
$creadListPrec :: ReadPrec [RegistryCredential]
readPrec :: ReadPrec RegistryCredential
$creadPrec :: ReadPrec RegistryCredential
readList :: ReadS [RegistryCredential]
$creadList :: ReadS [RegistryCredential]
readsPrec :: Int -> ReadS RegistryCredential
$creadsPrec :: Int -> ReadS RegistryCredential
Prelude.Read, Int -> RegistryCredential -> ShowS
[RegistryCredential] -> ShowS
RegistryCredential -> String
(Int -> RegistryCredential -> ShowS)
-> (RegistryCredential -> String)
-> ([RegistryCredential] -> ShowS)
-> Show RegistryCredential
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegistryCredential] -> ShowS
$cshowList :: [RegistryCredential] -> ShowS
show :: RegistryCredential -> String
$cshow :: RegistryCredential -> String
showsPrec :: Int -> RegistryCredential -> ShowS
$cshowsPrec :: Int -> RegistryCredential -> ShowS
Prelude.Show, (forall x. RegistryCredential -> Rep RegistryCredential x)
-> (forall x. Rep RegistryCredential x -> RegistryCredential)
-> Generic RegistryCredential
forall x. Rep RegistryCredential x -> RegistryCredential
forall x. RegistryCredential -> Rep RegistryCredential x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegistryCredential x -> RegistryCredential
$cfrom :: forall x. RegistryCredential -> Rep RegistryCredential x
Prelude.Generic)

-- |
-- Create a value of 'RegistryCredential' 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:
--
-- 'credential', 'registryCredential_credential' - The Amazon Resource Name (ARN) or name of credentials created using
-- Secrets Manager.
--
-- The @credential@ can use the name of the credentials only if they exist
-- in your current Amazon Web Services Region.
--
-- 'credentialProvider', 'registryCredential_credentialProvider' - The service that created the credentials to access a private Docker
-- registry. The valid value, SECRETS_MANAGER, is for Secrets Manager.
newRegistryCredential ::
  -- | 'credential'
  Prelude.Text ->
  -- | 'credentialProvider'
  CredentialProviderType ->
  RegistryCredential
newRegistryCredential :: Text -> CredentialProviderType -> RegistryCredential
newRegistryCredential
  Text
pCredential_
  CredentialProviderType
pCredentialProvider_ =
    RegistryCredential' :: Text -> CredentialProviderType -> RegistryCredential
RegistryCredential'
      { $sel:credential:RegistryCredential' :: Text
credential = Text
pCredential_,
        $sel:credentialProvider:RegistryCredential' :: CredentialProviderType
credentialProvider = CredentialProviderType
pCredentialProvider_
      }

-- | The Amazon Resource Name (ARN) or name of credentials created using
-- Secrets Manager.
--
-- The @credential@ can use the name of the credentials only if they exist
-- in your current Amazon Web Services Region.
registryCredential_credential :: Lens.Lens' RegistryCredential Prelude.Text
registryCredential_credential :: (Text -> f Text) -> RegistryCredential -> f RegistryCredential
registryCredential_credential = (RegistryCredential -> Text)
-> (RegistryCredential -> Text -> RegistryCredential)
-> Lens RegistryCredential RegistryCredential Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegistryCredential' {Text
credential :: Text
$sel:credential:RegistryCredential' :: RegistryCredential -> Text
credential} -> Text
credential) (\s :: RegistryCredential
s@RegistryCredential' {} Text
a -> RegistryCredential
s {$sel:credential:RegistryCredential' :: Text
credential = Text
a} :: RegistryCredential)

-- | The service that created the credentials to access a private Docker
-- registry. The valid value, SECRETS_MANAGER, is for Secrets Manager.
registryCredential_credentialProvider :: Lens.Lens' RegistryCredential CredentialProviderType
registryCredential_credentialProvider :: (CredentialProviderType -> f CredentialProviderType)
-> RegistryCredential -> f RegistryCredential
registryCredential_credentialProvider = (RegistryCredential -> CredentialProviderType)
-> (RegistryCredential
    -> CredentialProviderType -> RegistryCredential)
-> Lens
     RegistryCredential
     RegistryCredential
     CredentialProviderType
     CredentialProviderType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegistryCredential' {CredentialProviderType
credentialProvider :: CredentialProviderType
$sel:credentialProvider:RegistryCredential' :: RegistryCredential -> CredentialProviderType
credentialProvider} -> CredentialProviderType
credentialProvider) (\s :: RegistryCredential
s@RegistryCredential' {} CredentialProviderType
a -> RegistryCredential
s {$sel:credentialProvider:RegistryCredential' :: CredentialProviderType
credentialProvider = CredentialProviderType
a} :: RegistryCredential)

instance Core.FromJSON RegistryCredential where
  parseJSON :: Value -> Parser RegistryCredential
parseJSON =
    String
-> (Object -> Parser RegistryCredential)
-> Value
-> Parser RegistryCredential
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RegistryCredential"
      ( \Object
x ->
          Text -> CredentialProviderType -> RegistryCredential
RegistryCredential'
            (Text -> CredentialProviderType -> RegistryCredential)
-> Parser Text
-> Parser (CredentialProviderType -> RegistryCredential)
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
"credential")
            Parser (CredentialProviderType -> RegistryCredential)
-> Parser CredentialProviderType -> Parser RegistryCredential
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser CredentialProviderType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"credentialProvider")
      )

instance Prelude.Hashable RegistryCredential

instance Prelude.NFData RegistryCredential

instance Core.ToJSON RegistryCredential where
  toJSON :: RegistryCredential -> Value
toJSON RegistryCredential' {Text
CredentialProviderType
credentialProvider :: CredentialProviderType
credential :: Text
$sel:credentialProvider:RegistryCredential' :: RegistryCredential -> CredentialProviderType
$sel:credential:RegistryCredential' :: RegistryCredential -> 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
"credential" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
credential),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"credentialProvider" Text -> CredentialProviderType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= CredentialProviderType
credentialProvider)
          ]
      )