{-# 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.SESV2.GetEmailIdentityPolicies
-- 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)
--
-- Returns the requested sending authorization policies for the given
-- identity (an email address or a domain). The policies are returned as a
-- map of policy names to policy contents. You can retrieve a maximum of 20
-- policies at a time.
--
-- 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.SESV2.GetEmailIdentityPolicies
  ( -- * Creating a Request
    GetEmailIdentityPolicies (..),
    newGetEmailIdentityPolicies,

    -- * Request Lenses
    getEmailIdentityPolicies_emailIdentity,

    -- * Destructuring the Response
    GetEmailIdentityPoliciesResponse (..),
    newGetEmailIdentityPoliciesResponse,

    -- * Response Lenses
    getEmailIdentityPoliciesResponse_policies,
    getEmailIdentityPoliciesResponse_httpStatus,
  )
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.SESV2.Types

-- | A request to return the policies of an email identity.
--
-- /See:/ 'newGetEmailIdentityPolicies' smart constructor.
data GetEmailIdentityPolicies = GetEmailIdentityPolicies'
  { -- | The email identity.
    GetEmailIdentityPolicies -> Text
emailIdentity :: Prelude.Text
  }
  deriving (GetEmailIdentityPolicies -> GetEmailIdentityPolicies -> Bool
(GetEmailIdentityPolicies -> GetEmailIdentityPolicies -> Bool)
-> (GetEmailIdentityPolicies -> GetEmailIdentityPolicies -> Bool)
-> Eq GetEmailIdentityPolicies
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetEmailIdentityPolicies -> GetEmailIdentityPolicies -> Bool
$c/= :: GetEmailIdentityPolicies -> GetEmailIdentityPolicies -> Bool
== :: GetEmailIdentityPolicies -> GetEmailIdentityPolicies -> Bool
$c== :: GetEmailIdentityPolicies -> GetEmailIdentityPolicies -> Bool
Prelude.Eq, ReadPrec [GetEmailIdentityPolicies]
ReadPrec GetEmailIdentityPolicies
Int -> ReadS GetEmailIdentityPolicies
ReadS [GetEmailIdentityPolicies]
(Int -> ReadS GetEmailIdentityPolicies)
-> ReadS [GetEmailIdentityPolicies]
-> ReadPrec GetEmailIdentityPolicies
-> ReadPrec [GetEmailIdentityPolicies]
-> Read GetEmailIdentityPolicies
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetEmailIdentityPolicies]
$creadListPrec :: ReadPrec [GetEmailIdentityPolicies]
readPrec :: ReadPrec GetEmailIdentityPolicies
$creadPrec :: ReadPrec GetEmailIdentityPolicies
readList :: ReadS [GetEmailIdentityPolicies]
$creadList :: ReadS [GetEmailIdentityPolicies]
readsPrec :: Int -> ReadS GetEmailIdentityPolicies
$creadsPrec :: Int -> ReadS GetEmailIdentityPolicies
Prelude.Read, Int -> GetEmailIdentityPolicies -> ShowS
[GetEmailIdentityPolicies] -> ShowS
GetEmailIdentityPolicies -> String
(Int -> GetEmailIdentityPolicies -> ShowS)
-> (GetEmailIdentityPolicies -> String)
-> ([GetEmailIdentityPolicies] -> ShowS)
-> Show GetEmailIdentityPolicies
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetEmailIdentityPolicies] -> ShowS
$cshowList :: [GetEmailIdentityPolicies] -> ShowS
show :: GetEmailIdentityPolicies -> String
$cshow :: GetEmailIdentityPolicies -> String
showsPrec :: Int -> GetEmailIdentityPolicies -> ShowS
$cshowsPrec :: Int -> GetEmailIdentityPolicies -> ShowS
Prelude.Show, (forall x.
 GetEmailIdentityPolicies -> Rep GetEmailIdentityPolicies x)
-> (forall x.
    Rep GetEmailIdentityPolicies x -> GetEmailIdentityPolicies)
-> Generic GetEmailIdentityPolicies
forall x.
Rep GetEmailIdentityPolicies x -> GetEmailIdentityPolicies
forall x.
GetEmailIdentityPolicies -> Rep GetEmailIdentityPolicies x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetEmailIdentityPolicies x -> GetEmailIdentityPolicies
$cfrom :: forall x.
GetEmailIdentityPolicies -> Rep GetEmailIdentityPolicies x
Prelude.Generic)

-- |
-- Create a value of 'GetEmailIdentityPolicies' 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:
--
-- 'emailIdentity', 'getEmailIdentityPolicies_emailIdentity' - The email identity.
newGetEmailIdentityPolicies ::
  -- | 'emailIdentity'
  Prelude.Text ->
  GetEmailIdentityPolicies
newGetEmailIdentityPolicies :: Text -> GetEmailIdentityPolicies
newGetEmailIdentityPolicies Text
pEmailIdentity_ =
  GetEmailIdentityPolicies' :: Text -> GetEmailIdentityPolicies
GetEmailIdentityPolicies'
    { $sel:emailIdentity:GetEmailIdentityPolicies' :: Text
emailIdentity =
        Text
pEmailIdentity_
    }

-- | The email identity.
getEmailIdentityPolicies_emailIdentity :: Lens.Lens' GetEmailIdentityPolicies Prelude.Text
getEmailIdentityPolicies_emailIdentity :: (Text -> f Text)
-> GetEmailIdentityPolicies -> f GetEmailIdentityPolicies
getEmailIdentityPolicies_emailIdentity = (GetEmailIdentityPolicies -> Text)
-> (GetEmailIdentityPolicies -> Text -> GetEmailIdentityPolicies)
-> Lens GetEmailIdentityPolicies GetEmailIdentityPolicies Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetEmailIdentityPolicies' {Text
emailIdentity :: Text
$sel:emailIdentity:GetEmailIdentityPolicies' :: GetEmailIdentityPolicies -> Text
emailIdentity} -> Text
emailIdentity) (\s :: GetEmailIdentityPolicies
s@GetEmailIdentityPolicies' {} Text
a -> GetEmailIdentityPolicies
s {$sel:emailIdentity:GetEmailIdentityPolicies' :: Text
emailIdentity = Text
a} :: GetEmailIdentityPolicies)

instance Core.AWSRequest GetEmailIdentityPolicies where
  type
    AWSResponse GetEmailIdentityPolicies =
      GetEmailIdentityPoliciesResponse
  request :: GetEmailIdentityPolicies -> Request GetEmailIdentityPolicies
request = Service
-> GetEmailIdentityPolicies -> Request GetEmailIdentityPolicies
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetEmailIdentityPolicies
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetEmailIdentityPolicies)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetEmailIdentityPolicies))
-> Logger
-> Service
-> Proxy GetEmailIdentityPolicies
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetEmailIdentityPolicies)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe (HashMap Text Text)
-> Int -> GetEmailIdentityPoliciesResponse
GetEmailIdentityPoliciesResponse'
            (Maybe (HashMap Text Text)
 -> Int -> GetEmailIdentityPoliciesResponse)
-> Either String (Maybe (HashMap Text Text))
-> Either String (Int -> GetEmailIdentityPoliciesResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Policies" Either String (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text)
-> Either String (Maybe (HashMap Text Text))
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> GetEmailIdentityPoliciesResponse)
-> Either String Int
-> Either String GetEmailIdentityPoliciesResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
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 GetEmailIdentityPolicies

instance Prelude.NFData GetEmailIdentityPolicies

instance Core.ToHeaders GetEmailIdentityPolicies where
  toHeaders :: GetEmailIdentityPolicies -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetEmailIdentityPolicies -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToPath GetEmailIdentityPolicies where
  toPath :: GetEmailIdentityPolicies -> ByteString
toPath GetEmailIdentityPolicies' {Text
emailIdentity :: Text
$sel:emailIdentity:GetEmailIdentityPolicies' :: GetEmailIdentityPolicies -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/v2/email/identities/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
emailIdentity,
        ByteString
"/policies"
      ]

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

-- | Identity policies associated with email identity.
--
-- /See:/ 'newGetEmailIdentityPoliciesResponse' smart constructor.
data GetEmailIdentityPoliciesResponse = GetEmailIdentityPoliciesResponse'
  { -- | A map of policy names to policies.
    GetEmailIdentityPoliciesResponse -> Maybe (HashMap Text Text)
policies :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The response's http status code.
    GetEmailIdentityPoliciesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetEmailIdentityPoliciesResponse
-> GetEmailIdentityPoliciesResponse -> Bool
(GetEmailIdentityPoliciesResponse
 -> GetEmailIdentityPoliciesResponse -> Bool)
-> (GetEmailIdentityPoliciesResponse
    -> GetEmailIdentityPoliciesResponse -> Bool)
-> Eq GetEmailIdentityPoliciesResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetEmailIdentityPoliciesResponse
-> GetEmailIdentityPoliciesResponse -> Bool
$c/= :: GetEmailIdentityPoliciesResponse
-> GetEmailIdentityPoliciesResponse -> Bool
== :: GetEmailIdentityPoliciesResponse
-> GetEmailIdentityPoliciesResponse -> Bool
$c== :: GetEmailIdentityPoliciesResponse
-> GetEmailIdentityPoliciesResponse -> Bool
Prelude.Eq, ReadPrec [GetEmailIdentityPoliciesResponse]
ReadPrec GetEmailIdentityPoliciesResponse
Int -> ReadS GetEmailIdentityPoliciesResponse
ReadS [GetEmailIdentityPoliciesResponse]
(Int -> ReadS GetEmailIdentityPoliciesResponse)
-> ReadS [GetEmailIdentityPoliciesResponse]
-> ReadPrec GetEmailIdentityPoliciesResponse
-> ReadPrec [GetEmailIdentityPoliciesResponse]
-> Read GetEmailIdentityPoliciesResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetEmailIdentityPoliciesResponse]
$creadListPrec :: ReadPrec [GetEmailIdentityPoliciesResponse]
readPrec :: ReadPrec GetEmailIdentityPoliciesResponse
$creadPrec :: ReadPrec GetEmailIdentityPoliciesResponse
readList :: ReadS [GetEmailIdentityPoliciesResponse]
$creadList :: ReadS [GetEmailIdentityPoliciesResponse]
readsPrec :: Int -> ReadS GetEmailIdentityPoliciesResponse
$creadsPrec :: Int -> ReadS GetEmailIdentityPoliciesResponse
Prelude.Read, Int -> GetEmailIdentityPoliciesResponse -> ShowS
[GetEmailIdentityPoliciesResponse] -> ShowS
GetEmailIdentityPoliciesResponse -> String
(Int -> GetEmailIdentityPoliciesResponse -> ShowS)
-> (GetEmailIdentityPoliciesResponse -> String)
-> ([GetEmailIdentityPoliciesResponse] -> ShowS)
-> Show GetEmailIdentityPoliciesResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetEmailIdentityPoliciesResponse] -> ShowS
$cshowList :: [GetEmailIdentityPoliciesResponse] -> ShowS
show :: GetEmailIdentityPoliciesResponse -> String
$cshow :: GetEmailIdentityPoliciesResponse -> String
showsPrec :: Int -> GetEmailIdentityPoliciesResponse -> ShowS
$cshowsPrec :: Int -> GetEmailIdentityPoliciesResponse -> ShowS
Prelude.Show, (forall x.
 GetEmailIdentityPoliciesResponse
 -> Rep GetEmailIdentityPoliciesResponse x)
-> (forall x.
    Rep GetEmailIdentityPoliciesResponse x
    -> GetEmailIdentityPoliciesResponse)
-> Generic GetEmailIdentityPoliciesResponse
forall x.
Rep GetEmailIdentityPoliciesResponse x
-> GetEmailIdentityPoliciesResponse
forall x.
GetEmailIdentityPoliciesResponse
-> Rep GetEmailIdentityPoliciesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetEmailIdentityPoliciesResponse x
-> GetEmailIdentityPoliciesResponse
$cfrom :: forall x.
GetEmailIdentityPoliciesResponse
-> Rep GetEmailIdentityPoliciesResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetEmailIdentityPoliciesResponse' 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:
--
-- 'policies', 'getEmailIdentityPoliciesResponse_policies' - A map of policy names to policies.
--
-- 'httpStatus', 'getEmailIdentityPoliciesResponse_httpStatus' - The response's http status code.
newGetEmailIdentityPoliciesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetEmailIdentityPoliciesResponse
newGetEmailIdentityPoliciesResponse :: Int -> GetEmailIdentityPoliciesResponse
newGetEmailIdentityPoliciesResponse Int
pHttpStatus_ =
  GetEmailIdentityPoliciesResponse' :: Maybe (HashMap Text Text)
-> Int -> GetEmailIdentityPoliciesResponse
GetEmailIdentityPoliciesResponse'
    { $sel:policies:GetEmailIdentityPoliciesResponse' :: Maybe (HashMap Text Text)
policies =
        Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetEmailIdentityPoliciesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A map of policy names to policies.
getEmailIdentityPoliciesResponse_policies :: Lens.Lens' GetEmailIdentityPoliciesResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
getEmailIdentityPoliciesResponse_policies :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GetEmailIdentityPoliciesResponse
-> f GetEmailIdentityPoliciesResponse
getEmailIdentityPoliciesResponse_policies = (GetEmailIdentityPoliciesResponse -> Maybe (HashMap Text Text))
-> (GetEmailIdentityPoliciesResponse
    -> Maybe (HashMap Text Text) -> GetEmailIdentityPoliciesResponse)
-> Lens
     GetEmailIdentityPoliciesResponse
     GetEmailIdentityPoliciesResponse
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetEmailIdentityPoliciesResponse' {Maybe (HashMap Text Text)
policies :: Maybe (HashMap Text Text)
$sel:policies:GetEmailIdentityPoliciesResponse' :: GetEmailIdentityPoliciesResponse -> Maybe (HashMap Text Text)
policies} -> Maybe (HashMap Text Text)
policies) (\s :: GetEmailIdentityPoliciesResponse
s@GetEmailIdentityPoliciesResponse' {} Maybe (HashMap Text Text)
a -> GetEmailIdentityPoliciesResponse
s {$sel:policies:GetEmailIdentityPoliciesResponse' :: Maybe (HashMap Text Text)
policies = Maybe (HashMap Text Text)
a} :: GetEmailIdentityPoliciesResponse) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> GetEmailIdentityPoliciesResponse
 -> f GetEmailIdentityPoliciesResponse)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GetEmailIdentityPoliciesResponse
-> f GetEmailIdentityPoliciesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance
  Prelude.NFData
    GetEmailIdentityPoliciesResponse