{-# 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.ServerlessApplicationRepository.GetApplicationPolicy
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Retrieves the policy for the application.
module Amazonka.ServerlessApplicationRepository.GetApplicationPolicy
  ( -- * Creating a Request
    GetApplicationPolicy (..),
    newGetApplicationPolicy,

    -- * Request Lenses
    getApplicationPolicy_applicationId,

    -- * Destructuring the Response
    GetApplicationPolicyResponse (..),
    newGetApplicationPolicyResponse,

    -- * Response Lenses
    getApplicationPolicyResponse_statements,
    getApplicationPolicyResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.ServerlessApplicationRepository.Types

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

-- |
-- Create a value of 'GetApplicationPolicy' 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:
--
-- 'applicationId', 'getApplicationPolicy_applicationId' - The Amazon Resource Name (ARN) of the application.
newGetApplicationPolicy ::
  -- | 'applicationId'
  Prelude.Text ->
  GetApplicationPolicy
newGetApplicationPolicy :: Text -> GetApplicationPolicy
newGetApplicationPolicy Text
pApplicationId_ =
  GetApplicationPolicy'
    { $sel:applicationId:GetApplicationPolicy' :: Text
applicationId =
        Text
pApplicationId_
    }

-- | The Amazon Resource Name (ARN) of the application.
getApplicationPolicy_applicationId :: Lens.Lens' GetApplicationPolicy Prelude.Text
getApplicationPolicy_applicationId :: Lens' GetApplicationPolicy Text
getApplicationPolicy_applicationId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetApplicationPolicy' {Text
applicationId :: Text
$sel:applicationId:GetApplicationPolicy' :: GetApplicationPolicy -> Text
applicationId} -> Text
applicationId) (\s :: GetApplicationPolicy
s@GetApplicationPolicy' {} Text
a -> GetApplicationPolicy
s {$sel:applicationId:GetApplicationPolicy' :: Text
applicationId = Text
a} :: GetApplicationPolicy)

instance Core.AWSRequest GetApplicationPolicy where
  type
    AWSResponse GetApplicationPolicy =
      GetApplicationPolicyResponse
  request :: (Service -> Service)
-> GetApplicationPolicy -> Request GetApplicationPolicy
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 GetApplicationPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetApplicationPolicy)))
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 [ApplicationPolicyStatement]
-> Int -> GetApplicationPolicyResponse
GetApplicationPolicyResponse'
            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
"statements" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            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 GetApplicationPolicy where
  hashWithSalt :: Int -> GetApplicationPolicy -> Int
hashWithSalt Int
_salt GetApplicationPolicy' {Text
applicationId :: Text
$sel:applicationId:GetApplicationPolicy' :: GetApplicationPolicy -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
applicationId

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

instance Data.ToHeaders GetApplicationPolicy where
  toHeaders :: GetApplicationPolicy -> 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 GetApplicationPolicy where
  toPath :: GetApplicationPolicy -> ByteString
toPath GetApplicationPolicy' {Text
applicationId :: Text
$sel:applicationId:GetApplicationPolicy' :: GetApplicationPolicy -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/applications/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
applicationId,
        ByteString
"/policy"
      ]

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

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

-- |
-- Create a value of 'GetApplicationPolicyResponse' 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:
--
-- 'statements', 'getApplicationPolicyResponse_statements' - An array of policy statements applied to the application.
--
-- 'httpStatus', 'getApplicationPolicyResponse_httpStatus' - The response's http status code.
newGetApplicationPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetApplicationPolicyResponse
newGetApplicationPolicyResponse :: Int -> GetApplicationPolicyResponse
newGetApplicationPolicyResponse Int
pHttpStatus_ =
  GetApplicationPolicyResponse'
    { $sel:statements:GetApplicationPolicyResponse' :: Maybe [ApplicationPolicyStatement]
statements =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetApplicationPolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of policy statements applied to the application.
getApplicationPolicyResponse_statements :: Lens.Lens' GetApplicationPolicyResponse (Prelude.Maybe [ApplicationPolicyStatement])
getApplicationPolicyResponse_statements :: Lens'
  GetApplicationPolicyResponse (Maybe [ApplicationPolicyStatement])
getApplicationPolicyResponse_statements = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetApplicationPolicyResponse' {Maybe [ApplicationPolicyStatement]
statements :: Maybe [ApplicationPolicyStatement]
$sel:statements:GetApplicationPolicyResponse' :: GetApplicationPolicyResponse -> Maybe [ApplicationPolicyStatement]
statements} -> Maybe [ApplicationPolicyStatement]
statements) (\s :: GetApplicationPolicyResponse
s@GetApplicationPolicyResponse' {} Maybe [ApplicationPolicyStatement]
a -> GetApplicationPolicyResponse
s {$sel:statements:GetApplicationPolicyResponse' :: Maybe [ApplicationPolicyStatement]
statements = Maybe [ApplicationPolicyStatement]
a} :: GetApplicationPolicyResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData GetApplicationPolicyResponse where
  rnf :: GetApplicationPolicyResponse -> ()
rnf GetApplicationPolicyResponse' {Int
Maybe [ApplicationPolicyStatement]
httpStatus :: Int
statements :: Maybe [ApplicationPolicyStatement]
$sel:httpStatus:GetApplicationPolicyResponse' :: GetApplicationPolicyResponse -> Int
$sel:statements:GetApplicationPolicyResponse' :: GetApplicationPolicyResponse -> Maybe [ApplicationPolicyStatement]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [ApplicationPolicyStatement]
statements
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus