{-# 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.ImageBuilder.GetComponentPolicy
-- 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)
--
-- Gets a component policy.
module Amazonka.ImageBuilder.GetComponentPolicy
  ( -- * Creating a Request
    GetComponentPolicy (..),
    newGetComponentPolicy,

    -- * Request Lenses
    getComponentPolicy_componentArn,

    -- * Destructuring the Response
    GetComponentPolicyResponse (..),
    newGetComponentPolicyResponse,

    -- * Response Lenses
    getComponentPolicyResponse_requestId,
    getComponentPolicyResponse_policy,
    getComponentPolicyResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.ImageBuilder.Types
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:/ 'newGetComponentPolicy' smart constructor.
data GetComponentPolicy = GetComponentPolicy'
  { -- | The Amazon Resource Name (ARN) of the component whose policy you want to
    -- retrieve.
    GetComponentPolicy -> Text
componentArn :: Prelude.Text
  }
  deriving (GetComponentPolicy -> GetComponentPolicy -> Bool
(GetComponentPolicy -> GetComponentPolicy -> Bool)
-> (GetComponentPolicy -> GetComponentPolicy -> Bool)
-> Eq GetComponentPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetComponentPolicy -> GetComponentPolicy -> Bool
$c/= :: GetComponentPolicy -> GetComponentPolicy -> Bool
== :: GetComponentPolicy -> GetComponentPolicy -> Bool
$c== :: GetComponentPolicy -> GetComponentPolicy -> Bool
Prelude.Eq, ReadPrec [GetComponentPolicy]
ReadPrec GetComponentPolicy
Int -> ReadS GetComponentPolicy
ReadS [GetComponentPolicy]
(Int -> ReadS GetComponentPolicy)
-> ReadS [GetComponentPolicy]
-> ReadPrec GetComponentPolicy
-> ReadPrec [GetComponentPolicy]
-> Read GetComponentPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetComponentPolicy]
$creadListPrec :: ReadPrec [GetComponentPolicy]
readPrec :: ReadPrec GetComponentPolicy
$creadPrec :: ReadPrec GetComponentPolicy
readList :: ReadS [GetComponentPolicy]
$creadList :: ReadS [GetComponentPolicy]
readsPrec :: Int -> ReadS GetComponentPolicy
$creadsPrec :: Int -> ReadS GetComponentPolicy
Prelude.Read, Int -> GetComponentPolicy -> ShowS
[GetComponentPolicy] -> ShowS
GetComponentPolicy -> String
(Int -> GetComponentPolicy -> ShowS)
-> (GetComponentPolicy -> String)
-> ([GetComponentPolicy] -> ShowS)
-> Show GetComponentPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetComponentPolicy] -> ShowS
$cshowList :: [GetComponentPolicy] -> ShowS
show :: GetComponentPolicy -> String
$cshow :: GetComponentPolicy -> String
showsPrec :: Int -> GetComponentPolicy -> ShowS
$cshowsPrec :: Int -> GetComponentPolicy -> ShowS
Prelude.Show, (forall x. GetComponentPolicy -> Rep GetComponentPolicy x)
-> (forall x. Rep GetComponentPolicy x -> GetComponentPolicy)
-> Generic GetComponentPolicy
forall x. Rep GetComponentPolicy x -> GetComponentPolicy
forall x. GetComponentPolicy -> Rep GetComponentPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetComponentPolicy x -> GetComponentPolicy
$cfrom :: forall x. GetComponentPolicy -> Rep GetComponentPolicy x
Prelude.Generic)

-- |
-- Create a value of 'GetComponentPolicy' 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:
--
-- 'componentArn', 'getComponentPolicy_componentArn' - The Amazon Resource Name (ARN) of the component whose policy you want to
-- retrieve.
newGetComponentPolicy ::
  -- | 'componentArn'
  Prelude.Text ->
  GetComponentPolicy
newGetComponentPolicy :: Text -> GetComponentPolicy
newGetComponentPolicy Text
pComponentArn_ =
  GetComponentPolicy' :: Text -> GetComponentPolicy
GetComponentPolicy' {$sel:componentArn:GetComponentPolicy' :: Text
componentArn = Text
pComponentArn_}

-- | The Amazon Resource Name (ARN) of the component whose policy you want to
-- retrieve.
getComponentPolicy_componentArn :: Lens.Lens' GetComponentPolicy Prelude.Text
getComponentPolicy_componentArn :: (Text -> f Text) -> GetComponentPolicy -> f GetComponentPolicy
getComponentPolicy_componentArn = (GetComponentPolicy -> Text)
-> (GetComponentPolicy -> Text -> GetComponentPolicy)
-> Lens GetComponentPolicy GetComponentPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetComponentPolicy' {Text
componentArn :: Text
$sel:componentArn:GetComponentPolicy' :: GetComponentPolicy -> Text
componentArn} -> Text
componentArn) (\s :: GetComponentPolicy
s@GetComponentPolicy' {} Text
a -> GetComponentPolicy
s {$sel:componentArn:GetComponentPolicy' :: Text
componentArn = Text
a} :: GetComponentPolicy)

instance Core.AWSRequest GetComponentPolicy where
  type
    AWSResponse GetComponentPolicy =
      GetComponentPolicyResponse
  request :: GetComponentPolicy -> Request GetComponentPolicy
request = Service -> GetComponentPolicy -> Request GetComponentPolicy
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetComponentPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetComponentPolicy)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetComponentPolicy))
-> Logger
-> Service
-> Proxy GetComponentPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetComponentPolicy)))
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 -> Maybe Text -> Int -> GetComponentPolicyResponse
GetComponentPolicyResponse'
            (Maybe Text -> Maybe Text -> Int -> GetComponentPolicyResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> GetComponentPolicyResponse)
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
"requestId")
            Either String (Maybe Text -> Int -> GetComponentPolicyResponse)
-> Either String (Maybe Text)
-> Either String (Int -> GetComponentPolicyResponse)
forall (f :: * -> *) a b. Applicative f => 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 -> GetComponentPolicyResponse)
-> Either String Int -> Either String GetComponentPolicyResponse
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 GetComponentPolicy

instance Prelude.NFData GetComponentPolicy

instance Core.ToHeaders GetComponentPolicy where
  toHeaders :: GetComponentPolicy -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetComponentPolicy -> 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 GetComponentPolicy where
  toPath :: GetComponentPolicy -> ByteString
toPath = ByteString -> GetComponentPolicy -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/GetComponentPolicy"

instance Core.ToQuery GetComponentPolicy where
  toQuery :: GetComponentPolicy -> QueryString
toQuery GetComponentPolicy' {Text
componentArn :: Text
$sel:componentArn:GetComponentPolicy' :: GetComponentPolicy -> Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"componentArn" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
componentArn]

-- | /See:/ 'newGetComponentPolicyResponse' smart constructor.
data GetComponentPolicyResponse = GetComponentPolicyResponse'
  { -- | The request ID that uniquely identifies this request.
    GetComponentPolicyResponse -> Maybe Text
requestId :: Prelude.Maybe Prelude.Text,
    -- | The component policy.
    GetComponentPolicyResponse -> Maybe Text
policy :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetComponentPolicyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetComponentPolicyResponse -> GetComponentPolicyResponse -> Bool
(GetComponentPolicyResponse -> GetComponentPolicyResponse -> Bool)
-> (GetComponentPolicyResponse
    -> GetComponentPolicyResponse -> Bool)
-> Eq GetComponentPolicyResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetComponentPolicyResponse -> GetComponentPolicyResponse -> Bool
$c/= :: GetComponentPolicyResponse -> GetComponentPolicyResponse -> Bool
== :: GetComponentPolicyResponse -> GetComponentPolicyResponse -> Bool
$c== :: GetComponentPolicyResponse -> GetComponentPolicyResponse -> Bool
Prelude.Eq, ReadPrec [GetComponentPolicyResponse]
ReadPrec GetComponentPolicyResponse
Int -> ReadS GetComponentPolicyResponse
ReadS [GetComponentPolicyResponse]
(Int -> ReadS GetComponentPolicyResponse)
-> ReadS [GetComponentPolicyResponse]
-> ReadPrec GetComponentPolicyResponse
-> ReadPrec [GetComponentPolicyResponse]
-> Read GetComponentPolicyResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetComponentPolicyResponse]
$creadListPrec :: ReadPrec [GetComponentPolicyResponse]
readPrec :: ReadPrec GetComponentPolicyResponse
$creadPrec :: ReadPrec GetComponentPolicyResponse
readList :: ReadS [GetComponentPolicyResponse]
$creadList :: ReadS [GetComponentPolicyResponse]
readsPrec :: Int -> ReadS GetComponentPolicyResponse
$creadsPrec :: Int -> ReadS GetComponentPolicyResponse
Prelude.Read, Int -> GetComponentPolicyResponse -> ShowS
[GetComponentPolicyResponse] -> ShowS
GetComponentPolicyResponse -> String
(Int -> GetComponentPolicyResponse -> ShowS)
-> (GetComponentPolicyResponse -> String)
-> ([GetComponentPolicyResponse] -> ShowS)
-> Show GetComponentPolicyResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetComponentPolicyResponse] -> ShowS
$cshowList :: [GetComponentPolicyResponse] -> ShowS
show :: GetComponentPolicyResponse -> String
$cshow :: GetComponentPolicyResponse -> String
showsPrec :: Int -> GetComponentPolicyResponse -> ShowS
$cshowsPrec :: Int -> GetComponentPolicyResponse -> ShowS
Prelude.Show, (forall x.
 GetComponentPolicyResponse -> Rep GetComponentPolicyResponse x)
-> (forall x.
    Rep GetComponentPolicyResponse x -> GetComponentPolicyResponse)
-> Generic GetComponentPolicyResponse
forall x.
Rep GetComponentPolicyResponse x -> GetComponentPolicyResponse
forall x.
GetComponentPolicyResponse -> Rep GetComponentPolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetComponentPolicyResponse x -> GetComponentPolicyResponse
$cfrom :: forall x.
GetComponentPolicyResponse -> Rep GetComponentPolicyResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetComponentPolicyResponse' 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:
--
-- 'requestId', 'getComponentPolicyResponse_requestId' - The request ID that uniquely identifies this request.
--
-- 'policy', 'getComponentPolicyResponse_policy' - The component policy.
--
-- 'httpStatus', 'getComponentPolicyResponse_httpStatus' - The response's http status code.
newGetComponentPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetComponentPolicyResponse
newGetComponentPolicyResponse :: Int -> GetComponentPolicyResponse
newGetComponentPolicyResponse Int
pHttpStatus_ =
  GetComponentPolicyResponse' :: Maybe Text -> Maybe Text -> Int -> GetComponentPolicyResponse
GetComponentPolicyResponse'
    { $sel:requestId:GetComponentPolicyResponse' :: Maybe Text
requestId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:policy:GetComponentPolicyResponse' :: Maybe Text
policy = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetComponentPolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The request ID that uniquely identifies this request.
getComponentPolicyResponse_requestId :: Lens.Lens' GetComponentPolicyResponse (Prelude.Maybe Prelude.Text)
getComponentPolicyResponse_requestId :: (Maybe Text -> f (Maybe Text))
-> GetComponentPolicyResponse -> f GetComponentPolicyResponse
getComponentPolicyResponse_requestId = (GetComponentPolicyResponse -> Maybe Text)
-> (GetComponentPolicyResponse
    -> Maybe Text -> GetComponentPolicyResponse)
-> Lens
     GetComponentPolicyResponse
     GetComponentPolicyResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetComponentPolicyResponse' {Maybe Text
requestId :: Maybe Text
$sel:requestId:GetComponentPolicyResponse' :: GetComponentPolicyResponse -> Maybe Text
requestId} -> Maybe Text
requestId) (\s :: GetComponentPolicyResponse
s@GetComponentPolicyResponse' {} Maybe Text
a -> GetComponentPolicyResponse
s {$sel:requestId:GetComponentPolicyResponse' :: Maybe Text
requestId = Maybe Text
a} :: GetComponentPolicyResponse)

-- | The component policy.
getComponentPolicyResponse_policy :: Lens.Lens' GetComponentPolicyResponse (Prelude.Maybe Prelude.Text)
getComponentPolicyResponse_policy :: (Maybe Text -> f (Maybe Text))
-> GetComponentPolicyResponse -> f GetComponentPolicyResponse
getComponentPolicyResponse_policy = (GetComponentPolicyResponse -> Maybe Text)
-> (GetComponentPolicyResponse
    -> Maybe Text -> GetComponentPolicyResponse)
-> Lens
     GetComponentPolicyResponse
     GetComponentPolicyResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetComponentPolicyResponse' {Maybe Text
policy :: Maybe Text
$sel:policy:GetComponentPolicyResponse' :: GetComponentPolicyResponse -> Maybe Text
policy} -> Maybe Text
policy) (\s :: GetComponentPolicyResponse
s@GetComponentPolicyResponse' {} Maybe Text
a -> GetComponentPolicyResponse
s {$sel:policy:GetComponentPolicyResponse' :: Maybe Text
policy = Maybe Text
a} :: GetComponentPolicyResponse)

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

instance Prelude.NFData GetComponentPolicyResponse