{-# 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.WAF.GetPermissionPolicy
-- 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)
--
-- This is __AWS WAF Classic__ documentation. For more information, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/classic-waf-chapter.html AWS WAF Classic>
-- in the developer guide.
--
-- __For the latest version of AWS WAF__, use the AWS WAFV2 API and see the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html AWS WAF Developer Guide>.
-- With the latest version, AWS WAF has a single set of endpoints for
-- regional and global use.
--
-- Returns the IAM policy attached to the RuleGroup.
module Amazonka.WAF.GetPermissionPolicy
  ( -- * Creating a Request
    GetPermissionPolicy (..),
    newGetPermissionPolicy,

    -- * Request Lenses
    getPermissionPolicy_resourceArn,

    -- * Destructuring the Response
    GetPermissionPolicyResponse (..),
    newGetPermissionPolicyResponse,

    -- * Response Lenses
    getPermissionPolicyResponse_policy,
    getPermissionPolicyResponse_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.WAF.Types

-- | /See:/ 'newGetPermissionPolicy' smart constructor.
data GetPermissionPolicy = GetPermissionPolicy'
  { -- | The Amazon Resource Name (ARN) of the RuleGroup for which you want to
    -- get the policy.
    GetPermissionPolicy -> Text
resourceArn :: Prelude.Text
  }
  deriving (GetPermissionPolicy -> GetPermissionPolicy -> Bool
(GetPermissionPolicy -> GetPermissionPolicy -> Bool)
-> (GetPermissionPolicy -> GetPermissionPolicy -> Bool)
-> Eq GetPermissionPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetPermissionPolicy -> GetPermissionPolicy -> Bool
$c/= :: GetPermissionPolicy -> GetPermissionPolicy -> Bool
== :: GetPermissionPolicy -> GetPermissionPolicy -> Bool
$c== :: GetPermissionPolicy -> GetPermissionPolicy -> Bool
Prelude.Eq, ReadPrec [GetPermissionPolicy]
ReadPrec GetPermissionPolicy
Int -> ReadS GetPermissionPolicy
ReadS [GetPermissionPolicy]
(Int -> ReadS GetPermissionPolicy)
-> ReadS [GetPermissionPolicy]
-> ReadPrec GetPermissionPolicy
-> ReadPrec [GetPermissionPolicy]
-> Read GetPermissionPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetPermissionPolicy]
$creadListPrec :: ReadPrec [GetPermissionPolicy]
readPrec :: ReadPrec GetPermissionPolicy
$creadPrec :: ReadPrec GetPermissionPolicy
readList :: ReadS [GetPermissionPolicy]
$creadList :: ReadS [GetPermissionPolicy]
readsPrec :: Int -> ReadS GetPermissionPolicy
$creadsPrec :: Int -> ReadS GetPermissionPolicy
Prelude.Read, Int -> GetPermissionPolicy -> ShowS
[GetPermissionPolicy] -> ShowS
GetPermissionPolicy -> String
(Int -> GetPermissionPolicy -> ShowS)
-> (GetPermissionPolicy -> String)
-> ([GetPermissionPolicy] -> ShowS)
-> Show GetPermissionPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetPermissionPolicy] -> ShowS
$cshowList :: [GetPermissionPolicy] -> ShowS
show :: GetPermissionPolicy -> String
$cshow :: GetPermissionPolicy -> String
showsPrec :: Int -> GetPermissionPolicy -> ShowS
$cshowsPrec :: Int -> GetPermissionPolicy -> ShowS
Prelude.Show, (forall x. GetPermissionPolicy -> Rep GetPermissionPolicy x)
-> (forall x. Rep GetPermissionPolicy x -> GetPermissionPolicy)
-> Generic GetPermissionPolicy
forall x. Rep GetPermissionPolicy x -> GetPermissionPolicy
forall x. GetPermissionPolicy -> Rep GetPermissionPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetPermissionPolicy x -> GetPermissionPolicy
$cfrom :: forall x. GetPermissionPolicy -> Rep GetPermissionPolicy x
Prelude.Generic)

-- |
-- Create a value of 'GetPermissionPolicy' 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:
--
-- 'resourceArn', 'getPermissionPolicy_resourceArn' - The Amazon Resource Name (ARN) of the RuleGroup for which you want to
-- get the policy.
newGetPermissionPolicy ::
  -- | 'resourceArn'
  Prelude.Text ->
  GetPermissionPolicy
newGetPermissionPolicy :: Text -> GetPermissionPolicy
newGetPermissionPolicy Text
pResourceArn_ =
  GetPermissionPolicy' :: Text -> GetPermissionPolicy
GetPermissionPolicy' {$sel:resourceArn:GetPermissionPolicy' :: Text
resourceArn = Text
pResourceArn_}

-- | The Amazon Resource Name (ARN) of the RuleGroup for which you want to
-- get the policy.
getPermissionPolicy_resourceArn :: Lens.Lens' GetPermissionPolicy Prelude.Text
getPermissionPolicy_resourceArn :: (Text -> f Text) -> GetPermissionPolicy -> f GetPermissionPolicy
getPermissionPolicy_resourceArn = (GetPermissionPolicy -> Text)
-> (GetPermissionPolicy -> Text -> GetPermissionPolicy)
-> Lens GetPermissionPolicy GetPermissionPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPermissionPolicy' {Text
resourceArn :: Text
$sel:resourceArn:GetPermissionPolicy' :: GetPermissionPolicy -> Text
resourceArn} -> Text
resourceArn) (\s :: GetPermissionPolicy
s@GetPermissionPolicy' {} Text
a -> GetPermissionPolicy
s {$sel:resourceArn:GetPermissionPolicy' :: Text
resourceArn = Text
a} :: GetPermissionPolicy)

instance Core.AWSRequest GetPermissionPolicy where
  type
    AWSResponse GetPermissionPolicy =
      GetPermissionPolicyResponse
  request :: GetPermissionPolicy -> Request GetPermissionPolicy
request = Service -> GetPermissionPolicy -> Request GetPermissionPolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetPermissionPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetPermissionPolicy)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetPermissionPolicy))
-> Logger
-> Service
-> Proxy GetPermissionPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetPermissionPolicy)))
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 Text -> Int -> GetPermissionPolicyResponse
GetPermissionPolicyResponse'
            (Maybe Text -> Int -> GetPermissionPolicyResponse)
-> Either String (Maybe Text)
-> Either String (Int -> GetPermissionPolicyResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Policy")
            Either String (Int -> GetPermissionPolicyResponse)
-> Either String Int -> Either String GetPermissionPolicyResponse
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 GetPermissionPolicy

instance Prelude.NFData GetPermissionPolicy

instance Core.ToHeaders GetPermissionPolicy where
  toHeaders :: GetPermissionPolicy -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetPermissionPolicy -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AWSWAF_20150824.GetPermissionPolicy" ::
                          Prelude.ByteString
                      ),
            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.ToJSON GetPermissionPolicy where
  toJSON :: GetPermissionPolicy -> Value
toJSON GetPermissionPolicy' {Text
resourceArn :: Text
$sel:resourceArn:GetPermissionPolicy' :: GetPermissionPolicy -> 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
"ResourceArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
resourceArn)]
      )

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

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

-- | /See:/ 'newGetPermissionPolicyResponse' smart constructor.
data GetPermissionPolicyResponse = GetPermissionPolicyResponse'
  { -- | The IAM policy attached to the specified RuleGroup.
    GetPermissionPolicyResponse -> Maybe Text
policy :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetPermissionPolicyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetPermissionPolicyResponse -> GetPermissionPolicyResponse -> Bool
(GetPermissionPolicyResponse
 -> GetPermissionPolicyResponse -> Bool)
-> (GetPermissionPolicyResponse
    -> GetPermissionPolicyResponse -> Bool)
-> Eq GetPermissionPolicyResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetPermissionPolicyResponse -> GetPermissionPolicyResponse -> Bool
$c/= :: GetPermissionPolicyResponse -> GetPermissionPolicyResponse -> Bool
== :: GetPermissionPolicyResponse -> GetPermissionPolicyResponse -> Bool
$c== :: GetPermissionPolicyResponse -> GetPermissionPolicyResponse -> Bool
Prelude.Eq, ReadPrec [GetPermissionPolicyResponse]
ReadPrec GetPermissionPolicyResponse
Int -> ReadS GetPermissionPolicyResponse
ReadS [GetPermissionPolicyResponse]
(Int -> ReadS GetPermissionPolicyResponse)
-> ReadS [GetPermissionPolicyResponse]
-> ReadPrec GetPermissionPolicyResponse
-> ReadPrec [GetPermissionPolicyResponse]
-> Read GetPermissionPolicyResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetPermissionPolicyResponse]
$creadListPrec :: ReadPrec [GetPermissionPolicyResponse]
readPrec :: ReadPrec GetPermissionPolicyResponse
$creadPrec :: ReadPrec GetPermissionPolicyResponse
readList :: ReadS [GetPermissionPolicyResponse]
$creadList :: ReadS [GetPermissionPolicyResponse]
readsPrec :: Int -> ReadS GetPermissionPolicyResponse
$creadsPrec :: Int -> ReadS GetPermissionPolicyResponse
Prelude.Read, Int -> GetPermissionPolicyResponse -> ShowS
[GetPermissionPolicyResponse] -> ShowS
GetPermissionPolicyResponse -> String
(Int -> GetPermissionPolicyResponse -> ShowS)
-> (GetPermissionPolicyResponse -> String)
-> ([GetPermissionPolicyResponse] -> ShowS)
-> Show GetPermissionPolicyResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetPermissionPolicyResponse] -> ShowS
$cshowList :: [GetPermissionPolicyResponse] -> ShowS
show :: GetPermissionPolicyResponse -> String
$cshow :: GetPermissionPolicyResponse -> String
showsPrec :: Int -> GetPermissionPolicyResponse -> ShowS
$cshowsPrec :: Int -> GetPermissionPolicyResponse -> ShowS
Prelude.Show, (forall x.
 GetPermissionPolicyResponse -> Rep GetPermissionPolicyResponse x)
-> (forall x.
    Rep GetPermissionPolicyResponse x -> GetPermissionPolicyResponse)
-> Generic GetPermissionPolicyResponse
forall x.
Rep GetPermissionPolicyResponse x -> GetPermissionPolicyResponse
forall x.
GetPermissionPolicyResponse -> Rep GetPermissionPolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetPermissionPolicyResponse x -> GetPermissionPolicyResponse
$cfrom :: forall x.
GetPermissionPolicyResponse -> Rep GetPermissionPolicyResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetPermissionPolicyResponse' 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:
--
-- 'policy', 'getPermissionPolicyResponse_policy' - The IAM policy attached to the specified RuleGroup.
--
-- 'httpStatus', 'getPermissionPolicyResponse_httpStatus' - The response's http status code.
newGetPermissionPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetPermissionPolicyResponse
newGetPermissionPolicyResponse :: Int -> GetPermissionPolicyResponse
newGetPermissionPolicyResponse Int
pHttpStatus_ =
  GetPermissionPolicyResponse' :: Maybe Text -> Int -> GetPermissionPolicyResponse
GetPermissionPolicyResponse'
    { $sel:policy:GetPermissionPolicyResponse' :: Maybe Text
policy =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetPermissionPolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The IAM policy attached to the specified RuleGroup.
getPermissionPolicyResponse_policy :: Lens.Lens' GetPermissionPolicyResponse (Prelude.Maybe Prelude.Text)
getPermissionPolicyResponse_policy :: (Maybe Text -> f (Maybe Text))
-> GetPermissionPolicyResponse -> f GetPermissionPolicyResponse
getPermissionPolicyResponse_policy = (GetPermissionPolicyResponse -> Maybe Text)
-> (GetPermissionPolicyResponse
    -> Maybe Text -> GetPermissionPolicyResponse)
-> Lens
     GetPermissionPolicyResponse
     GetPermissionPolicyResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPermissionPolicyResponse' {Maybe Text
policy :: Maybe Text
$sel:policy:GetPermissionPolicyResponse' :: GetPermissionPolicyResponse -> Maybe Text
policy} -> Maybe Text
policy) (\s :: GetPermissionPolicyResponse
s@GetPermissionPolicyResponse' {} Maybe Text
a -> GetPermissionPolicyResponse
s {$sel:policy:GetPermissionPolicyResponse' :: Maybe Text
policy = Maybe Text
a} :: GetPermissionPolicyResponse)

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

instance Prelude.NFData GetPermissionPolicyResponse