{-# 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.PutDestinationPolicy
-- 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 or updates an access policy associated with an existing
-- destination. An access policy is an
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/policies_overview.html IAM policy document>
-- that is used to authorize claims to register a subscription filter
-- against a given destination.
module Amazonka.CloudWatchLogs.PutDestinationPolicy
  ( -- * Creating a Request
    PutDestinationPolicy (..),
    newPutDestinationPolicy,

    -- * Request Lenses
    putDestinationPolicy_forceUpdate,
    putDestinationPolicy_destinationName,
    putDestinationPolicy_accessPolicy,

    -- * Destructuring the Response
    PutDestinationPolicyResponse (..),
    newPutDestinationPolicyResponse,
  )
where

import Amazonka.CloudWatchLogs.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:/ 'newPutDestinationPolicy' smart constructor.
data PutDestinationPolicy = PutDestinationPolicy'
  { -- | Specify true if you are updating an existing destination policy to grant
    -- permission to an organization ID instead of granting permission to
    -- individual AWS accounts. Before you update a destination policy this
    -- way, you must first update the subscription filters in the accounts that
    -- send logs to this destination. If you do not, the subscription filters
    -- might stop working. By specifying @true@ for @forceUpdate@, you are
    -- affirming that you have already updated the subscription filters. For
    -- more information, see
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Cross-Account-Log_Subscription-Update.html Updating an existing cross-account subscription>
    --
    -- If you omit this parameter, the default of @false@ is used.
    PutDestinationPolicy -> Maybe Bool
forceUpdate :: Prelude.Maybe Prelude.Bool,
    -- | A name for an existing destination.
    PutDestinationPolicy -> Text
destinationName :: Prelude.Text,
    -- | An IAM policy document that authorizes cross-account users to deliver
    -- their log events to the associated destination. This can be up to 5120
    -- bytes.
    PutDestinationPolicy -> Text
accessPolicy :: Prelude.Text
  }
  deriving (PutDestinationPolicy -> PutDestinationPolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutDestinationPolicy -> PutDestinationPolicy -> Bool
$c/= :: PutDestinationPolicy -> PutDestinationPolicy -> Bool
== :: PutDestinationPolicy -> PutDestinationPolicy -> Bool
$c== :: PutDestinationPolicy -> PutDestinationPolicy -> Bool
Prelude.Eq, ReadPrec [PutDestinationPolicy]
ReadPrec PutDestinationPolicy
Int -> ReadS PutDestinationPolicy
ReadS [PutDestinationPolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutDestinationPolicy]
$creadListPrec :: ReadPrec [PutDestinationPolicy]
readPrec :: ReadPrec PutDestinationPolicy
$creadPrec :: ReadPrec PutDestinationPolicy
readList :: ReadS [PutDestinationPolicy]
$creadList :: ReadS [PutDestinationPolicy]
readsPrec :: Int -> ReadS PutDestinationPolicy
$creadsPrec :: Int -> ReadS PutDestinationPolicy
Prelude.Read, Int -> PutDestinationPolicy -> ShowS
[PutDestinationPolicy] -> ShowS
PutDestinationPolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutDestinationPolicy] -> ShowS
$cshowList :: [PutDestinationPolicy] -> ShowS
show :: PutDestinationPolicy -> String
$cshow :: PutDestinationPolicy -> String
showsPrec :: Int -> PutDestinationPolicy -> ShowS
$cshowsPrec :: Int -> PutDestinationPolicy -> ShowS
Prelude.Show, forall x. Rep PutDestinationPolicy x -> PutDestinationPolicy
forall x. PutDestinationPolicy -> Rep PutDestinationPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutDestinationPolicy x -> PutDestinationPolicy
$cfrom :: forall x. PutDestinationPolicy -> Rep PutDestinationPolicy x
Prelude.Generic)

-- |
-- Create a value of 'PutDestinationPolicy' 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:
--
-- 'forceUpdate', 'putDestinationPolicy_forceUpdate' - Specify true if you are updating an existing destination policy to grant
-- permission to an organization ID instead of granting permission to
-- individual AWS accounts. Before you update a destination policy this
-- way, you must first update the subscription filters in the accounts that
-- send logs to this destination. If you do not, the subscription filters
-- might stop working. By specifying @true@ for @forceUpdate@, you are
-- affirming that you have already updated the subscription filters. For
-- more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Cross-Account-Log_Subscription-Update.html Updating an existing cross-account subscription>
--
-- If you omit this parameter, the default of @false@ is used.
--
-- 'destinationName', 'putDestinationPolicy_destinationName' - A name for an existing destination.
--
-- 'accessPolicy', 'putDestinationPolicy_accessPolicy' - An IAM policy document that authorizes cross-account users to deliver
-- their log events to the associated destination. This can be up to 5120
-- bytes.
newPutDestinationPolicy ::
  -- | 'destinationName'
  Prelude.Text ->
  -- | 'accessPolicy'
  Prelude.Text ->
  PutDestinationPolicy
newPutDestinationPolicy :: Text -> Text -> PutDestinationPolicy
newPutDestinationPolicy
  Text
pDestinationName_
  Text
pAccessPolicy_ =
    PutDestinationPolicy'
      { $sel:forceUpdate:PutDestinationPolicy' :: Maybe Bool
forceUpdate =
          forall a. Maybe a
Prelude.Nothing,
        $sel:destinationName:PutDestinationPolicy' :: Text
destinationName = Text
pDestinationName_,
        $sel:accessPolicy:PutDestinationPolicy' :: Text
accessPolicy = Text
pAccessPolicy_
      }

-- | Specify true if you are updating an existing destination policy to grant
-- permission to an organization ID instead of granting permission to
-- individual AWS accounts. Before you update a destination policy this
-- way, you must first update the subscription filters in the accounts that
-- send logs to this destination. If you do not, the subscription filters
-- might stop working. By specifying @true@ for @forceUpdate@, you are
-- affirming that you have already updated the subscription filters. For
-- more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Cross-Account-Log_Subscription-Update.html Updating an existing cross-account subscription>
--
-- If you omit this parameter, the default of @false@ is used.
putDestinationPolicy_forceUpdate :: Lens.Lens' PutDestinationPolicy (Prelude.Maybe Prelude.Bool)
putDestinationPolicy_forceUpdate :: Lens' PutDestinationPolicy (Maybe Bool)
putDestinationPolicy_forceUpdate = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutDestinationPolicy' {Maybe Bool
forceUpdate :: Maybe Bool
$sel:forceUpdate:PutDestinationPolicy' :: PutDestinationPolicy -> Maybe Bool
forceUpdate} -> Maybe Bool
forceUpdate) (\s :: PutDestinationPolicy
s@PutDestinationPolicy' {} Maybe Bool
a -> PutDestinationPolicy
s {$sel:forceUpdate:PutDestinationPolicy' :: Maybe Bool
forceUpdate = Maybe Bool
a} :: PutDestinationPolicy)

-- | A name for an existing destination.
putDestinationPolicy_destinationName :: Lens.Lens' PutDestinationPolicy Prelude.Text
putDestinationPolicy_destinationName :: Lens' PutDestinationPolicy Text
putDestinationPolicy_destinationName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutDestinationPolicy' {Text
destinationName :: Text
$sel:destinationName:PutDestinationPolicy' :: PutDestinationPolicy -> Text
destinationName} -> Text
destinationName) (\s :: PutDestinationPolicy
s@PutDestinationPolicy' {} Text
a -> PutDestinationPolicy
s {$sel:destinationName:PutDestinationPolicy' :: Text
destinationName = Text
a} :: PutDestinationPolicy)

-- | An IAM policy document that authorizes cross-account users to deliver
-- their log events to the associated destination. This can be up to 5120
-- bytes.
putDestinationPolicy_accessPolicy :: Lens.Lens' PutDestinationPolicy Prelude.Text
putDestinationPolicy_accessPolicy :: Lens' PutDestinationPolicy Text
putDestinationPolicy_accessPolicy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutDestinationPolicy' {Text
accessPolicy :: Text
$sel:accessPolicy:PutDestinationPolicy' :: PutDestinationPolicy -> Text
accessPolicy} -> Text
accessPolicy) (\s :: PutDestinationPolicy
s@PutDestinationPolicy' {} Text
a -> PutDestinationPolicy
s {$sel:accessPolicy:PutDestinationPolicy' :: Text
accessPolicy = Text
a} :: PutDestinationPolicy)

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

instance Prelude.Hashable PutDestinationPolicy where
  hashWithSalt :: Int -> PutDestinationPolicy -> Int
hashWithSalt Int
_salt PutDestinationPolicy' {Maybe Bool
Text
accessPolicy :: Text
destinationName :: Text
forceUpdate :: Maybe Bool
$sel:accessPolicy:PutDestinationPolicy' :: PutDestinationPolicy -> Text
$sel:destinationName:PutDestinationPolicy' :: PutDestinationPolicy -> Text
$sel:forceUpdate:PutDestinationPolicy' :: PutDestinationPolicy -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
forceUpdate
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
destinationName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
accessPolicy

instance Prelude.NFData PutDestinationPolicy where
  rnf :: PutDestinationPolicy -> ()
rnf PutDestinationPolicy' {Maybe Bool
Text
accessPolicy :: Text
destinationName :: Text
forceUpdate :: Maybe Bool
$sel:accessPolicy:PutDestinationPolicy' :: PutDestinationPolicy -> Text
$sel:destinationName:PutDestinationPolicy' :: PutDestinationPolicy -> Text
$sel:forceUpdate:PutDestinationPolicy' :: PutDestinationPolicy -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
forceUpdate
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
destinationName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
accessPolicy

instance Data.ToHeaders PutDestinationPolicy where
  toHeaders :: PutDestinationPolicy -> [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
"Logs_20140328.PutDestinationPolicy" ::
                          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 PutDestinationPolicy where
  toJSON :: PutDestinationPolicy -> Value
toJSON PutDestinationPolicy' {Maybe Bool
Text
accessPolicy :: Text
destinationName :: Text
forceUpdate :: Maybe Bool
$sel:accessPolicy:PutDestinationPolicy' :: PutDestinationPolicy -> Text
$sel:destinationName:PutDestinationPolicy' :: PutDestinationPolicy -> Text
$sel:forceUpdate:PutDestinationPolicy' :: PutDestinationPolicy -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"forceUpdate" 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 Bool
forceUpdate,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"destinationName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
destinationName),
            forall a. a -> Maybe a
Prelude.Just (Key
"accessPolicy" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
accessPolicy)
          ]
      )

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

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

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

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

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