{-# 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.SES.PutIdentityPolicy
-- 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 or updates a sending authorization policy for the specified
-- identity (an email address or a domain).
--
-- This API is for the identity owner only. If you have not verified the
-- identity, this API will return an error.
--
-- Sending authorization is a feature that enables an identity owner to
-- authorize other senders to use its identities. For information about
-- using sending authorization, see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-authorization.html Amazon SES Developer Guide>.
--
-- You can execute this operation no more than once per second.
module Amazonka.SES.PutIdentityPolicy
  ( -- * Creating a Request
    PutIdentityPolicy (..),
    newPutIdentityPolicy,

    -- * Request Lenses
    putIdentityPolicy_identity,
    putIdentityPolicy_policyName,
    putIdentityPolicy_policy,

    -- * Destructuring the Response
    PutIdentityPolicyResponse (..),
    newPutIdentityPolicyResponse,

    -- * Response Lenses
    putIdentityPolicyResponse_httpStatus,
  )
where

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

-- | Represents a request to add or update a sending authorization policy for
-- an identity. Sending authorization is an Amazon SES feature that enables
-- you to authorize other senders to use your identities. For information,
-- see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-authorization.html Amazon SES Developer Guide>.
--
-- /See:/ 'newPutIdentityPolicy' smart constructor.
data PutIdentityPolicy = PutIdentityPolicy'
  { -- | The identity that the policy will apply to. You can specify an identity
    -- by using its name or by using its Amazon Resource Name (ARN). Examples:
    -- @user\@example.com@, @example.com@,
    -- @arn:aws:ses:us-east-1:123456789012:identity\/example.com@.
    --
    -- To successfully call this API, you must own the identity.
    PutIdentityPolicy -> Text
identity :: Prelude.Text,
    -- | The name of the policy.
    --
    -- The policy name cannot exceed 64 characters and can only include
    -- alphanumeric characters, dashes, and underscores.
    PutIdentityPolicy -> Text
policyName :: Prelude.Text,
    -- | The text of the policy in JSON format. The policy cannot exceed 4 KB.
    --
    -- For information about the syntax of sending authorization policies, see
    -- the
    -- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-authorization-policies.html Amazon SES Developer Guide>.
    PutIdentityPolicy -> Text
policy :: Prelude.Text
  }
  deriving (PutIdentityPolicy -> PutIdentityPolicy -> Bool
(PutIdentityPolicy -> PutIdentityPolicy -> Bool)
-> (PutIdentityPolicy -> PutIdentityPolicy -> Bool)
-> Eq PutIdentityPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PutIdentityPolicy -> PutIdentityPolicy -> Bool
== :: PutIdentityPolicy -> PutIdentityPolicy -> Bool
$c/= :: PutIdentityPolicy -> PutIdentityPolicy -> Bool
/= :: PutIdentityPolicy -> PutIdentityPolicy -> Bool
Prelude.Eq, ReadPrec [PutIdentityPolicy]
ReadPrec PutIdentityPolicy
Int -> ReadS PutIdentityPolicy
ReadS [PutIdentityPolicy]
(Int -> ReadS PutIdentityPolicy)
-> ReadS [PutIdentityPolicy]
-> ReadPrec PutIdentityPolicy
-> ReadPrec [PutIdentityPolicy]
-> Read PutIdentityPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS PutIdentityPolicy
readsPrec :: Int -> ReadS PutIdentityPolicy
$creadList :: ReadS [PutIdentityPolicy]
readList :: ReadS [PutIdentityPolicy]
$creadPrec :: ReadPrec PutIdentityPolicy
readPrec :: ReadPrec PutIdentityPolicy
$creadListPrec :: ReadPrec [PutIdentityPolicy]
readListPrec :: ReadPrec [PutIdentityPolicy]
Prelude.Read, Int -> PutIdentityPolicy -> ShowS
[PutIdentityPolicy] -> ShowS
PutIdentityPolicy -> String
(Int -> PutIdentityPolicy -> ShowS)
-> (PutIdentityPolicy -> String)
-> ([PutIdentityPolicy] -> ShowS)
-> Show PutIdentityPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PutIdentityPolicy -> ShowS
showsPrec :: Int -> PutIdentityPolicy -> ShowS
$cshow :: PutIdentityPolicy -> String
show :: PutIdentityPolicy -> String
$cshowList :: [PutIdentityPolicy] -> ShowS
showList :: [PutIdentityPolicy] -> ShowS
Prelude.Show, (forall x. PutIdentityPolicy -> Rep PutIdentityPolicy x)
-> (forall x. Rep PutIdentityPolicy x -> PutIdentityPolicy)
-> Generic PutIdentityPolicy
forall x. Rep PutIdentityPolicy x -> PutIdentityPolicy
forall x. PutIdentityPolicy -> Rep PutIdentityPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PutIdentityPolicy -> Rep PutIdentityPolicy x
from :: forall x. PutIdentityPolicy -> Rep PutIdentityPolicy x
$cto :: forall x. Rep PutIdentityPolicy x -> PutIdentityPolicy
to :: forall x. Rep PutIdentityPolicy x -> PutIdentityPolicy
Prelude.Generic)

-- |
-- Create a value of 'PutIdentityPolicy' 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:
--
-- 'identity', 'putIdentityPolicy_identity' - The identity that the policy will apply to. You can specify an identity
-- by using its name or by using its Amazon Resource Name (ARN). Examples:
-- @user\@example.com@, @example.com@,
-- @arn:aws:ses:us-east-1:123456789012:identity\/example.com@.
--
-- To successfully call this API, you must own the identity.
--
-- 'policyName', 'putIdentityPolicy_policyName' - The name of the policy.
--
-- The policy name cannot exceed 64 characters and can only include
-- alphanumeric characters, dashes, and underscores.
--
-- 'policy', 'putIdentityPolicy_policy' - The text of the policy in JSON format. The policy cannot exceed 4 KB.
--
-- For information about the syntax of sending authorization policies, see
-- the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-authorization-policies.html Amazon SES Developer Guide>.
newPutIdentityPolicy ::
  -- | 'identity'
  Prelude.Text ->
  -- | 'policyName'
  Prelude.Text ->
  -- | 'policy'
  Prelude.Text ->
  PutIdentityPolicy
newPutIdentityPolicy :: Text -> Text -> Text -> PutIdentityPolicy
newPutIdentityPolicy Text
pIdentity_ Text
pPolicyName_ Text
pPolicy_ =
  PutIdentityPolicy'
    { $sel:identity:PutIdentityPolicy' :: Text
identity = Text
pIdentity_,
      $sel:policyName:PutIdentityPolicy' :: Text
policyName = Text
pPolicyName_,
      $sel:policy:PutIdentityPolicy' :: Text
policy = Text
pPolicy_
    }

-- | The identity that the policy will apply to. You can specify an identity
-- by using its name or by using its Amazon Resource Name (ARN). Examples:
-- @user\@example.com@, @example.com@,
-- @arn:aws:ses:us-east-1:123456789012:identity\/example.com@.
--
-- To successfully call this API, you must own the identity.
putIdentityPolicy_identity :: Lens.Lens' PutIdentityPolicy Prelude.Text
putIdentityPolicy_identity :: Lens' PutIdentityPolicy Text
putIdentityPolicy_identity = (PutIdentityPolicy -> Text)
-> (PutIdentityPolicy -> Text -> PutIdentityPolicy)
-> Lens' PutIdentityPolicy Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutIdentityPolicy' {Text
$sel:identity:PutIdentityPolicy' :: PutIdentityPolicy -> Text
identity :: Text
identity} -> Text
identity) (\s :: PutIdentityPolicy
s@PutIdentityPolicy' {} Text
a -> PutIdentityPolicy
s {identity = a} :: PutIdentityPolicy)

-- | The name of the policy.
--
-- The policy name cannot exceed 64 characters and can only include
-- alphanumeric characters, dashes, and underscores.
putIdentityPolicy_policyName :: Lens.Lens' PutIdentityPolicy Prelude.Text
putIdentityPolicy_policyName :: Lens' PutIdentityPolicy Text
putIdentityPolicy_policyName = (PutIdentityPolicy -> Text)
-> (PutIdentityPolicy -> Text -> PutIdentityPolicy)
-> Lens' PutIdentityPolicy Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutIdentityPolicy' {Text
$sel:policyName:PutIdentityPolicy' :: PutIdentityPolicy -> Text
policyName :: Text
policyName} -> Text
policyName) (\s :: PutIdentityPolicy
s@PutIdentityPolicy' {} Text
a -> PutIdentityPolicy
s {policyName = a} :: PutIdentityPolicy)

-- | The text of the policy in JSON format. The policy cannot exceed 4 KB.
--
-- For information about the syntax of sending authorization policies, see
-- the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-authorization-policies.html Amazon SES Developer Guide>.
putIdentityPolicy_policy :: Lens.Lens' PutIdentityPolicy Prelude.Text
putIdentityPolicy_policy :: Lens' PutIdentityPolicy Text
putIdentityPolicy_policy = (PutIdentityPolicy -> Text)
-> (PutIdentityPolicy -> Text -> PutIdentityPolicy)
-> Lens' PutIdentityPolicy Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutIdentityPolicy' {Text
$sel:policy:PutIdentityPolicy' :: PutIdentityPolicy -> Text
policy :: Text
policy} -> Text
policy) (\s :: PutIdentityPolicy
s@PutIdentityPolicy' {} Text
a -> PutIdentityPolicy
s {policy = a} :: PutIdentityPolicy)

instance Core.AWSRequest PutIdentityPolicy where
  type
    AWSResponse PutIdentityPolicy =
      PutIdentityPolicyResponse
  request :: (Service -> Service)
-> PutIdentityPolicy -> Request PutIdentityPolicy
request Service -> Service
overrides =
    Service -> PutIdentityPolicy -> Request PutIdentityPolicy
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy PutIdentityPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutIdentityPolicy)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse PutIdentityPolicy))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy PutIdentityPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutIdentityPolicy)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"PutIdentityPolicyResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Int -> PutIdentityPolicyResponse
PutIdentityPolicyResponse'
            (Int -> PutIdentityPolicyResponse)
-> Either String Int -> Either String PutIdentityPolicyResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall a. a -> Either String a
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable PutIdentityPolicy where
  hashWithSalt :: Int -> PutIdentityPolicy -> Int
hashWithSalt Int
_salt PutIdentityPolicy' {Text
$sel:identity:PutIdentityPolicy' :: PutIdentityPolicy -> Text
$sel:policyName:PutIdentityPolicy' :: PutIdentityPolicy -> Text
$sel:policy:PutIdentityPolicy' :: PutIdentityPolicy -> Text
identity :: Text
policyName :: Text
policy :: Text
..} =
    Int
_salt
      Int -> Text -> Int
forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
identity
      Int -> Text -> Int
forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
policyName
      Int -> Text -> Int
forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
policy

instance Prelude.NFData PutIdentityPolicy where
  rnf :: PutIdentityPolicy -> ()
rnf PutIdentityPolicy' {Text
$sel:identity:PutIdentityPolicy' :: PutIdentityPolicy -> Text
$sel:policyName:PutIdentityPolicy' :: PutIdentityPolicy -> Text
$sel:policy:PutIdentityPolicy' :: PutIdentityPolicy -> Text
identity :: Text
policyName :: Text
policy :: Text
..} =
    Text -> ()
forall a. NFData a => a -> ()
Prelude.rnf Text
identity
      () -> () -> ()
forall a b. a -> b -> b
`Prelude.seq` Text -> ()
forall a. NFData a => a -> ()
Prelude.rnf Text
policyName
      () -> () -> ()
forall a b. a -> b -> b
`Prelude.seq` Text -> ()
forall a. NFData a => a -> ()
Prelude.rnf Text
policy

instance Data.ToHeaders PutIdentityPolicy where
  toHeaders :: PutIdentityPolicy -> ResponseHeaders
toHeaders = ResponseHeaders -> PutIdentityPolicy -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

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

instance Data.ToQuery PutIdentityPolicy where
  toQuery :: PutIdentityPolicy -> QueryString
toQuery PutIdentityPolicy' {Text
$sel:identity:PutIdentityPolicy' :: PutIdentityPolicy -> Text
$sel:policyName:PutIdentityPolicy' :: PutIdentityPolicy -> Text
$sel:policy:PutIdentityPolicy' :: PutIdentityPolicy -> Text
identity :: Text
policyName :: Text
policy :: Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"PutIdentityPolicy" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2010-12-01" :: Prelude.ByteString),
        ByteString
"Identity" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
identity,
        ByteString
"PolicyName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
policyName,
        ByteString
"Policy" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
policy
      ]

-- | An empty element returned on a successful request.
--
-- /See:/ 'newPutIdentityPolicyResponse' smart constructor.
data PutIdentityPolicyResponse = PutIdentityPolicyResponse'
  { -- | The response's http status code.
    PutIdentityPolicyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (PutIdentityPolicyResponse -> PutIdentityPolicyResponse -> Bool
(PutIdentityPolicyResponse -> PutIdentityPolicyResponse -> Bool)
-> (PutIdentityPolicyResponse -> PutIdentityPolicyResponse -> Bool)
-> Eq PutIdentityPolicyResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PutIdentityPolicyResponse -> PutIdentityPolicyResponse -> Bool
== :: PutIdentityPolicyResponse -> PutIdentityPolicyResponse -> Bool
$c/= :: PutIdentityPolicyResponse -> PutIdentityPolicyResponse -> Bool
/= :: PutIdentityPolicyResponse -> PutIdentityPolicyResponse -> Bool
Prelude.Eq, ReadPrec [PutIdentityPolicyResponse]
ReadPrec PutIdentityPolicyResponse
Int -> ReadS PutIdentityPolicyResponse
ReadS [PutIdentityPolicyResponse]
(Int -> ReadS PutIdentityPolicyResponse)
-> ReadS [PutIdentityPolicyResponse]
-> ReadPrec PutIdentityPolicyResponse
-> ReadPrec [PutIdentityPolicyResponse]
-> Read PutIdentityPolicyResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS PutIdentityPolicyResponse
readsPrec :: Int -> ReadS PutIdentityPolicyResponse
$creadList :: ReadS [PutIdentityPolicyResponse]
readList :: ReadS [PutIdentityPolicyResponse]
$creadPrec :: ReadPrec PutIdentityPolicyResponse
readPrec :: ReadPrec PutIdentityPolicyResponse
$creadListPrec :: ReadPrec [PutIdentityPolicyResponse]
readListPrec :: ReadPrec [PutIdentityPolicyResponse]
Prelude.Read, Int -> PutIdentityPolicyResponse -> ShowS
[PutIdentityPolicyResponse] -> ShowS
PutIdentityPolicyResponse -> String
(Int -> PutIdentityPolicyResponse -> ShowS)
-> (PutIdentityPolicyResponse -> String)
-> ([PutIdentityPolicyResponse] -> ShowS)
-> Show PutIdentityPolicyResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PutIdentityPolicyResponse -> ShowS
showsPrec :: Int -> PutIdentityPolicyResponse -> ShowS
$cshow :: PutIdentityPolicyResponse -> String
show :: PutIdentityPolicyResponse -> String
$cshowList :: [PutIdentityPolicyResponse] -> ShowS
showList :: [PutIdentityPolicyResponse] -> ShowS
Prelude.Show, (forall x.
 PutIdentityPolicyResponse -> Rep PutIdentityPolicyResponse x)
-> (forall x.
    Rep PutIdentityPolicyResponse x -> PutIdentityPolicyResponse)
-> Generic PutIdentityPolicyResponse
forall x.
Rep PutIdentityPolicyResponse x -> PutIdentityPolicyResponse
forall x.
PutIdentityPolicyResponse -> Rep PutIdentityPolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x.
PutIdentityPolicyResponse -> Rep PutIdentityPolicyResponse x
from :: forall x.
PutIdentityPolicyResponse -> Rep PutIdentityPolicyResponse x
$cto :: forall x.
Rep PutIdentityPolicyResponse x -> PutIdentityPolicyResponse
to :: forall x.
Rep PutIdentityPolicyResponse x -> PutIdentityPolicyResponse
Prelude.Generic)

-- |
-- Create a value of 'PutIdentityPolicyResponse' 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:
--
-- 'httpStatus', 'putIdentityPolicyResponse_httpStatus' - The response's http status code.
newPutIdentityPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutIdentityPolicyResponse
newPutIdentityPolicyResponse :: Int -> PutIdentityPolicyResponse
newPutIdentityPolicyResponse Int
pHttpStatus_ =
  PutIdentityPolicyResponse'
    { $sel:httpStatus:PutIdentityPolicyResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

-- | The response's http status code.
putIdentityPolicyResponse_httpStatus :: Lens.Lens' PutIdentityPolicyResponse Prelude.Int
putIdentityPolicyResponse_httpStatus :: Lens' PutIdentityPolicyResponse Int
putIdentityPolicyResponse_httpStatus = (PutIdentityPolicyResponse -> Int)
-> (PutIdentityPolicyResponse -> Int -> PutIdentityPolicyResponse)
-> Lens' PutIdentityPolicyResponse Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutIdentityPolicyResponse' {Int
$sel:httpStatus:PutIdentityPolicyResponse' :: PutIdentityPolicyResponse -> Int
httpStatus :: Int
httpStatus} -> Int
httpStatus) (\s :: PutIdentityPolicyResponse
s@PutIdentityPolicyResponse' {} Int
a -> PutIdentityPolicyResponse
s {httpStatus = a} :: PutIdentityPolicyResponse)

instance Prelude.NFData PutIdentityPolicyResponse where
  rnf :: PutIdentityPolicyResponse -> ()
rnf PutIdentityPolicyResponse' {Int
$sel:httpStatus:PutIdentityPolicyResponse' :: PutIdentityPolicyResponse -> Int
httpStatus :: Int
..} =
    Int -> ()
forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus