{-# 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.CodeArtifact.CreateDomain
-- 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 domain. CodeArtifact /domains/ make it easier to manage
-- multiple repositories across an organization. You can use a domain to
-- apply permissions across many repositories owned by different Amazon Web
-- Services accounts. An asset is stored only once in a domain, even if
-- it\'s in multiple repositories.
--
-- Although you can have multiple domains, we recommend a single production
-- domain that contains all published artifacts so that your development
-- teams can find and share packages. You can use a second pre-production
-- domain to test changes to the production domain configuration.
module Amazonka.CodeArtifact.CreateDomain
  ( -- * Creating a Request
    CreateDomain (..),
    newCreateDomain,

    -- * Request Lenses
    createDomain_encryptionKey,
    createDomain_tags,
    createDomain_domain,

    -- * Destructuring the Response
    CreateDomainResponse (..),
    newCreateDomainResponse,

    -- * Response Lenses
    createDomainResponse_domain,
    createDomainResponse_httpStatus,
  )
where

import Amazonka.CodeArtifact.Types
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

-- | /See:/ 'newCreateDomain' smart constructor.
data CreateDomain = CreateDomain'
  { -- | The encryption key for the domain. This is used to encrypt content
    -- stored in a domain. An encryption key can be a key ID, a key Amazon
    -- Resource Name (ARN), a key alias, or a key alias ARN. To specify an
    -- @encryptionKey@, your IAM role must have @kms:DescribeKey@ and
    -- @kms:CreateGrant@ permissions on the encryption key that is used. For
    -- more information, see
    -- <https://docs.aws.amazon.com/kms/latest/APIReference/API_DescribeKey.html#API_DescribeKey_RequestSyntax DescribeKey>
    -- in the /Key Management Service API Reference/ and
    -- <https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html Key Management Service API Permissions Reference>
    -- in the /Key Management Service Developer Guide/.
    --
    -- CodeArtifact supports only symmetric CMKs. Do not associate an
    -- asymmetric CMK with your domain. For more information, see
    -- <https://docs.aws.amazon.com/kms/latest/developerguide/symmetric-asymmetric.html Using symmetric and asymmetric keys>
    -- in the /Key Management Service Developer Guide/.
    CreateDomain -> Maybe Text
encryptionKey :: Prelude.Maybe Prelude.Text,
    -- | One or more tag key-value pairs for the domain.
    CreateDomain -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | The name of the domain to create. All domain names in an Amazon Web
    -- Services Region that are in the same Amazon Web Services account must be
    -- unique. The domain name is used as the prefix in DNS hostnames. Do not
    -- use sensitive information in a domain name because it is publicly
    -- discoverable.
    CreateDomain -> Text
domain :: Prelude.Text
  }
  deriving (CreateDomain -> CreateDomain -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateDomain -> CreateDomain -> Bool
$c/= :: CreateDomain -> CreateDomain -> Bool
== :: CreateDomain -> CreateDomain -> Bool
$c== :: CreateDomain -> CreateDomain -> Bool
Prelude.Eq, ReadPrec [CreateDomain]
ReadPrec CreateDomain
Int -> ReadS CreateDomain
ReadS [CreateDomain]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateDomain]
$creadListPrec :: ReadPrec [CreateDomain]
readPrec :: ReadPrec CreateDomain
$creadPrec :: ReadPrec CreateDomain
readList :: ReadS [CreateDomain]
$creadList :: ReadS [CreateDomain]
readsPrec :: Int -> ReadS CreateDomain
$creadsPrec :: Int -> ReadS CreateDomain
Prelude.Read, Int -> CreateDomain -> ShowS
[CreateDomain] -> ShowS
CreateDomain -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateDomain] -> ShowS
$cshowList :: [CreateDomain] -> ShowS
show :: CreateDomain -> String
$cshow :: CreateDomain -> String
showsPrec :: Int -> CreateDomain -> ShowS
$cshowsPrec :: Int -> CreateDomain -> ShowS
Prelude.Show, forall x. Rep CreateDomain x -> CreateDomain
forall x. CreateDomain -> Rep CreateDomain x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateDomain x -> CreateDomain
$cfrom :: forall x. CreateDomain -> Rep CreateDomain x
Prelude.Generic)

-- |
-- Create a value of 'CreateDomain' 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:
--
-- 'encryptionKey', 'createDomain_encryptionKey' - The encryption key for the domain. This is used to encrypt content
-- stored in a domain. An encryption key can be a key ID, a key Amazon
-- Resource Name (ARN), a key alias, or a key alias ARN. To specify an
-- @encryptionKey@, your IAM role must have @kms:DescribeKey@ and
-- @kms:CreateGrant@ permissions on the encryption key that is used. For
-- more information, see
-- <https://docs.aws.amazon.com/kms/latest/APIReference/API_DescribeKey.html#API_DescribeKey_RequestSyntax DescribeKey>
-- in the /Key Management Service API Reference/ and
-- <https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html Key Management Service API Permissions Reference>
-- in the /Key Management Service Developer Guide/.
--
-- CodeArtifact supports only symmetric CMKs. Do not associate an
-- asymmetric CMK with your domain. For more information, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/symmetric-asymmetric.html Using symmetric and asymmetric keys>
-- in the /Key Management Service Developer Guide/.
--
-- 'tags', 'createDomain_tags' - One or more tag key-value pairs for the domain.
--
-- 'domain', 'createDomain_domain' - The name of the domain to create. All domain names in an Amazon Web
-- Services Region that are in the same Amazon Web Services account must be
-- unique. The domain name is used as the prefix in DNS hostnames. Do not
-- use sensitive information in a domain name because it is publicly
-- discoverable.
newCreateDomain ::
  -- | 'domain'
  Prelude.Text ->
  CreateDomain
newCreateDomain :: Text -> CreateDomain
newCreateDomain Text
pDomain_ =
  CreateDomain'
    { $sel:encryptionKey:CreateDomain' :: Maybe Text
encryptionKey = forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateDomain' :: Maybe [Tag]
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:domain:CreateDomain' :: Text
domain = Text
pDomain_
    }

-- | The encryption key for the domain. This is used to encrypt content
-- stored in a domain. An encryption key can be a key ID, a key Amazon
-- Resource Name (ARN), a key alias, or a key alias ARN. To specify an
-- @encryptionKey@, your IAM role must have @kms:DescribeKey@ and
-- @kms:CreateGrant@ permissions on the encryption key that is used. For
-- more information, see
-- <https://docs.aws.amazon.com/kms/latest/APIReference/API_DescribeKey.html#API_DescribeKey_RequestSyntax DescribeKey>
-- in the /Key Management Service API Reference/ and
-- <https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html Key Management Service API Permissions Reference>
-- in the /Key Management Service Developer Guide/.
--
-- CodeArtifact supports only symmetric CMKs. Do not associate an
-- asymmetric CMK with your domain. For more information, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/symmetric-asymmetric.html Using symmetric and asymmetric keys>
-- in the /Key Management Service Developer Guide/.
createDomain_encryptionKey :: Lens.Lens' CreateDomain (Prelude.Maybe Prelude.Text)
createDomain_encryptionKey :: Lens' CreateDomain (Maybe Text)
createDomain_encryptionKey = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDomain' {Maybe Text
encryptionKey :: Maybe Text
$sel:encryptionKey:CreateDomain' :: CreateDomain -> Maybe Text
encryptionKey} -> Maybe Text
encryptionKey) (\s :: CreateDomain
s@CreateDomain' {} Maybe Text
a -> CreateDomain
s {$sel:encryptionKey:CreateDomain' :: Maybe Text
encryptionKey = Maybe Text
a} :: CreateDomain)

-- | One or more tag key-value pairs for the domain.
createDomain_tags :: Lens.Lens' CreateDomain (Prelude.Maybe [Tag])
createDomain_tags :: Lens' CreateDomain (Maybe [Tag])
createDomain_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDomain' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:CreateDomain' :: CreateDomain -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: CreateDomain
s@CreateDomain' {} Maybe [Tag]
a -> CreateDomain
s {$sel:tags:CreateDomain' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: CreateDomain) 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 domain to create. All domain names in an Amazon Web
-- Services Region that are in the same Amazon Web Services account must be
-- unique. The domain name is used as the prefix in DNS hostnames. Do not
-- use sensitive information in a domain name because it is publicly
-- discoverable.
createDomain_domain :: Lens.Lens' CreateDomain Prelude.Text
createDomain_domain :: Lens' CreateDomain Text
createDomain_domain = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDomain' {Text
domain :: Text
$sel:domain:CreateDomain' :: CreateDomain -> Text
domain} -> Text
domain) (\s :: CreateDomain
s@CreateDomain' {} Text
a -> CreateDomain
s {$sel:domain:CreateDomain' :: Text
domain = Text
a} :: CreateDomain)

instance Core.AWSRequest CreateDomain where
  type AWSResponse CreateDomain = CreateDomainResponse
  request :: (Service -> Service) -> CreateDomain -> Request CreateDomain
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 CreateDomain
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateDomain)))
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 ->
          Maybe DomainDescription -> Int -> CreateDomainResponse
CreateDomainResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"domain")
            forall (f :: * -> *) a b. Applicative f => 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))
      )

instance Prelude.Hashable CreateDomain where
  hashWithSalt :: Int -> CreateDomain -> Int
hashWithSalt Int
_salt CreateDomain' {Maybe [Tag]
Maybe Text
Text
domain :: Text
tags :: Maybe [Tag]
encryptionKey :: Maybe Text
$sel:domain:CreateDomain' :: CreateDomain -> Text
$sel:tags:CreateDomain' :: CreateDomain -> Maybe [Tag]
$sel:encryptionKey:CreateDomain' :: CreateDomain -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
encryptionKey
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Tag]
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
domain

instance Prelude.NFData CreateDomain where
  rnf :: CreateDomain -> ()
rnf CreateDomain' {Maybe [Tag]
Maybe Text
Text
domain :: Text
tags :: Maybe [Tag]
encryptionKey :: Maybe Text
$sel:domain:CreateDomain' :: CreateDomain -> Text
$sel:tags:CreateDomain' :: CreateDomain -> Maybe [Tag]
$sel:encryptionKey:CreateDomain' :: CreateDomain -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
encryptionKey
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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
domain

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

instance Data.ToJSON CreateDomain where
  toJSON :: CreateDomain -> Value
toJSON CreateDomain' {Maybe [Tag]
Maybe Text
Text
domain :: Text
tags :: Maybe [Tag]
encryptionKey :: Maybe Text
$sel:domain:CreateDomain' :: CreateDomain -> Text
$sel:tags:CreateDomain' :: CreateDomain -> Maybe [Tag]
$sel:encryptionKey:CreateDomain' :: CreateDomain -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"encryptionKey" 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 Text
encryptionKey,
            (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
          ]
      )

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

instance Data.ToQuery CreateDomain where
  toQuery :: CreateDomain -> QueryString
toQuery CreateDomain' {Maybe [Tag]
Maybe Text
Text
domain :: Text
tags :: Maybe [Tag]
encryptionKey :: Maybe Text
$sel:domain:CreateDomain' :: CreateDomain -> Text
$sel:tags:CreateDomain' :: CreateDomain -> Maybe [Tag]
$sel:encryptionKey:CreateDomain' :: CreateDomain -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"domain" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
domain]

-- | /See:/ 'newCreateDomainResponse' smart constructor.
data CreateDomainResponse = CreateDomainResponse'
  { -- | Contains information about the created domain after processing the
    -- request.
    CreateDomainResponse -> Maybe DomainDescription
domain :: Prelude.Maybe DomainDescription,
    -- | The response's http status code.
    CreateDomainResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateDomainResponse -> CreateDomainResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateDomainResponse -> CreateDomainResponse -> Bool
$c/= :: CreateDomainResponse -> CreateDomainResponse -> Bool
== :: CreateDomainResponse -> CreateDomainResponse -> Bool
$c== :: CreateDomainResponse -> CreateDomainResponse -> Bool
Prelude.Eq, ReadPrec [CreateDomainResponse]
ReadPrec CreateDomainResponse
Int -> ReadS CreateDomainResponse
ReadS [CreateDomainResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateDomainResponse]
$creadListPrec :: ReadPrec [CreateDomainResponse]
readPrec :: ReadPrec CreateDomainResponse
$creadPrec :: ReadPrec CreateDomainResponse
readList :: ReadS [CreateDomainResponse]
$creadList :: ReadS [CreateDomainResponse]
readsPrec :: Int -> ReadS CreateDomainResponse
$creadsPrec :: Int -> ReadS CreateDomainResponse
Prelude.Read, Int -> CreateDomainResponse -> ShowS
[CreateDomainResponse] -> ShowS
CreateDomainResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateDomainResponse] -> ShowS
$cshowList :: [CreateDomainResponse] -> ShowS
show :: CreateDomainResponse -> String
$cshow :: CreateDomainResponse -> String
showsPrec :: Int -> CreateDomainResponse -> ShowS
$cshowsPrec :: Int -> CreateDomainResponse -> ShowS
Prelude.Show, forall x. Rep CreateDomainResponse x -> CreateDomainResponse
forall x. CreateDomainResponse -> Rep CreateDomainResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateDomainResponse x -> CreateDomainResponse
$cfrom :: forall x. CreateDomainResponse -> Rep CreateDomainResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateDomainResponse' 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:
--
-- 'domain', 'createDomainResponse_domain' - Contains information about the created domain after processing the
-- request.
--
-- 'httpStatus', 'createDomainResponse_httpStatus' - The response's http status code.
newCreateDomainResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateDomainResponse
newCreateDomainResponse :: Int -> CreateDomainResponse
newCreateDomainResponse Int
pHttpStatus_ =
  CreateDomainResponse'
    { $sel:domain:CreateDomainResponse' :: Maybe DomainDescription
domain = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateDomainResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Contains information about the created domain after processing the
-- request.
createDomainResponse_domain :: Lens.Lens' CreateDomainResponse (Prelude.Maybe DomainDescription)
createDomainResponse_domain :: Lens' CreateDomainResponse (Maybe DomainDescription)
createDomainResponse_domain = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateDomainResponse' {Maybe DomainDescription
domain :: Maybe DomainDescription
$sel:domain:CreateDomainResponse' :: CreateDomainResponse -> Maybe DomainDescription
domain} -> Maybe DomainDescription
domain) (\s :: CreateDomainResponse
s@CreateDomainResponse' {} Maybe DomainDescription
a -> CreateDomainResponse
s {$sel:domain:CreateDomainResponse' :: Maybe DomainDescription
domain = Maybe DomainDescription
a} :: CreateDomainResponse)

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

instance Prelude.NFData CreateDomainResponse where
  rnf :: CreateDomainResponse -> ()
rnf CreateDomainResponse' {Int
Maybe DomainDescription
httpStatus :: Int
domain :: Maybe DomainDescription
$sel:httpStatus:CreateDomainResponse' :: CreateDomainResponse -> Int
$sel:domain:CreateDomainResponse' :: CreateDomainResponse -> Maybe DomainDescription
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe DomainDescription
domain
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus