{-# 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.CloudWatchLogs.TagLogGroup
-- 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)
--
-- Adds or updates the specified tags for the specified log group.
--
-- To list the tags for a log group, use
-- <https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_ListTagsLogGroup.html ListTagsLogGroup>.
-- To remove tags, use
-- <https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_UntagLogGroup.html UntagLogGroup>.
--
-- For more information about tags, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Working-with-log-groups-and-streams.html#log-group-tagging Tag Log Groups in Amazon CloudWatch Logs>
-- in the /Amazon CloudWatch Logs User Guide/.
--
-- CloudWatch Logs doesn’t support IAM policies that prevent users from
-- assigning specified tags to log groups using the
-- @aws:Resource\/key-name @ or @aws:TagKeys@ condition keys. For more
-- information about using tags to control access, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html Controlling access to Amazon Web Services resources using tags>.
module Amazonka.CloudWatchLogs.TagLogGroup
  ( -- * Creating a Request
    TagLogGroup (..),
    newTagLogGroup,

    -- * Request Lenses
    tagLogGroup_logGroupName,
    tagLogGroup_tags,

    -- * Destructuring the Response
    TagLogGroupResponse (..),
    newTagLogGroupResponse,
  )
where

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

-- | /See:/ 'newTagLogGroup' smart constructor.
data TagLogGroup = TagLogGroup'
  { -- | The name of the log group.
    TagLogGroup -> Text
logGroupName :: Prelude.Text,
    -- | The key-value pairs to use for the tags.
    TagLogGroup -> HashMap Text Text
tags :: Prelude.HashMap Prelude.Text Prelude.Text
  }
  deriving (TagLogGroup -> TagLogGroup -> Bool
(TagLogGroup -> TagLogGroup -> Bool)
-> (TagLogGroup -> TagLogGroup -> Bool) -> Eq TagLogGroup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TagLogGroup -> TagLogGroup -> Bool
$c/= :: TagLogGroup -> TagLogGroup -> Bool
== :: TagLogGroup -> TagLogGroup -> Bool
$c== :: TagLogGroup -> TagLogGroup -> Bool
Prelude.Eq, ReadPrec [TagLogGroup]
ReadPrec TagLogGroup
Int -> ReadS TagLogGroup
ReadS [TagLogGroup]
(Int -> ReadS TagLogGroup)
-> ReadS [TagLogGroup]
-> ReadPrec TagLogGroup
-> ReadPrec [TagLogGroup]
-> Read TagLogGroup
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TagLogGroup]
$creadListPrec :: ReadPrec [TagLogGroup]
readPrec :: ReadPrec TagLogGroup
$creadPrec :: ReadPrec TagLogGroup
readList :: ReadS [TagLogGroup]
$creadList :: ReadS [TagLogGroup]
readsPrec :: Int -> ReadS TagLogGroup
$creadsPrec :: Int -> ReadS TagLogGroup
Prelude.Read, Int -> TagLogGroup -> ShowS
[TagLogGroup] -> ShowS
TagLogGroup -> String
(Int -> TagLogGroup -> ShowS)
-> (TagLogGroup -> String)
-> ([TagLogGroup] -> ShowS)
-> Show TagLogGroup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TagLogGroup] -> ShowS
$cshowList :: [TagLogGroup] -> ShowS
show :: TagLogGroup -> String
$cshow :: TagLogGroup -> String
showsPrec :: Int -> TagLogGroup -> ShowS
$cshowsPrec :: Int -> TagLogGroup -> ShowS
Prelude.Show, (forall x. TagLogGroup -> Rep TagLogGroup x)
-> (forall x. Rep TagLogGroup x -> TagLogGroup)
-> Generic TagLogGroup
forall x. Rep TagLogGroup x -> TagLogGroup
forall x. TagLogGroup -> Rep TagLogGroup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TagLogGroup x -> TagLogGroup
$cfrom :: forall x. TagLogGroup -> Rep TagLogGroup x
Prelude.Generic)

-- |
-- Create a value of 'TagLogGroup' 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:
--
-- 'logGroupName', 'tagLogGroup_logGroupName' - The name of the log group.
--
-- 'tags', 'tagLogGroup_tags' - The key-value pairs to use for the tags.
newTagLogGroup ::
  -- | 'logGroupName'
  Prelude.Text ->
  TagLogGroup
newTagLogGroup :: Text -> TagLogGroup
newTagLogGroup Text
pLogGroupName_ =
  TagLogGroup' :: Text -> HashMap Text Text -> TagLogGroup
TagLogGroup'
    { $sel:logGroupName:TagLogGroup' :: Text
logGroupName = Text
pLogGroupName_,
      $sel:tags:TagLogGroup' :: HashMap Text Text
tags = HashMap Text Text
forall a. Monoid a => a
Prelude.mempty
    }

-- | The name of the log group.
tagLogGroup_logGroupName :: Lens.Lens' TagLogGroup Prelude.Text
tagLogGroup_logGroupName :: (Text -> f Text) -> TagLogGroup -> f TagLogGroup
tagLogGroup_logGroupName = (TagLogGroup -> Text)
-> (TagLogGroup -> Text -> TagLogGroup)
-> Lens TagLogGroup TagLogGroup Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagLogGroup' {Text
logGroupName :: Text
$sel:logGroupName:TagLogGroup' :: TagLogGroup -> Text
logGroupName} -> Text
logGroupName) (\s :: TagLogGroup
s@TagLogGroup' {} Text
a -> TagLogGroup
s {$sel:logGroupName:TagLogGroup' :: Text
logGroupName = Text
a} :: TagLogGroup)

-- | The key-value pairs to use for the tags.
tagLogGroup_tags :: Lens.Lens' TagLogGroup (Prelude.HashMap Prelude.Text Prelude.Text)
tagLogGroup_tags :: (HashMap Text Text -> f (HashMap Text Text))
-> TagLogGroup -> f TagLogGroup
tagLogGroup_tags = (TagLogGroup -> HashMap Text Text)
-> (TagLogGroup -> HashMap Text Text -> TagLogGroup)
-> Lens
     TagLogGroup TagLogGroup (HashMap Text Text) (HashMap Text Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagLogGroup' {HashMap Text Text
tags :: HashMap Text Text
$sel:tags:TagLogGroup' :: TagLogGroup -> HashMap Text Text
tags} -> HashMap Text Text
tags) (\s :: TagLogGroup
s@TagLogGroup' {} HashMap Text Text
a -> TagLogGroup
s {$sel:tags:TagLogGroup' :: HashMap Text Text
tags = HashMap Text Text
a} :: TagLogGroup) ((HashMap Text Text -> f (HashMap Text Text))
 -> TagLogGroup -> f TagLogGroup)
-> ((HashMap Text Text -> f (HashMap Text Text))
    -> HashMap Text Text -> f (HashMap Text Text))
-> (HashMap Text Text -> f (HashMap Text Text))
-> TagLogGroup
-> f TagLogGroup
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text Text -> f (HashMap Text Text))
-> HashMap Text Text -> f (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable TagLogGroup

instance Prelude.NFData TagLogGroup

instance Core.ToHeaders TagLogGroup where
  toHeaders :: TagLogGroup -> [Header]
toHeaders =
    [Header] -> TagLogGroup -> [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
"Logs_20140328.TagLogGroup" :: 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 TagLogGroup where
  toJSON :: TagLogGroup -> Value
toJSON TagLogGroup' {Text
HashMap Text Text
tags :: HashMap Text Text
logGroupName :: Text
$sel:tags:TagLogGroup' :: TagLogGroup -> HashMap Text Text
$sel:logGroupName:TagLogGroup' :: TagLogGroup -> 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
"logGroupName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
logGroupName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"tags" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text Text
tags)
          ]
      )

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

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

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

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

instance Prelude.NFData TagLogGroupResponse