{-# 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-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)
--
-- 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.
--
-- If multiple Amazon Web Services accounts are sending logs to this
-- destination, each sender account must be listed separately in the
-- policy. The policy does not support specifying @*@ as the Principal or
-- the use of the @aws:PrincipalOrgId@ global key.
module Amazonka.CloudWatchLogs.PutDestinationPolicy
  ( -- * Creating a Request
    PutDestinationPolicy (..),
    newPutDestinationPolicy,

    -- * Request Lenses
    putDestinationPolicy_destinationName,
    putDestinationPolicy_accessPolicy,

    -- * Destructuring the Response
    PutDestinationPolicyResponse (..),
    newPutDestinationPolicyResponse,
  )
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:/ 'newPutDestinationPolicy' smart constructor.
data PutDestinationPolicy = PutDestinationPolicy'
  { -- | 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
(PutDestinationPolicy -> PutDestinationPolicy -> Bool)
-> (PutDestinationPolicy -> PutDestinationPolicy -> Bool)
-> Eq PutDestinationPolicy
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]
(Int -> ReadS PutDestinationPolicy)
-> ReadS [PutDestinationPolicy]
-> ReadPrec PutDestinationPolicy
-> ReadPrec [PutDestinationPolicy]
-> Read 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
(Int -> PutDestinationPolicy -> ShowS)
-> (PutDestinationPolicy -> String)
-> ([PutDestinationPolicy] -> ShowS)
-> Show PutDestinationPolicy
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. PutDestinationPolicy -> Rep PutDestinationPolicy x)
-> (forall x. Rep PutDestinationPolicy x -> PutDestinationPolicy)
-> Generic PutDestinationPolicy
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:
--
-- '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' :: Text -> Text -> PutDestinationPolicy
PutDestinationPolicy'
      { $sel:destinationName:PutDestinationPolicy' :: Text
destinationName =
          Text
pDestinationName_,
        $sel:accessPolicy:PutDestinationPolicy' :: Text
accessPolicy = Text
pAccessPolicy_
      }

-- | A name for an existing destination.
putDestinationPolicy_destinationName :: Lens.Lens' PutDestinationPolicy Prelude.Text
putDestinationPolicy_destinationName :: (Text -> f Text) -> PutDestinationPolicy -> f PutDestinationPolicy
putDestinationPolicy_destinationName = (PutDestinationPolicy -> Text)
-> (PutDestinationPolicy -> Text -> PutDestinationPolicy)
-> Lens PutDestinationPolicy PutDestinationPolicy Text Text
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 :: (Text -> f Text) -> PutDestinationPolicy -> f PutDestinationPolicy
putDestinationPolicy_accessPolicy = (PutDestinationPolicy -> Text)
-> (PutDestinationPolicy -> Text -> PutDestinationPolicy)
-> Lens PutDestinationPolicy PutDestinationPolicy Text Text
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 :: PutDestinationPolicy -> Request PutDestinationPolicy
request = Service -> PutDestinationPolicy -> Request PutDestinationPolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutDestinationPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutDestinationPolicy)))
response =
    AWSResponse PutDestinationPolicy
-> Logger
-> Service
-> Proxy PutDestinationPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutDestinationPolicy)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse PutDestinationPolicy
PutDestinationPolicyResponse
PutDestinationPolicyResponse'

instance Prelude.Hashable PutDestinationPolicy

instance Prelude.NFData PutDestinationPolicy

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

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

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

-- | /See:/ 'newPutDestinationPolicyResponse' smart constructor.
data PutDestinationPolicyResponse = PutDestinationPolicyResponse'
  {
  }
  deriving (PutDestinationPolicyResponse
-> PutDestinationPolicyResponse -> Bool
(PutDestinationPolicyResponse
 -> PutDestinationPolicyResponse -> Bool)
-> (PutDestinationPolicyResponse
    -> PutDestinationPolicyResponse -> Bool)
-> Eq PutDestinationPolicyResponse
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]
(Int -> ReadS PutDestinationPolicyResponse)
-> ReadS [PutDestinationPolicyResponse]
-> ReadPrec PutDestinationPolicyResponse
-> ReadPrec [PutDestinationPolicyResponse]
-> Read 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
(Int -> PutDestinationPolicyResponse -> ShowS)
-> (PutDestinationPolicyResponse -> String)
-> ([PutDestinationPolicyResponse] -> ShowS)
-> Show PutDestinationPolicyResponse
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.
 PutDestinationPolicyResponse -> Rep PutDestinationPolicyResponse x)
-> (forall x.
    Rep PutDestinationPolicyResponse x -> PutDestinationPolicyResponse)
-> Generic PutDestinationPolicyResponse
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