{-# 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.Lambda.GetLayerVersionPolicy
-- 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 permission policy for a version of an
-- <https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html Lambda layer>.
-- For more information, see AddLayerVersionPermission.
module Amazonka.Lambda.GetLayerVersionPolicy
  ( -- * Creating a Request
    GetLayerVersionPolicy (..),
    newGetLayerVersionPolicy,

    -- * Request Lenses
    getLayerVersionPolicy_layerName,
    getLayerVersionPolicy_versionNumber,

    -- * Destructuring the Response
    GetLayerVersionPolicyResponse (..),
    newGetLayerVersionPolicyResponse,

    -- * Response Lenses
    getLayerVersionPolicyResponse_policy,
    getLayerVersionPolicyResponse_revisionId,
    getLayerVersionPolicyResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.Lambda.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:/ 'newGetLayerVersionPolicy' smart constructor.
data GetLayerVersionPolicy = GetLayerVersionPolicy'
  { -- | The name or Amazon Resource Name (ARN) of the layer.
    GetLayerVersionPolicy -> Text
layerName :: Prelude.Text,
    -- | The version number.
    GetLayerVersionPolicy -> Integer
versionNumber :: Prelude.Integer
  }
  deriving (GetLayerVersionPolicy -> GetLayerVersionPolicy -> Bool
(GetLayerVersionPolicy -> GetLayerVersionPolicy -> Bool)
-> (GetLayerVersionPolicy -> GetLayerVersionPolicy -> Bool)
-> Eq GetLayerVersionPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetLayerVersionPolicy -> GetLayerVersionPolicy -> Bool
$c/= :: GetLayerVersionPolicy -> GetLayerVersionPolicy -> Bool
== :: GetLayerVersionPolicy -> GetLayerVersionPolicy -> Bool
$c== :: GetLayerVersionPolicy -> GetLayerVersionPolicy -> Bool
Prelude.Eq, ReadPrec [GetLayerVersionPolicy]
ReadPrec GetLayerVersionPolicy
Int -> ReadS GetLayerVersionPolicy
ReadS [GetLayerVersionPolicy]
(Int -> ReadS GetLayerVersionPolicy)
-> ReadS [GetLayerVersionPolicy]
-> ReadPrec GetLayerVersionPolicy
-> ReadPrec [GetLayerVersionPolicy]
-> Read GetLayerVersionPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetLayerVersionPolicy]
$creadListPrec :: ReadPrec [GetLayerVersionPolicy]
readPrec :: ReadPrec GetLayerVersionPolicy
$creadPrec :: ReadPrec GetLayerVersionPolicy
readList :: ReadS [GetLayerVersionPolicy]
$creadList :: ReadS [GetLayerVersionPolicy]
readsPrec :: Int -> ReadS GetLayerVersionPolicy
$creadsPrec :: Int -> ReadS GetLayerVersionPolicy
Prelude.Read, Int -> GetLayerVersionPolicy -> ShowS
[GetLayerVersionPolicy] -> ShowS
GetLayerVersionPolicy -> String
(Int -> GetLayerVersionPolicy -> ShowS)
-> (GetLayerVersionPolicy -> String)
-> ([GetLayerVersionPolicy] -> ShowS)
-> Show GetLayerVersionPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetLayerVersionPolicy] -> ShowS
$cshowList :: [GetLayerVersionPolicy] -> ShowS
show :: GetLayerVersionPolicy -> String
$cshow :: GetLayerVersionPolicy -> String
showsPrec :: Int -> GetLayerVersionPolicy -> ShowS
$cshowsPrec :: Int -> GetLayerVersionPolicy -> ShowS
Prelude.Show, (forall x. GetLayerVersionPolicy -> Rep GetLayerVersionPolicy x)
-> (forall x. Rep GetLayerVersionPolicy x -> GetLayerVersionPolicy)
-> Generic GetLayerVersionPolicy
forall x. Rep GetLayerVersionPolicy x -> GetLayerVersionPolicy
forall x. GetLayerVersionPolicy -> Rep GetLayerVersionPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetLayerVersionPolicy x -> GetLayerVersionPolicy
$cfrom :: forall x. GetLayerVersionPolicy -> Rep GetLayerVersionPolicy x
Prelude.Generic)

-- |
-- Create a value of 'GetLayerVersionPolicy' 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:
--
-- 'layerName', 'getLayerVersionPolicy_layerName' - The name or Amazon Resource Name (ARN) of the layer.
--
-- 'versionNumber', 'getLayerVersionPolicy_versionNumber' - The version number.
newGetLayerVersionPolicy ::
  -- | 'layerName'
  Prelude.Text ->
  -- | 'versionNumber'
  Prelude.Integer ->
  GetLayerVersionPolicy
newGetLayerVersionPolicy :: Text -> Integer -> GetLayerVersionPolicy
newGetLayerVersionPolicy Text
pLayerName_ Integer
pVersionNumber_ =
  GetLayerVersionPolicy' :: Text -> Integer -> GetLayerVersionPolicy
GetLayerVersionPolicy'
    { $sel:layerName:GetLayerVersionPolicy' :: Text
layerName = Text
pLayerName_,
      $sel:versionNumber:GetLayerVersionPolicy' :: Integer
versionNumber = Integer
pVersionNumber_
    }

-- | The name or Amazon Resource Name (ARN) of the layer.
getLayerVersionPolicy_layerName :: Lens.Lens' GetLayerVersionPolicy Prelude.Text
getLayerVersionPolicy_layerName :: (Text -> f Text)
-> GetLayerVersionPolicy -> f GetLayerVersionPolicy
getLayerVersionPolicy_layerName = (GetLayerVersionPolicy -> Text)
-> (GetLayerVersionPolicy -> Text -> GetLayerVersionPolicy)
-> Lens GetLayerVersionPolicy GetLayerVersionPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetLayerVersionPolicy' {Text
layerName :: Text
$sel:layerName:GetLayerVersionPolicy' :: GetLayerVersionPolicy -> Text
layerName} -> Text
layerName) (\s :: GetLayerVersionPolicy
s@GetLayerVersionPolicy' {} Text
a -> GetLayerVersionPolicy
s {$sel:layerName:GetLayerVersionPolicy' :: Text
layerName = Text
a} :: GetLayerVersionPolicy)

-- | The version number.
getLayerVersionPolicy_versionNumber :: Lens.Lens' GetLayerVersionPolicy Prelude.Integer
getLayerVersionPolicy_versionNumber :: (Integer -> f Integer)
-> GetLayerVersionPolicy -> f GetLayerVersionPolicy
getLayerVersionPolicy_versionNumber = (GetLayerVersionPolicy -> Integer)
-> (GetLayerVersionPolicy -> Integer -> GetLayerVersionPolicy)
-> Lens GetLayerVersionPolicy GetLayerVersionPolicy Integer Integer
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetLayerVersionPolicy' {Integer
versionNumber :: Integer
$sel:versionNumber:GetLayerVersionPolicy' :: GetLayerVersionPolicy -> Integer
versionNumber} -> Integer
versionNumber) (\s :: GetLayerVersionPolicy
s@GetLayerVersionPolicy' {} Integer
a -> GetLayerVersionPolicy
s {$sel:versionNumber:GetLayerVersionPolicy' :: Integer
versionNumber = Integer
a} :: GetLayerVersionPolicy)

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

instance Prelude.NFData GetLayerVersionPolicy

instance Core.ToHeaders GetLayerVersionPolicy where
  toHeaders :: GetLayerVersionPolicy -> ResponseHeaders
toHeaders = ResponseHeaders -> GetLayerVersionPolicy -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToPath GetLayerVersionPolicy where
  toPath :: GetLayerVersionPolicy -> ByteString
toPath GetLayerVersionPolicy' {Integer
Text
versionNumber :: Integer
layerName :: Text
$sel:versionNumber:GetLayerVersionPolicy' :: GetLayerVersionPolicy -> Integer
$sel:layerName:GetLayerVersionPolicy' :: GetLayerVersionPolicy -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/2018-10-31/layers/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
layerName,
        ByteString
"/versions/",
        Integer -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Integer
versionNumber,
        ByteString
"/policy"
      ]

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

-- | /See:/ 'newGetLayerVersionPolicyResponse' smart constructor.
data GetLayerVersionPolicyResponse = GetLayerVersionPolicyResponse'
  { -- | The policy document.
    GetLayerVersionPolicyResponse -> Maybe Text
policy :: Prelude.Maybe Prelude.Text,
    -- | A unique identifier for the current revision of the policy.
    GetLayerVersionPolicyResponse -> Maybe Text
revisionId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetLayerVersionPolicyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetLayerVersionPolicyResponse
-> GetLayerVersionPolicyResponse -> Bool
(GetLayerVersionPolicyResponse
 -> GetLayerVersionPolicyResponse -> Bool)
-> (GetLayerVersionPolicyResponse
    -> GetLayerVersionPolicyResponse -> Bool)
-> Eq GetLayerVersionPolicyResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetLayerVersionPolicyResponse
-> GetLayerVersionPolicyResponse -> Bool
$c/= :: GetLayerVersionPolicyResponse
-> GetLayerVersionPolicyResponse -> Bool
== :: GetLayerVersionPolicyResponse
-> GetLayerVersionPolicyResponse -> Bool
$c== :: GetLayerVersionPolicyResponse
-> GetLayerVersionPolicyResponse -> Bool
Prelude.Eq, ReadPrec [GetLayerVersionPolicyResponse]
ReadPrec GetLayerVersionPolicyResponse
Int -> ReadS GetLayerVersionPolicyResponse
ReadS [GetLayerVersionPolicyResponse]
(Int -> ReadS GetLayerVersionPolicyResponse)
-> ReadS [GetLayerVersionPolicyResponse]
-> ReadPrec GetLayerVersionPolicyResponse
-> ReadPrec [GetLayerVersionPolicyResponse]
-> Read GetLayerVersionPolicyResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetLayerVersionPolicyResponse]
$creadListPrec :: ReadPrec [GetLayerVersionPolicyResponse]
readPrec :: ReadPrec GetLayerVersionPolicyResponse
$creadPrec :: ReadPrec GetLayerVersionPolicyResponse
readList :: ReadS [GetLayerVersionPolicyResponse]
$creadList :: ReadS [GetLayerVersionPolicyResponse]
readsPrec :: Int -> ReadS GetLayerVersionPolicyResponse
$creadsPrec :: Int -> ReadS GetLayerVersionPolicyResponse
Prelude.Read, Int -> GetLayerVersionPolicyResponse -> ShowS
[GetLayerVersionPolicyResponse] -> ShowS
GetLayerVersionPolicyResponse -> String
(Int -> GetLayerVersionPolicyResponse -> ShowS)
-> (GetLayerVersionPolicyResponse -> String)
-> ([GetLayerVersionPolicyResponse] -> ShowS)
-> Show GetLayerVersionPolicyResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetLayerVersionPolicyResponse] -> ShowS
$cshowList :: [GetLayerVersionPolicyResponse] -> ShowS
show :: GetLayerVersionPolicyResponse -> String
$cshow :: GetLayerVersionPolicyResponse -> String
showsPrec :: Int -> GetLayerVersionPolicyResponse -> ShowS
$cshowsPrec :: Int -> GetLayerVersionPolicyResponse -> ShowS
Prelude.Show, (forall x.
 GetLayerVersionPolicyResponse
 -> Rep GetLayerVersionPolicyResponse x)
-> (forall x.
    Rep GetLayerVersionPolicyResponse x
    -> GetLayerVersionPolicyResponse)
-> Generic GetLayerVersionPolicyResponse
forall x.
Rep GetLayerVersionPolicyResponse x
-> GetLayerVersionPolicyResponse
forall x.
GetLayerVersionPolicyResponse
-> Rep GetLayerVersionPolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetLayerVersionPolicyResponse x
-> GetLayerVersionPolicyResponse
$cfrom :: forall x.
GetLayerVersionPolicyResponse
-> Rep GetLayerVersionPolicyResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetLayerVersionPolicyResponse' 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', 'getLayerVersionPolicyResponse_policy' - The policy document.
--
-- 'revisionId', 'getLayerVersionPolicyResponse_revisionId' - A unique identifier for the current revision of the policy.
--
-- 'httpStatus', 'getLayerVersionPolicyResponse_httpStatus' - The response's http status code.
newGetLayerVersionPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetLayerVersionPolicyResponse
newGetLayerVersionPolicyResponse :: Int -> GetLayerVersionPolicyResponse
newGetLayerVersionPolicyResponse Int
pHttpStatus_ =
  GetLayerVersionPolicyResponse' :: Maybe Text -> Maybe Text -> Int -> GetLayerVersionPolicyResponse
GetLayerVersionPolicyResponse'
    { $sel:policy:GetLayerVersionPolicyResponse' :: Maybe Text
policy =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:revisionId:GetLayerVersionPolicyResponse' :: Maybe Text
revisionId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetLayerVersionPolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

-- | A unique identifier for the current revision of the policy.
getLayerVersionPolicyResponse_revisionId :: Lens.Lens' GetLayerVersionPolicyResponse (Prelude.Maybe Prelude.Text)
getLayerVersionPolicyResponse_revisionId :: (Maybe Text -> f (Maybe Text))
-> GetLayerVersionPolicyResponse -> f GetLayerVersionPolicyResponse
getLayerVersionPolicyResponse_revisionId = (GetLayerVersionPolicyResponse -> Maybe Text)
-> (GetLayerVersionPolicyResponse
    -> Maybe Text -> GetLayerVersionPolicyResponse)
-> Lens
     GetLayerVersionPolicyResponse
     GetLayerVersionPolicyResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetLayerVersionPolicyResponse' {Maybe Text
revisionId :: Maybe Text
$sel:revisionId:GetLayerVersionPolicyResponse' :: GetLayerVersionPolicyResponse -> Maybe Text
revisionId} -> Maybe Text
revisionId) (\s :: GetLayerVersionPolicyResponse
s@GetLayerVersionPolicyResponse' {} Maybe Text
a -> GetLayerVersionPolicyResponse
s {$sel:revisionId:GetLayerVersionPolicyResponse' :: Maybe Text
revisionId = Maybe Text
a} :: GetLayerVersionPolicyResponse)

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

instance Prelude.NFData GetLayerVersionPolicyResponse