{-# 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.SageMaker.Types.GitConfig
-- 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.SageMaker.Types.GitConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies configuration details for a Git repository in your Amazon Web
-- Services account.
--
-- /See:/ 'newGitConfig' smart constructor.
data GitConfig = GitConfig'
  { -- | The default branch for the Git repository.
    GitConfig -> Maybe Text
branch :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the Amazon Web Services Secrets
    -- Manager secret that contains the credentials used to access the git
    -- repository. The secret must have a staging label of @AWSCURRENT@ and
    -- must be in the following format:
    --
    -- @{\"username\": UserName, \"password\": Password}@
    GitConfig -> Maybe Text
secretArn :: Prelude.Maybe Prelude.Text,
    -- | The URL where the Git repository is located.
    GitConfig -> Text
repositoryUrl :: Prelude.Text
  }
  deriving (GitConfig -> GitConfig -> Bool
(GitConfig -> GitConfig -> Bool)
-> (GitConfig -> GitConfig -> Bool) -> Eq GitConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GitConfig -> GitConfig -> Bool
$c/= :: GitConfig -> GitConfig -> Bool
== :: GitConfig -> GitConfig -> Bool
$c== :: GitConfig -> GitConfig -> Bool
Prelude.Eq, ReadPrec [GitConfig]
ReadPrec GitConfig
Int -> ReadS GitConfig
ReadS [GitConfig]
(Int -> ReadS GitConfig)
-> ReadS [GitConfig]
-> ReadPrec GitConfig
-> ReadPrec [GitConfig]
-> Read GitConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GitConfig]
$creadListPrec :: ReadPrec [GitConfig]
readPrec :: ReadPrec GitConfig
$creadPrec :: ReadPrec GitConfig
readList :: ReadS [GitConfig]
$creadList :: ReadS [GitConfig]
readsPrec :: Int -> ReadS GitConfig
$creadsPrec :: Int -> ReadS GitConfig
Prelude.Read, Int -> GitConfig -> ShowS
[GitConfig] -> ShowS
GitConfig -> String
(Int -> GitConfig -> ShowS)
-> (GitConfig -> String)
-> ([GitConfig] -> ShowS)
-> Show GitConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GitConfig] -> ShowS
$cshowList :: [GitConfig] -> ShowS
show :: GitConfig -> String
$cshow :: GitConfig -> String
showsPrec :: Int -> GitConfig -> ShowS
$cshowsPrec :: Int -> GitConfig -> ShowS
Prelude.Show, (forall x. GitConfig -> Rep GitConfig x)
-> (forall x. Rep GitConfig x -> GitConfig) -> Generic GitConfig
forall x. Rep GitConfig x -> GitConfig
forall x. GitConfig -> Rep GitConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GitConfig x -> GitConfig
$cfrom :: forall x. GitConfig -> Rep GitConfig x
Prelude.Generic)

-- |
-- Create a value of 'GitConfig' 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:
--
-- 'branch', 'gitConfig_branch' - The default branch for the Git repository.
--
-- 'secretArn', 'gitConfig_secretArn' - The Amazon Resource Name (ARN) of the Amazon Web Services Secrets
-- Manager secret that contains the credentials used to access the git
-- repository. The secret must have a staging label of @AWSCURRENT@ and
-- must be in the following format:
--
-- @{\"username\": UserName, \"password\": Password}@
--
-- 'repositoryUrl', 'gitConfig_repositoryUrl' - The URL where the Git repository is located.
newGitConfig ::
  -- | 'repositoryUrl'
  Prelude.Text ->
  GitConfig
newGitConfig :: Text -> GitConfig
newGitConfig Text
pRepositoryUrl_ =
  GitConfig' :: Maybe Text -> Maybe Text -> Text -> GitConfig
GitConfig'
    { $sel:branch:GitConfig' :: Maybe Text
branch = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:secretArn:GitConfig' :: Maybe Text
secretArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:repositoryUrl:GitConfig' :: Text
repositoryUrl = Text
pRepositoryUrl_
    }

-- | The default branch for the Git repository.
gitConfig_branch :: Lens.Lens' GitConfig (Prelude.Maybe Prelude.Text)
gitConfig_branch :: (Maybe Text -> f (Maybe Text)) -> GitConfig -> f GitConfig
gitConfig_branch = (GitConfig -> Maybe Text)
-> (GitConfig -> Maybe Text -> GitConfig)
-> Lens GitConfig GitConfig (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GitConfig' {Maybe Text
branch :: Maybe Text
$sel:branch:GitConfig' :: GitConfig -> Maybe Text
branch} -> Maybe Text
branch) (\s :: GitConfig
s@GitConfig' {} Maybe Text
a -> GitConfig
s {$sel:branch:GitConfig' :: Maybe Text
branch = Maybe Text
a} :: GitConfig)

-- | The Amazon Resource Name (ARN) of the Amazon Web Services Secrets
-- Manager secret that contains the credentials used to access the git
-- repository. The secret must have a staging label of @AWSCURRENT@ and
-- must be in the following format:
--
-- @{\"username\": UserName, \"password\": Password}@
gitConfig_secretArn :: Lens.Lens' GitConfig (Prelude.Maybe Prelude.Text)
gitConfig_secretArn :: (Maybe Text -> f (Maybe Text)) -> GitConfig -> f GitConfig
gitConfig_secretArn = (GitConfig -> Maybe Text)
-> (GitConfig -> Maybe Text -> GitConfig)
-> Lens GitConfig GitConfig (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GitConfig' {Maybe Text
secretArn :: Maybe Text
$sel:secretArn:GitConfig' :: GitConfig -> Maybe Text
secretArn} -> Maybe Text
secretArn) (\s :: GitConfig
s@GitConfig' {} Maybe Text
a -> GitConfig
s {$sel:secretArn:GitConfig' :: Maybe Text
secretArn = Maybe Text
a} :: GitConfig)

-- | The URL where the Git repository is located.
gitConfig_repositoryUrl :: Lens.Lens' GitConfig Prelude.Text
gitConfig_repositoryUrl :: (Text -> f Text) -> GitConfig -> f GitConfig
gitConfig_repositoryUrl = (GitConfig -> Text)
-> (GitConfig -> Text -> GitConfig)
-> Lens GitConfig GitConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GitConfig' {Text
repositoryUrl :: Text
$sel:repositoryUrl:GitConfig' :: GitConfig -> Text
repositoryUrl} -> Text
repositoryUrl) (\s :: GitConfig
s@GitConfig' {} Text
a -> GitConfig
s {$sel:repositoryUrl:GitConfig' :: Text
repositoryUrl = Text
a} :: GitConfig)

instance Core.FromJSON GitConfig where
  parseJSON :: Value -> Parser GitConfig
parseJSON =
    String -> (Object -> Parser GitConfig) -> Value -> Parser GitConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"GitConfig"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Text -> GitConfig
GitConfig'
            (Maybe Text -> Maybe Text -> Text -> GitConfig)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Text -> GitConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Branch")
            Parser (Maybe Text -> Text -> GitConfig)
-> Parser (Maybe Text) -> Parser (Text -> GitConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SecretArn")
            Parser (Text -> GitConfig) -> Parser Text -> Parser GitConfig
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
"RepositoryUrl")
      )

instance Prelude.Hashable GitConfig

instance Prelude.NFData GitConfig

instance Core.ToJSON GitConfig where
  toJSON :: GitConfig -> Value
toJSON GitConfig' {Maybe Text
Text
repositoryUrl :: Text
secretArn :: Maybe Text
branch :: Maybe Text
$sel:repositoryUrl:GitConfig' :: GitConfig -> Text
$sel:secretArn:GitConfig' :: GitConfig -> Maybe Text
$sel:branch:GitConfig' :: GitConfig -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Branch" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
branch,
            (Text
"SecretArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
secretArn,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"RepositoryUrl" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
repositoryUrl)
          ]
      )