{-# 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.Organizations.DescribePolicy
-- 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)
--
-- Retrieves information about a policy.
--
-- This operation can be called only from the organization\'s management
-- account or by a member account that is a delegated administrator for an
-- AWS service.
module Amazonka.Organizations.DescribePolicy
  ( -- * Creating a Request
    DescribePolicy (..),
    newDescribePolicy,

    -- * Request Lenses
    describePolicy_policyId,

    -- * Destructuring the Response
    DescribePolicyResponse (..),
    newDescribePolicyResponse,

    -- * Response Lenses
    describePolicyResponse_policy,
    describePolicyResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Organizations.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newDescribePolicy' smart constructor.
data DescribePolicy = DescribePolicy'
  { -- | The unique identifier (ID) of the policy that you want details about.
    -- You can get the ID from the ListPolicies or ListPoliciesForTarget
    -- operations.
    --
    -- The <http://wikipedia.org/wiki/regex regex pattern> for a policy ID
    -- string requires \"p-\" followed by from 8 to 128 lowercase or uppercase
    -- letters, digits, or the underscore character (_).
    DescribePolicy -> Text
policyId :: Prelude.Text
  }
  deriving (DescribePolicy -> DescribePolicy -> Bool
(DescribePolicy -> DescribePolicy -> Bool)
-> (DescribePolicy -> DescribePolicy -> Bool) -> Eq DescribePolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribePolicy -> DescribePolicy -> Bool
$c/= :: DescribePolicy -> DescribePolicy -> Bool
== :: DescribePolicy -> DescribePolicy -> Bool
$c== :: DescribePolicy -> DescribePolicy -> Bool
Prelude.Eq, ReadPrec [DescribePolicy]
ReadPrec DescribePolicy
Int -> ReadS DescribePolicy
ReadS [DescribePolicy]
(Int -> ReadS DescribePolicy)
-> ReadS [DescribePolicy]
-> ReadPrec DescribePolicy
-> ReadPrec [DescribePolicy]
-> Read DescribePolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribePolicy]
$creadListPrec :: ReadPrec [DescribePolicy]
readPrec :: ReadPrec DescribePolicy
$creadPrec :: ReadPrec DescribePolicy
readList :: ReadS [DescribePolicy]
$creadList :: ReadS [DescribePolicy]
readsPrec :: Int -> ReadS DescribePolicy
$creadsPrec :: Int -> ReadS DescribePolicy
Prelude.Read, Int -> DescribePolicy -> ShowS
[DescribePolicy] -> ShowS
DescribePolicy -> String
(Int -> DescribePolicy -> ShowS)
-> (DescribePolicy -> String)
-> ([DescribePolicy] -> ShowS)
-> Show DescribePolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribePolicy] -> ShowS
$cshowList :: [DescribePolicy] -> ShowS
show :: DescribePolicy -> String
$cshow :: DescribePolicy -> String
showsPrec :: Int -> DescribePolicy -> ShowS
$cshowsPrec :: Int -> DescribePolicy -> ShowS
Prelude.Show, (forall x. DescribePolicy -> Rep DescribePolicy x)
-> (forall x. Rep DescribePolicy x -> DescribePolicy)
-> Generic DescribePolicy
forall x. Rep DescribePolicy x -> DescribePolicy
forall x. DescribePolicy -> Rep DescribePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribePolicy x -> DescribePolicy
$cfrom :: forall x. DescribePolicy -> Rep DescribePolicy x
Prelude.Generic)

-- |
-- Create a value of 'DescribePolicy' 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:
--
-- 'policyId', 'describePolicy_policyId' - The unique identifier (ID) of the policy that you want details about.
-- You can get the ID from the ListPolicies or ListPoliciesForTarget
-- operations.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for a policy ID
-- string requires \"p-\" followed by from 8 to 128 lowercase or uppercase
-- letters, digits, or the underscore character (_).
newDescribePolicy ::
  -- | 'policyId'
  Prelude.Text ->
  DescribePolicy
newDescribePolicy :: Text -> DescribePolicy
newDescribePolicy Text
pPolicyId_ =
  DescribePolicy' :: Text -> DescribePolicy
DescribePolicy' {$sel:policyId:DescribePolicy' :: Text
policyId = Text
pPolicyId_}

-- | The unique identifier (ID) of the policy that you want details about.
-- You can get the ID from the ListPolicies or ListPoliciesForTarget
-- operations.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for a policy ID
-- string requires \"p-\" followed by from 8 to 128 lowercase or uppercase
-- letters, digits, or the underscore character (_).
describePolicy_policyId :: Lens.Lens' DescribePolicy Prelude.Text
describePolicy_policyId :: (Text -> f Text) -> DescribePolicy -> f DescribePolicy
describePolicy_policyId = (DescribePolicy -> Text)
-> (DescribePolicy -> Text -> DescribePolicy)
-> Lens DescribePolicy DescribePolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribePolicy' {Text
policyId :: Text
$sel:policyId:DescribePolicy' :: DescribePolicy -> Text
policyId} -> Text
policyId) (\s :: DescribePolicy
s@DescribePolicy' {} Text
a -> DescribePolicy
s {$sel:policyId:DescribePolicy' :: Text
policyId = Text
a} :: DescribePolicy)

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

instance Prelude.NFData DescribePolicy

instance Core.ToHeaders DescribePolicy where
  toHeaders :: DescribePolicy -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribePolicy -> 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
"AWSOrganizationsV20161128.DescribePolicy" ::
                          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 DescribePolicy where
  toJSON :: DescribePolicy -> Value
toJSON DescribePolicy' {Text
policyId :: Text
$sel:policyId:DescribePolicy' :: DescribePolicy -> 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
"PolicyId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
policyId)]
      )

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

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

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

-- |
-- Create a value of 'DescribePolicyResponse' 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', 'describePolicyResponse_policy' - A structure that contains details about the specified policy.
--
-- 'httpStatus', 'describePolicyResponse_httpStatus' - The response's http status code.
newDescribePolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribePolicyResponse
newDescribePolicyResponse :: Int -> DescribePolicyResponse
newDescribePolicyResponse Int
pHttpStatus_ =
  DescribePolicyResponse' :: Maybe Policy -> Int -> DescribePolicyResponse
DescribePolicyResponse'
    { $sel:policy:DescribePolicyResponse' :: Maybe Policy
policy = Maybe Policy
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribePolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A structure that contains details about the specified policy.
describePolicyResponse_policy :: Lens.Lens' DescribePolicyResponse (Prelude.Maybe Policy)
describePolicyResponse_policy :: (Maybe Policy -> f (Maybe Policy))
-> DescribePolicyResponse -> f DescribePolicyResponse
describePolicyResponse_policy = (DescribePolicyResponse -> Maybe Policy)
-> (DescribePolicyResponse
    -> Maybe Policy -> DescribePolicyResponse)
-> Lens
     DescribePolicyResponse
     DescribePolicyResponse
     (Maybe Policy)
     (Maybe Policy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribePolicyResponse' {Maybe Policy
policy :: Maybe Policy
$sel:policy:DescribePolicyResponse' :: DescribePolicyResponse -> Maybe Policy
policy} -> Maybe Policy
policy) (\s :: DescribePolicyResponse
s@DescribePolicyResponse' {} Maybe Policy
a -> DescribePolicyResponse
s {$sel:policy:DescribePolicyResponse' :: Maybe Policy
policy = Maybe Policy
a} :: DescribePolicyResponse)

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

instance Prelude.NFData DescribePolicyResponse