{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.CreateCodeRepository
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a Git repository as a resource in your SageMaker account. You
-- can associate the repository with notebook instances so that you can use
-- Git source control for the notebooks you create. The Git repository is a
-- resource in your SageMaker account, so it can be associated with more
-- than one notebook instance, and it persists independently from the
-- lifecycle of any notebook instances it is associated with.
--
-- The repository can be hosted either in
-- <https://docs.aws.amazon.com/codecommit/latest/userguide/welcome.html Amazon Web Services CodeCommit>
-- or in any other Git repository.
module Amazonka.SageMaker.CreateCodeRepository
  ( -- * Creating a Request
    CreateCodeRepository (..),
    newCreateCodeRepository,

    -- * Request Lenses
    createCodeRepository_tags,
    createCodeRepository_codeRepositoryName,
    createCodeRepository_gitConfig,

    -- * Destructuring the Response
    CreateCodeRepositoryResponse (..),
    newCreateCodeRepositoryResponse,

    -- * Response Lenses
    createCodeRepositoryResponse_httpStatus,
    createCodeRepositoryResponse_codeRepositoryArn,
  )
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
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.SageMaker.Types

-- | /See:/ 'newCreateCodeRepository' smart constructor.
data CreateCodeRepository = CreateCodeRepository'
  { -- | An array of key-value pairs. You can use tags to categorize your Amazon
    -- Web Services resources in different ways, for example, by purpose,
    -- owner, or environment. For more information, see
    -- <https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html Tagging Amazon Web Services Resources>.
    CreateCodeRepository -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | The name of the Git repository. The name must have 1 to 63 characters.
    -- Valid characters are a-z, A-Z, 0-9, and - (hyphen).
    CreateCodeRepository -> Text
codeRepositoryName :: Prelude.Text,
    -- | Specifies details about the repository, including the URL where the
    -- repository is located, the default branch, and credentials to use to
    -- access the repository.
    CreateCodeRepository -> GitConfig
gitConfig :: GitConfig
  }
  deriving (CreateCodeRepository -> CreateCodeRepository -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateCodeRepository -> CreateCodeRepository -> Bool
$c/= :: CreateCodeRepository -> CreateCodeRepository -> Bool
== :: CreateCodeRepository -> CreateCodeRepository -> Bool
$c== :: CreateCodeRepository -> CreateCodeRepository -> Bool
Prelude.Eq, ReadPrec [CreateCodeRepository]
ReadPrec CreateCodeRepository
Int -> ReadS CreateCodeRepository
ReadS [CreateCodeRepository]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateCodeRepository]
$creadListPrec :: ReadPrec [CreateCodeRepository]
readPrec :: ReadPrec CreateCodeRepository
$creadPrec :: ReadPrec CreateCodeRepository
readList :: ReadS [CreateCodeRepository]
$creadList :: ReadS [CreateCodeRepository]
readsPrec :: Int -> ReadS CreateCodeRepository
$creadsPrec :: Int -> ReadS CreateCodeRepository
Prelude.Read, Int -> CreateCodeRepository -> ShowS
[CreateCodeRepository] -> ShowS
CreateCodeRepository -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateCodeRepository] -> ShowS
$cshowList :: [CreateCodeRepository] -> ShowS
show :: CreateCodeRepository -> String
$cshow :: CreateCodeRepository -> String
showsPrec :: Int -> CreateCodeRepository -> ShowS
$cshowsPrec :: Int -> CreateCodeRepository -> ShowS
Prelude.Show, forall x. Rep CreateCodeRepository x -> CreateCodeRepository
forall x. CreateCodeRepository -> Rep CreateCodeRepository x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateCodeRepository x -> CreateCodeRepository
$cfrom :: forall x. CreateCodeRepository -> Rep CreateCodeRepository x
Prelude.Generic)

-- |
-- Create a value of 'CreateCodeRepository' 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:
--
-- 'tags', 'createCodeRepository_tags' - An array of key-value pairs. You can use tags to categorize your Amazon
-- Web Services resources in different ways, for example, by purpose,
-- owner, or environment. For more information, see
-- <https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html Tagging Amazon Web Services Resources>.
--
-- 'codeRepositoryName', 'createCodeRepository_codeRepositoryName' - The name of the Git repository. The name must have 1 to 63 characters.
-- Valid characters are a-z, A-Z, 0-9, and - (hyphen).
--
-- 'gitConfig', 'createCodeRepository_gitConfig' - Specifies details about the repository, including the URL where the
-- repository is located, the default branch, and credentials to use to
-- access the repository.
newCreateCodeRepository ::
  -- | 'codeRepositoryName'
  Prelude.Text ->
  -- | 'gitConfig'
  GitConfig ->
  CreateCodeRepository
newCreateCodeRepository :: Text -> GitConfig -> CreateCodeRepository
newCreateCodeRepository
  Text
pCodeRepositoryName_
  GitConfig
pGitConfig_ =
    CreateCodeRepository'
      { $sel:tags:CreateCodeRepository' :: Maybe [Tag]
tags = forall a. Maybe a
Prelude.Nothing,
        $sel:codeRepositoryName:CreateCodeRepository' :: Text
codeRepositoryName = Text
pCodeRepositoryName_,
        $sel:gitConfig:CreateCodeRepository' :: GitConfig
gitConfig = GitConfig
pGitConfig_
      }

-- | An array of key-value pairs. You can use tags to categorize your Amazon
-- Web Services resources in different ways, for example, by purpose,
-- owner, or environment. For more information, see
-- <https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html Tagging Amazon Web Services Resources>.
createCodeRepository_tags :: Lens.Lens' CreateCodeRepository (Prelude.Maybe [Tag])
createCodeRepository_tags :: Lens' CreateCodeRepository (Maybe [Tag])
createCodeRepository_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCodeRepository' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:CreateCodeRepository' :: CreateCodeRepository -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: CreateCodeRepository
s@CreateCodeRepository' {} Maybe [Tag]
a -> CreateCodeRepository
s {$sel:tags:CreateCodeRepository' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: CreateCodeRepository) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the Git repository. The name must have 1 to 63 characters.
-- Valid characters are a-z, A-Z, 0-9, and - (hyphen).
createCodeRepository_codeRepositoryName :: Lens.Lens' CreateCodeRepository Prelude.Text
createCodeRepository_codeRepositoryName :: Lens' CreateCodeRepository Text
createCodeRepository_codeRepositoryName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCodeRepository' {Text
codeRepositoryName :: Text
$sel:codeRepositoryName:CreateCodeRepository' :: CreateCodeRepository -> Text
codeRepositoryName} -> Text
codeRepositoryName) (\s :: CreateCodeRepository
s@CreateCodeRepository' {} Text
a -> CreateCodeRepository
s {$sel:codeRepositoryName:CreateCodeRepository' :: Text
codeRepositoryName = Text
a} :: CreateCodeRepository)

-- | Specifies details about the repository, including the URL where the
-- repository is located, the default branch, and credentials to use to
-- access the repository.
createCodeRepository_gitConfig :: Lens.Lens' CreateCodeRepository GitConfig
createCodeRepository_gitConfig :: Lens' CreateCodeRepository GitConfig
createCodeRepository_gitConfig = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCodeRepository' {GitConfig
gitConfig :: GitConfig
$sel:gitConfig:CreateCodeRepository' :: CreateCodeRepository -> GitConfig
gitConfig} -> GitConfig
gitConfig) (\s :: CreateCodeRepository
s@CreateCodeRepository' {} GitConfig
a -> CreateCodeRepository
s {$sel:gitConfig:CreateCodeRepository' :: GitConfig
gitConfig = GitConfig
a} :: CreateCodeRepository)

instance Core.AWSRequest CreateCodeRepository where
  type
    AWSResponse CreateCodeRepository =
      CreateCodeRepositoryResponse
  request :: (Service -> Service)
-> CreateCodeRepository -> Request CreateCodeRepository
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy CreateCodeRepository
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateCodeRepository)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> Text -> CreateCodeRepositoryResponse
CreateCodeRepositoryResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"CodeRepositoryArn")
      )

instance Prelude.Hashable CreateCodeRepository where
  hashWithSalt :: Int -> CreateCodeRepository -> Int
hashWithSalt Int
_salt CreateCodeRepository' {Maybe [Tag]
Text
GitConfig
gitConfig :: GitConfig
codeRepositoryName :: Text
tags :: Maybe [Tag]
$sel:gitConfig:CreateCodeRepository' :: CreateCodeRepository -> GitConfig
$sel:codeRepositoryName:CreateCodeRepository' :: CreateCodeRepository -> Text
$sel:tags:CreateCodeRepository' :: CreateCodeRepository -> Maybe [Tag]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Tag]
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
codeRepositoryName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` GitConfig
gitConfig

instance Prelude.NFData CreateCodeRepository where
  rnf :: CreateCodeRepository -> ()
rnf CreateCodeRepository' {Maybe [Tag]
Text
GitConfig
gitConfig :: GitConfig
codeRepositoryName :: Text
tags :: Maybe [Tag]
$sel:gitConfig:CreateCodeRepository' :: CreateCodeRepository -> GitConfig
$sel:codeRepositoryName:CreateCodeRepository' :: CreateCodeRepository -> Text
$sel:tags:CreateCodeRepository' :: CreateCodeRepository -> Maybe [Tag]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Tag]
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
codeRepositoryName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf GitConfig
gitConfig

instance Data.ToHeaders CreateCodeRepository where
  toHeaders :: CreateCodeRepository -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"SageMaker.CreateCodeRepository" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON CreateCodeRepository where
  toJSON :: CreateCodeRepository -> Value
toJSON CreateCodeRepository' {Maybe [Tag]
Text
GitConfig
gitConfig :: GitConfig
codeRepositoryName :: Text
tags :: Maybe [Tag]
$sel:gitConfig:CreateCodeRepository' :: CreateCodeRepository -> GitConfig
$sel:codeRepositoryName:CreateCodeRepository' :: CreateCodeRepository -> Text
$sel:tags:CreateCodeRepository' :: CreateCodeRepository -> Maybe [Tag]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Tags" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Tag]
tags,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"CodeRepositoryName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
codeRepositoryName),
            forall a. a -> Maybe a
Prelude.Just (Key
"GitConfig" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= GitConfig
gitConfig)
          ]
      )

instance Data.ToPath CreateCodeRepository where
  toPath :: CreateCodeRepository -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery CreateCodeRepository where
  toQuery :: CreateCodeRepository -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newCreateCodeRepositoryResponse' smart constructor.
data CreateCodeRepositoryResponse = CreateCodeRepositoryResponse'
  { -- | The response's http status code.
    CreateCodeRepositoryResponse -> Int
httpStatus :: Prelude.Int,
    -- | The Amazon Resource Name (ARN) of the new repository.
    CreateCodeRepositoryResponse -> Text
codeRepositoryArn :: Prelude.Text
  }
  deriving (CreateCodeRepositoryResponse
-> CreateCodeRepositoryResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateCodeRepositoryResponse
-> CreateCodeRepositoryResponse -> Bool
$c/= :: CreateCodeRepositoryResponse
-> CreateCodeRepositoryResponse -> Bool
== :: CreateCodeRepositoryResponse
-> CreateCodeRepositoryResponse -> Bool
$c== :: CreateCodeRepositoryResponse
-> CreateCodeRepositoryResponse -> Bool
Prelude.Eq, ReadPrec [CreateCodeRepositoryResponse]
ReadPrec CreateCodeRepositoryResponse
Int -> ReadS CreateCodeRepositoryResponse
ReadS [CreateCodeRepositoryResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateCodeRepositoryResponse]
$creadListPrec :: ReadPrec [CreateCodeRepositoryResponse]
readPrec :: ReadPrec CreateCodeRepositoryResponse
$creadPrec :: ReadPrec CreateCodeRepositoryResponse
readList :: ReadS [CreateCodeRepositoryResponse]
$creadList :: ReadS [CreateCodeRepositoryResponse]
readsPrec :: Int -> ReadS CreateCodeRepositoryResponse
$creadsPrec :: Int -> ReadS CreateCodeRepositoryResponse
Prelude.Read, Int -> CreateCodeRepositoryResponse -> ShowS
[CreateCodeRepositoryResponse] -> ShowS
CreateCodeRepositoryResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateCodeRepositoryResponse] -> ShowS
$cshowList :: [CreateCodeRepositoryResponse] -> ShowS
show :: CreateCodeRepositoryResponse -> String
$cshow :: CreateCodeRepositoryResponse -> String
showsPrec :: Int -> CreateCodeRepositoryResponse -> ShowS
$cshowsPrec :: Int -> CreateCodeRepositoryResponse -> ShowS
Prelude.Show, forall x.
Rep CreateCodeRepositoryResponse x -> CreateCodeRepositoryResponse
forall x.
CreateCodeRepositoryResponse -> Rep CreateCodeRepositoryResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateCodeRepositoryResponse x -> CreateCodeRepositoryResponse
$cfrom :: forall x.
CreateCodeRepositoryResponse -> Rep CreateCodeRepositoryResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateCodeRepositoryResponse' 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:
--
-- 'httpStatus', 'createCodeRepositoryResponse_httpStatus' - The response's http status code.
--
-- 'codeRepositoryArn', 'createCodeRepositoryResponse_codeRepositoryArn' - The Amazon Resource Name (ARN) of the new repository.
newCreateCodeRepositoryResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'codeRepositoryArn'
  Prelude.Text ->
  CreateCodeRepositoryResponse
newCreateCodeRepositoryResponse :: Int -> Text -> CreateCodeRepositoryResponse
newCreateCodeRepositoryResponse
  Int
pHttpStatus_
  Text
pCodeRepositoryArn_ =
    CreateCodeRepositoryResponse'
      { $sel:httpStatus:CreateCodeRepositoryResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:codeRepositoryArn:CreateCodeRepositoryResponse' :: Text
codeRepositoryArn = Text
pCodeRepositoryArn_
      }

-- | The response's http status code.
createCodeRepositoryResponse_httpStatus :: Lens.Lens' CreateCodeRepositoryResponse Prelude.Int
createCodeRepositoryResponse_httpStatus :: Lens' CreateCodeRepositoryResponse Int
createCodeRepositoryResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCodeRepositoryResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateCodeRepositoryResponse' :: CreateCodeRepositoryResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateCodeRepositoryResponse
s@CreateCodeRepositoryResponse' {} Int
a -> CreateCodeRepositoryResponse
s {$sel:httpStatus:CreateCodeRepositoryResponse' :: Int
httpStatus = Int
a} :: CreateCodeRepositoryResponse)

-- | The Amazon Resource Name (ARN) of the new repository.
createCodeRepositoryResponse_codeRepositoryArn :: Lens.Lens' CreateCodeRepositoryResponse Prelude.Text
createCodeRepositoryResponse_codeRepositoryArn :: Lens' CreateCodeRepositoryResponse Text
createCodeRepositoryResponse_codeRepositoryArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCodeRepositoryResponse' {Text
codeRepositoryArn :: Text
$sel:codeRepositoryArn:CreateCodeRepositoryResponse' :: CreateCodeRepositoryResponse -> Text
codeRepositoryArn} -> Text
codeRepositoryArn) (\s :: CreateCodeRepositoryResponse
s@CreateCodeRepositoryResponse' {} Text
a -> CreateCodeRepositoryResponse
s {$sel:codeRepositoryArn:CreateCodeRepositoryResponse' :: Text
codeRepositoryArn = Text
a} :: CreateCodeRepositoryResponse)

instance Prelude.NFData CreateCodeRepositoryResponse where
  rnf :: CreateCodeRepositoryResponse -> ()
rnf CreateCodeRepositoryResponse' {Int
Text
codeRepositoryArn :: Text
httpStatus :: Int
$sel:codeRepositoryArn:CreateCodeRepositoryResponse' :: CreateCodeRepositoryResponse -> Text
$sel:httpStatus:CreateCodeRepositoryResponse' :: CreateCodeRepositoryResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
codeRepositoryArn