{-# 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.SecretsManager.TagResource
-- 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)
--
-- Attaches one or more tags, each consisting of a key name and a value, to
-- the specified secret. Tags are part of the secret\'s overall metadata,
-- and are not associated with any specific version of the secret. This
-- operation only appends tags to the existing list of tags. To remove
-- tags, you must use UntagResource.
--
-- The following basic restrictions apply to tags:
--
-- -   Maximum number of tags per secret—50
--
-- -   Maximum key length—127 Unicode characters in UTF-8
--
-- -   Maximum value length—255 Unicode characters in UTF-8
--
-- -   Tag keys and values are case sensitive.
--
-- -   Do not use the @aws:@ prefix in your tag names or values because
--     Amazon Web Services reserves it for Amazon Web Services use. You
--     can\'t edit or delete tag names or values with this prefix. Tags
--     with this prefix do not count against your tags per secret limit.
--
-- -   If you use your tagging schema across multiple services and
--     resources, remember other services might have restrictions on
--     allowed characters. Generally allowed characters: letters, spaces,
--     and numbers representable in UTF-8, plus the following special
--     characters: + - = . _ : \/ \@.
--
-- If you use tags as part of your security strategy, then adding or
-- removing a tag can change permissions. If successfully completing this
-- operation would result in you losing your permissions for this secret,
-- then the operation is blocked and returns an Access Denied error.
--
-- __Minimum permissions__
--
-- To run this command, you must have the following permissions:
--
-- -   secretsmanager:TagResource
--
-- __Related operations__
--
-- -   To remove one or more tags from the collection attached to a secret,
--     use UntagResource.
--
-- -   To view the list of tags attached to a secret, use DescribeSecret.
module Amazonka.SecretsManager.TagResource
  ( -- * Creating a Request
    TagResource (..),
    newTagResource,

    -- * Request Lenses
    tagResource_secretId,
    tagResource_tags,

    -- * Destructuring the Response
    TagResourceResponse (..),
    newTagResourceResponse,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.SecretsManager.Types

-- | /See:/ 'newTagResource' smart constructor.
data TagResource = TagResource'
  { -- | The identifier for the secret that you want to attach tags to. You can
    -- specify either the Amazon Resource Name (ARN) or the friendly name of
    -- the secret.
    --
    -- For an ARN, we recommend that you specify a complete ARN rather than a
    -- partial ARN.
    TagResource -> Text
secretId :: Prelude.Text,
    -- | The tags to attach to the secret. Each element in the list consists of a
    -- @Key@ and a @Value@.
    --
    -- This parameter to the API requires a JSON text string argument.
    --
    -- For storing multiple values, we recommend that you use a JSON text
    -- string argument and specify key\/value pairs. For more information, see
    -- <https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters.html Specifying parameter values for the Amazon Web Services CLI>
    -- in the Amazon Web Services CLI User Guide.
    TagResource -> [Tag]
tags :: [Tag]
  }
  deriving (TagResource -> TagResource -> Bool
(TagResource -> TagResource -> Bool)
-> (TagResource -> TagResource -> Bool) -> Eq TagResource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TagResource -> TagResource -> Bool
$c/= :: TagResource -> TagResource -> Bool
== :: TagResource -> TagResource -> Bool
$c== :: TagResource -> TagResource -> Bool
Prelude.Eq, ReadPrec [TagResource]
ReadPrec TagResource
Int -> ReadS TagResource
ReadS [TagResource]
(Int -> ReadS TagResource)
-> ReadS [TagResource]
-> ReadPrec TagResource
-> ReadPrec [TagResource]
-> Read TagResource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TagResource]
$creadListPrec :: ReadPrec [TagResource]
readPrec :: ReadPrec TagResource
$creadPrec :: ReadPrec TagResource
readList :: ReadS [TagResource]
$creadList :: ReadS [TagResource]
readsPrec :: Int -> ReadS TagResource
$creadsPrec :: Int -> ReadS TagResource
Prelude.Read, Int -> TagResource -> ShowS
[TagResource] -> ShowS
TagResource -> String
(Int -> TagResource -> ShowS)
-> (TagResource -> String)
-> ([TagResource] -> ShowS)
-> Show TagResource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TagResource] -> ShowS
$cshowList :: [TagResource] -> ShowS
show :: TagResource -> String
$cshow :: TagResource -> String
showsPrec :: Int -> TagResource -> ShowS
$cshowsPrec :: Int -> TagResource -> ShowS
Prelude.Show, (forall x. TagResource -> Rep TagResource x)
-> (forall x. Rep TagResource x -> TagResource)
-> Generic TagResource
forall x. Rep TagResource x -> TagResource
forall x. TagResource -> Rep TagResource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TagResource x -> TagResource
$cfrom :: forall x. TagResource -> Rep TagResource x
Prelude.Generic)

-- |
-- Create a value of 'TagResource' 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:
--
-- 'secretId', 'tagResource_secretId' - The identifier for the secret that you want to attach tags to. You can
-- specify either the Amazon Resource Name (ARN) or the friendly name of
-- the secret.
--
-- For an ARN, we recommend that you specify a complete ARN rather than a
-- partial ARN.
--
-- 'tags', 'tagResource_tags' - The tags to attach to the secret. Each element in the list consists of a
-- @Key@ and a @Value@.
--
-- This parameter to the API requires a JSON text string argument.
--
-- For storing multiple values, we recommend that you use a JSON text
-- string argument and specify key\/value pairs. For more information, see
-- <https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters.html Specifying parameter values for the Amazon Web Services CLI>
-- in the Amazon Web Services CLI User Guide.
newTagResource ::
  -- | 'secretId'
  Prelude.Text ->
  TagResource
newTagResource :: Text -> TagResource
newTagResource Text
pSecretId_ =
  TagResource' :: Text -> [Tag] -> TagResource
TagResource'
    { $sel:secretId:TagResource' :: Text
secretId = Text
pSecretId_,
      $sel:tags:TagResource' :: [Tag]
tags = [Tag]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The identifier for the secret that you want to attach tags to. You can
-- specify either the Amazon Resource Name (ARN) or the friendly name of
-- the secret.
--
-- For an ARN, we recommend that you specify a complete ARN rather than a
-- partial ARN.
tagResource_secretId :: Lens.Lens' TagResource Prelude.Text
tagResource_secretId :: (Text -> f Text) -> TagResource -> f TagResource
tagResource_secretId = (TagResource -> Text)
-> (TagResource -> Text -> TagResource)
-> Lens TagResource TagResource Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagResource' {Text
secretId :: Text
$sel:secretId:TagResource' :: TagResource -> Text
secretId} -> Text
secretId) (\s :: TagResource
s@TagResource' {} Text
a -> TagResource
s {$sel:secretId:TagResource' :: Text
secretId = Text
a} :: TagResource)

-- | The tags to attach to the secret. Each element in the list consists of a
-- @Key@ and a @Value@.
--
-- This parameter to the API requires a JSON text string argument.
--
-- For storing multiple values, we recommend that you use a JSON text
-- string argument and specify key\/value pairs. For more information, see
-- <https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters.html Specifying parameter values for the Amazon Web Services CLI>
-- in the Amazon Web Services CLI User Guide.
tagResource_tags :: Lens.Lens' TagResource [Tag]
tagResource_tags :: ([Tag] -> f [Tag]) -> TagResource -> f TagResource
tagResource_tags = (TagResource -> [Tag])
-> (TagResource -> [Tag] -> TagResource)
-> Lens TagResource TagResource [Tag] [Tag]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagResource' {[Tag]
tags :: [Tag]
$sel:tags:TagResource' :: TagResource -> [Tag]
tags} -> [Tag]
tags) (\s :: TagResource
s@TagResource' {} [Tag]
a -> TagResource
s {$sel:tags:TagResource' :: [Tag]
tags = [Tag]
a} :: TagResource) (([Tag] -> f [Tag]) -> TagResource -> f TagResource)
-> (([Tag] -> f [Tag]) -> [Tag] -> f [Tag])
-> ([Tag] -> f [Tag])
-> TagResource
-> f TagResource
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Tag] -> f [Tag]) -> [Tag] -> f [Tag]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest TagResource where
  type AWSResponse TagResource = TagResourceResponse
  request :: TagResource -> Request TagResource
request = Service -> TagResource -> Request TagResource
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy TagResource
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse TagResource)))
response = AWSResponse TagResource
-> Logger
-> Service
-> Proxy TagResource
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse TagResource)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse TagResource
TagResourceResponse
TagResourceResponse'

instance Prelude.Hashable TagResource

instance Prelude.NFData TagResource

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

instance Core.ToJSON TagResource where
  toJSON :: TagResource -> Value
toJSON TagResource' {[Tag]
Text
tags :: [Tag]
secretId :: Text
$sel:tags:TagResource' :: TagResource -> [Tag]
$sel:secretId:TagResource' :: TagResource -> 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
"SecretId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
secretId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Tags" Text -> [Tag] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Tag]
tags)
          ]
      )

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

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

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

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

instance Prelude.NFData TagResourceResponse