{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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_policy,
    getComponentPolicyResponse_requestId,
    getComponentPolicyResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.ImageBuilder.Types
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
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]
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
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. 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' {$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 :: Lens' GetComponentPolicy Text
getComponentPolicy_componentArn = 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 :: (Service -> Service)
-> GetComponentPolicy -> Request GetComponentPolicy
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetComponentPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetComponentPolicy)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> 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'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"policy")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"requestId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetComponentPolicy where
  hashWithSalt :: Int -> GetComponentPolicy -> Int
hashWithSalt Int
_salt GetComponentPolicy' {Text
componentArn :: Text
$sel:componentArn:GetComponentPolicy' :: GetComponentPolicy -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
componentArn

instance Prelude.NFData GetComponentPolicy where
  rnf :: GetComponentPolicy -> ()
rnf GetComponentPolicy' {Text
componentArn :: Text
$sel:componentArn:GetComponentPolicy' :: GetComponentPolicy -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
componentArn

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

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

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

-- | /See:/ 'newGetComponentPolicyResponse' smart constructor.
data GetComponentPolicyResponse = GetComponentPolicyResponse'
  { -- | The component policy.
    GetComponentPolicyResponse -> Maybe Text
policy :: Prelude.Maybe Prelude.Text,
    -- | The request ID that uniquely identifies this request.
    GetComponentPolicyResponse -> Maybe Text
requestId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetComponentPolicyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetComponentPolicyResponse -> GetComponentPolicyResponse -> Bool
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]
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
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.
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:
--
-- 'policy', 'getComponentPolicyResponse_policy' - The component policy.
--
-- 'requestId', 'getComponentPolicyResponse_requestId' - The request ID that uniquely identifies this request.
--
-- 'httpStatus', 'getComponentPolicyResponse_httpStatus' - The response's http status code.
newGetComponentPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetComponentPolicyResponse
newGetComponentPolicyResponse :: Int -> GetComponentPolicyResponse
newGetComponentPolicyResponse Int
pHttpStatus_ =
  GetComponentPolicyResponse'
    { $sel:policy:GetComponentPolicyResponse' :: Maybe Text
policy =
        forall a. Maybe a
Prelude.Nothing,
      $sel:requestId:GetComponentPolicyResponse' :: Maybe Text
requestId = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetComponentPolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The component policy.
getComponentPolicyResponse_policy :: Lens.Lens' GetComponentPolicyResponse (Prelude.Maybe Prelude.Text)
getComponentPolicyResponse_policy :: Lens' GetComponentPolicyResponse (Maybe Text)
getComponentPolicyResponse_policy = 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 request ID that uniquely identifies this request.
getComponentPolicyResponse_requestId :: Lens.Lens' GetComponentPolicyResponse (Prelude.Maybe Prelude.Text)
getComponentPolicyResponse_requestId :: Lens' GetComponentPolicyResponse (Maybe Text)
getComponentPolicyResponse_requestId = 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 response's http status code.
getComponentPolicyResponse_httpStatus :: Lens.Lens' GetComponentPolicyResponse Prelude.Int
getComponentPolicyResponse_httpStatus :: Lens' GetComponentPolicyResponse Int
getComponentPolicyResponse_httpStatus = 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 where
  rnf :: GetComponentPolicyResponse -> ()
rnf GetComponentPolicyResponse' {Int
Maybe Text
httpStatus :: Int
requestId :: Maybe Text
policy :: Maybe Text
$sel:httpStatus:GetComponentPolicyResponse' :: GetComponentPolicyResponse -> Int
$sel:requestId:GetComponentPolicyResponse' :: GetComponentPolicyResponse -> Maybe Text
$sel:policy:GetComponentPolicyResponse' :: GetComponentPolicyResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
policy
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
requestId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus