{-# 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.CertificateManagerPCA.TagCertificateAuthority
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Adds one or more tags to your private CA. Tags are labels that you can
-- use to identify and organize your Amazon Web Services resources. Each
-- tag consists of a key and an optional value. You specify the private CA
-- on input by its Amazon Resource Name (ARN). You specify the tag by using
-- a key-value pair. You can apply a tag to just one private CA if you want
-- to identify a specific characteristic of that CA, or you can apply the
-- same tag to multiple private CAs if you want to filter for a common
-- relationship among those CAs. To remove one or more tags, use the
-- <https://docs.aws.amazon.com/privateca/latest/APIReference/API_UntagCertificateAuthority.html UntagCertificateAuthority>
-- action. Call the
-- <https://docs.aws.amazon.com/privateca/latest/APIReference/API_ListTags.html ListTags>
-- action to see what tags are associated with your CA.
--
-- To attach tags to a private CA during the creation procedure, a CA
-- administrator must first associate an inline IAM policy with the
-- @CreateCertificateAuthority@ action and explicitly allow tagging. For
-- more information, see
-- <https://docs.aws.amazon.com/privateca/latest/userguide/auth-InlinePolicies.html#policy-tag-ca Attaching tags to a CA at the time of creation>.
module Amazonka.CertificateManagerPCA.TagCertificateAuthority
  ( -- * Creating a Request
    TagCertificateAuthority (..),
    newTagCertificateAuthority,

    -- * Request Lenses
    tagCertificateAuthority_certificateAuthorityArn,
    tagCertificateAuthority_tags,

    -- * Destructuring the Response
    TagCertificateAuthorityResponse (..),
    newTagCertificateAuthorityResponse,
  )
where

import Amazonka.CertificateManagerPCA.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:/ 'newTagCertificateAuthority' smart constructor.
data TagCertificateAuthority = TagCertificateAuthority'
  { -- | The Amazon Resource Name (ARN) that was returned when you called
    -- <https://docs.aws.amazon.com/privateca/latest/APIReference/API_CreateCertificateAuthority.html CreateCertificateAuthority>.
    -- This must be of the form:
    --
    -- @arn:aws:acm-pca:@/@region@/@:@/@account@/@:certificate-authority\/@/@12345678-1234-1234-1234-123456789012@/@ @
    TagCertificateAuthority -> Text
certificateAuthorityArn :: Prelude.Text,
    -- | List of tags to be associated with the CA.
    TagCertificateAuthority -> NonEmpty Tag
tags :: Prelude.NonEmpty Tag
  }
  deriving (TagCertificateAuthority -> TagCertificateAuthority -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TagCertificateAuthority -> TagCertificateAuthority -> Bool
$c/= :: TagCertificateAuthority -> TagCertificateAuthority -> Bool
== :: TagCertificateAuthority -> TagCertificateAuthority -> Bool
$c== :: TagCertificateAuthority -> TagCertificateAuthority -> Bool
Prelude.Eq, ReadPrec [TagCertificateAuthority]
ReadPrec TagCertificateAuthority
Int -> ReadS TagCertificateAuthority
ReadS [TagCertificateAuthority]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TagCertificateAuthority]
$creadListPrec :: ReadPrec [TagCertificateAuthority]
readPrec :: ReadPrec TagCertificateAuthority
$creadPrec :: ReadPrec TagCertificateAuthority
readList :: ReadS [TagCertificateAuthority]
$creadList :: ReadS [TagCertificateAuthority]
readsPrec :: Int -> ReadS TagCertificateAuthority
$creadsPrec :: Int -> ReadS TagCertificateAuthority
Prelude.Read, Int -> TagCertificateAuthority -> ShowS
[TagCertificateAuthority] -> ShowS
TagCertificateAuthority -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TagCertificateAuthority] -> ShowS
$cshowList :: [TagCertificateAuthority] -> ShowS
show :: TagCertificateAuthority -> String
$cshow :: TagCertificateAuthority -> String
showsPrec :: Int -> TagCertificateAuthority -> ShowS
$cshowsPrec :: Int -> TagCertificateAuthority -> ShowS
Prelude.Show, forall x. Rep TagCertificateAuthority x -> TagCertificateAuthority
forall x. TagCertificateAuthority -> Rep TagCertificateAuthority x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TagCertificateAuthority x -> TagCertificateAuthority
$cfrom :: forall x. TagCertificateAuthority -> Rep TagCertificateAuthority x
Prelude.Generic)

-- |
-- Create a value of 'TagCertificateAuthority' 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:
--
-- 'certificateAuthorityArn', 'tagCertificateAuthority_certificateAuthorityArn' - The Amazon Resource Name (ARN) that was returned when you called
-- <https://docs.aws.amazon.com/privateca/latest/APIReference/API_CreateCertificateAuthority.html CreateCertificateAuthority>.
-- This must be of the form:
--
-- @arn:aws:acm-pca:@/@region@/@:@/@account@/@:certificate-authority\/@/@12345678-1234-1234-1234-123456789012@/@ @
--
-- 'tags', 'tagCertificateAuthority_tags' - List of tags to be associated with the CA.
newTagCertificateAuthority ::
  -- | 'certificateAuthorityArn'
  Prelude.Text ->
  -- | 'tags'
  Prelude.NonEmpty Tag ->
  TagCertificateAuthority
newTagCertificateAuthority :: Text -> NonEmpty Tag -> TagCertificateAuthority
newTagCertificateAuthority
  Text
pCertificateAuthorityArn_
  NonEmpty Tag
pTags_ =
    TagCertificateAuthority'
      { $sel:certificateAuthorityArn:TagCertificateAuthority' :: Text
certificateAuthorityArn =
          Text
pCertificateAuthorityArn_,
        $sel:tags:TagCertificateAuthority' :: NonEmpty Tag
tags = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Tag
pTags_
      }

-- | The Amazon Resource Name (ARN) that was returned when you called
-- <https://docs.aws.amazon.com/privateca/latest/APIReference/API_CreateCertificateAuthority.html CreateCertificateAuthority>.
-- This must be of the form:
--
-- @arn:aws:acm-pca:@/@region@/@:@/@account@/@:certificate-authority\/@/@12345678-1234-1234-1234-123456789012@/@ @
tagCertificateAuthority_certificateAuthorityArn :: Lens.Lens' TagCertificateAuthority Prelude.Text
tagCertificateAuthority_certificateAuthorityArn :: Lens' TagCertificateAuthority Text
tagCertificateAuthority_certificateAuthorityArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagCertificateAuthority' {Text
certificateAuthorityArn :: Text
$sel:certificateAuthorityArn:TagCertificateAuthority' :: TagCertificateAuthority -> Text
certificateAuthorityArn} -> Text
certificateAuthorityArn) (\s :: TagCertificateAuthority
s@TagCertificateAuthority' {} Text
a -> TagCertificateAuthority
s {$sel:certificateAuthorityArn:TagCertificateAuthority' :: Text
certificateAuthorityArn = Text
a} :: TagCertificateAuthority)

-- | List of tags to be associated with the CA.
tagCertificateAuthority_tags :: Lens.Lens' TagCertificateAuthority (Prelude.NonEmpty Tag)
tagCertificateAuthority_tags :: Lens' TagCertificateAuthority (NonEmpty Tag)
tagCertificateAuthority_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagCertificateAuthority' {NonEmpty Tag
tags :: NonEmpty Tag
$sel:tags:TagCertificateAuthority' :: TagCertificateAuthority -> NonEmpty Tag
tags} -> NonEmpty Tag
tags) (\s :: TagCertificateAuthority
s@TagCertificateAuthority' {} NonEmpty Tag
a -> TagCertificateAuthority
s {$sel:tags:TagCertificateAuthority' :: NonEmpty Tag
tags = NonEmpty Tag
a} :: TagCertificateAuthority) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest TagCertificateAuthority where
  type
    AWSResponse TagCertificateAuthority =
      TagCertificateAuthorityResponse
  request :: (Service -> Service)
-> TagCertificateAuthority -> Request TagCertificateAuthority
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 TagCertificateAuthority
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse TagCertificateAuthority)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull
      TagCertificateAuthorityResponse
TagCertificateAuthorityResponse'

instance Prelude.Hashable TagCertificateAuthority where
  hashWithSalt :: Int -> TagCertificateAuthority -> Int
hashWithSalt Int
_salt TagCertificateAuthority' {NonEmpty Tag
Text
tags :: NonEmpty Tag
certificateAuthorityArn :: Text
$sel:tags:TagCertificateAuthority' :: TagCertificateAuthority -> NonEmpty Tag
$sel:certificateAuthorityArn:TagCertificateAuthority' :: TagCertificateAuthority -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
certificateAuthorityArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Tag
tags

instance Prelude.NFData TagCertificateAuthority where
  rnf :: TagCertificateAuthority -> ()
rnf TagCertificateAuthority' {NonEmpty Tag
Text
tags :: NonEmpty Tag
certificateAuthorityArn :: Text
$sel:tags:TagCertificateAuthority' :: TagCertificateAuthority -> NonEmpty Tag
$sel:certificateAuthorityArn:TagCertificateAuthority' :: TagCertificateAuthority -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
certificateAuthorityArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Tag
tags

instance Data.ToHeaders TagCertificateAuthority where
  toHeaders :: TagCertificateAuthority -> [Header]
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 -> [Header]
Data.=# ( ByteString
"ACMPrivateCA.TagCertificateAuthority" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> [Header]
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON TagCertificateAuthority where
  toJSON :: TagCertificateAuthority -> Value
toJSON TagCertificateAuthority' {NonEmpty Tag
Text
tags :: NonEmpty Tag
certificateAuthorityArn :: Text
$sel:tags:TagCertificateAuthority' :: TagCertificateAuthority -> NonEmpty Tag
$sel:certificateAuthorityArn:TagCertificateAuthority' :: TagCertificateAuthority -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              ( Key
"CertificateAuthorityArn"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
certificateAuthorityArn
              ),
            forall a. a -> Maybe a
Prelude.Just (Key
"Tags" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Tag
tags)
          ]
      )

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

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

-- | /See:/ 'newTagCertificateAuthorityResponse' smart constructor.
data TagCertificateAuthorityResponse = TagCertificateAuthorityResponse'
  {
  }
  deriving (TagCertificateAuthorityResponse
-> TagCertificateAuthorityResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TagCertificateAuthorityResponse
-> TagCertificateAuthorityResponse -> Bool
$c/= :: TagCertificateAuthorityResponse
-> TagCertificateAuthorityResponse -> Bool
== :: TagCertificateAuthorityResponse
-> TagCertificateAuthorityResponse -> Bool
$c== :: TagCertificateAuthorityResponse
-> TagCertificateAuthorityResponse -> Bool
Prelude.Eq, ReadPrec [TagCertificateAuthorityResponse]
ReadPrec TagCertificateAuthorityResponse
Int -> ReadS TagCertificateAuthorityResponse
ReadS [TagCertificateAuthorityResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TagCertificateAuthorityResponse]
$creadListPrec :: ReadPrec [TagCertificateAuthorityResponse]
readPrec :: ReadPrec TagCertificateAuthorityResponse
$creadPrec :: ReadPrec TagCertificateAuthorityResponse
readList :: ReadS [TagCertificateAuthorityResponse]
$creadList :: ReadS [TagCertificateAuthorityResponse]
readsPrec :: Int -> ReadS TagCertificateAuthorityResponse
$creadsPrec :: Int -> ReadS TagCertificateAuthorityResponse
Prelude.Read, Int -> TagCertificateAuthorityResponse -> ShowS
[TagCertificateAuthorityResponse] -> ShowS
TagCertificateAuthorityResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TagCertificateAuthorityResponse] -> ShowS
$cshowList :: [TagCertificateAuthorityResponse] -> ShowS
show :: TagCertificateAuthorityResponse -> String
$cshow :: TagCertificateAuthorityResponse -> String
showsPrec :: Int -> TagCertificateAuthorityResponse -> ShowS
$cshowsPrec :: Int -> TagCertificateAuthorityResponse -> ShowS
Prelude.Show, forall x.
Rep TagCertificateAuthorityResponse x
-> TagCertificateAuthorityResponse
forall x.
TagCertificateAuthorityResponse
-> Rep TagCertificateAuthorityResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep TagCertificateAuthorityResponse x
-> TagCertificateAuthorityResponse
$cfrom :: forall x.
TagCertificateAuthorityResponse
-> Rep TagCertificateAuthorityResponse x
Prelude.Generic)

-- |
-- Create a value of 'TagCertificateAuthorityResponse' 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.
newTagCertificateAuthorityResponse ::
  TagCertificateAuthorityResponse
newTagCertificateAuthorityResponse :: TagCertificateAuthorityResponse
newTagCertificateAuthorityResponse =
  TagCertificateAuthorityResponse
TagCertificateAuthorityResponse'

instance
  Prelude.NFData
    TagCertificateAuthorityResponse
  where
  rnf :: TagCertificateAuthorityResponse -> ()
rnf TagCertificateAuthorityResponse
_ = ()