{-# 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.AddPermission
-- 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)
--
-- Grants an Amazon Web Services service or another account permission to
-- use a function. You can apply the policy at the function level, or
-- specify a qualifier to restrict access to a single version or alias. If
-- you use a qualifier, the invoker must use the full Amazon Resource Name
-- (ARN) of that version or alias to invoke the function. Note: Lambda does
-- not support adding policies to version $LATEST.
--
-- To grant permission to another account, specify the account ID as the
-- @Principal@. For Amazon Web Services services, the principal is a
-- domain-style identifier defined by the service, like @s3.amazonaws.com@
-- or @sns.amazonaws.com@. For Amazon Web Services services, you can also
-- specify the ARN of the associated resource as the @SourceArn@. If you
-- grant permission to a service principal without specifying the source,
-- other accounts could potentially configure resources in their account to
-- invoke your Lambda function.
--
-- This action adds a statement to a resource-based permissions policy for
-- the function. For more information about function policies, see
-- <https://docs.aws.amazon.com/lambda/latest/dg/access-control-resource-based.html Lambda Function Policies>.
module Amazonka.Lambda.AddPermission
  ( -- * Creating a Request
    AddPermission (..),
    newAddPermission,

    -- * Request Lenses
    addPermission_sourceAccount,
    addPermission_eventSourceToken,
    addPermission_sourceArn,
    addPermission_qualifier,
    addPermission_revisionId,
    addPermission_functionName,
    addPermission_statementId,
    addPermission_action,
    addPermission_principal,

    -- * Destructuring the Response
    AddPermissionResponse (..),
    newAddPermissionResponse,

    -- * Response Lenses
    addPermissionResponse_statement,
    addPermissionResponse_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:/ 'newAddPermission' smart constructor.
data AddPermission = AddPermission'
  { -- | For Amazon S3, the ID of the account that owns the resource. Use this
    -- together with @SourceArn@ to ensure that the resource is owned by the
    -- specified account. It is possible for an Amazon S3 bucket to be deleted
    -- by its owner and recreated by another account.
    AddPermission -> Maybe Text
sourceAccount :: Prelude.Maybe Prelude.Text,
    -- | For Alexa Smart Home functions, a token that must be supplied by the
    -- invoker.
    AddPermission -> Maybe Text
eventSourceToken :: Prelude.Maybe Prelude.Text,
    -- | For Amazon Web Services services, the ARN of the Amazon Web Services
    -- resource that invokes the function. For example, an Amazon S3 bucket or
    -- Amazon SNS topic.
    --
    -- Note that Lambda configures the comparison using the @StringLike@
    -- operator.
    AddPermission -> Maybe Text
sourceArn :: Prelude.Maybe Prelude.Text,
    -- | Specify a version or alias to add permissions to a published version of
    -- the function.
    AddPermission -> Maybe Text
qualifier :: Prelude.Maybe Prelude.Text,
    -- | Only update the policy if the revision ID matches the ID that\'s
    -- specified. Use this option to avoid modifying a policy that has changed
    -- since you last read it.
    AddPermission -> Maybe Text
revisionId :: Prelude.Maybe Prelude.Text,
    -- | The name of the Lambda function, version, or alias.
    --
    -- __Name formats__
    --
    -- -   __Function name__ - @my-function@ (name-only), @my-function:v1@
    --     (with alias).
    --
    -- -   __Function ARN__ -
    --     @arn:aws:lambda:us-west-2:123456789012:function:my-function@.
    --
    -- -   __Partial ARN__ - @123456789012:function:my-function@.
    --
    -- You can append a version number or alias to any of the formats. The
    -- length constraint applies only to the full ARN. If you specify only the
    -- function name, it is limited to 64 characters in length.
    AddPermission -> Text
functionName :: Prelude.Text,
    -- | A statement identifier that differentiates the statement from others in
    -- the same policy.
    AddPermission -> Text
statementId :: Prelude.Text,
    -- | The action that the principal can use on the function. For example,
    -- @lambda:InvokeFunction@ or @lambda:GetFunction@.
    AddPermission -> Text
action :: Prelude.Text,
    -- | The Amazon Web Services service or account that invokes the function. If
    -- you specify a service, use @SourceArn@ or @SourceAccount@ to limit who
    -- can invoke the function through that service.
    AddPermission -> Text
principal :: Prelude.Text
  }
  deriving (AddPermission -> AddPermission -> Bool
(AddPermission -> AddPermission -> Bool)
-> (AddPermission -> AddPermission -> Bool) -> Eq AddPermission
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AddPermission -> AddPermission -> Bool
$c/= :: AddPermission -> AddPermission -> Bool
== :: AddPermission -> AddPermission -> Bool
$c== :: AddPermission -> AddPermission -> Bool
Prelude.Eq, ReadPrec [AddPermission]
ReadPrec AddPermission
Int -> ReadS AddPermission
ReadS [AddPermission]
(Int -> ReadS AddPermission)
-> ReadS [AddPermission]
-> ReadPrec AddPermission
-> ReadPrec [AddPermission]
-> Read AddPermission
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AddPermission]
$creadListPrec :: ReadPrec [AddPermission]
readPrec :: ReadPrec AddPermission
$creadPrec :: ReadPrec AddPermission
readList :: ReadS [AddPermission]
$creadList :: ReadS [AddPermission]
readsPrec :: Int -> ReadS AddPermission
$creadsPrec :: Int -> ReadS AddPermission
Prelude.Read, Int -> AddPermission -> ShowS
[AddPermission] -> ShowS
AddPermission -> String
(Int -> AddPermission -> ShowS)
-> (AddPermission -> String)
-> ([AddPermission] -> ShowS)
-> Show AddPermission
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddPermission] -> ShowS
$cshowList :: [AddPermission] -> ShowS
show :: AddPermission -> String
$cshow :: AddPermission -> String
showsPrec :: Int -> AddPermission -> ShowS
$cshowsPrec :: Int -> AddPermission -> ShowS
Prelude.Show, (forall x. AddPermission -> Rep AddPermission x)
-> (forall x. Rep AddPermission x -> AddPermission)
-> Generic AddPermission
forall x. Rep AddPermission x -> AddPermission
forall x. AddPermission -> Rep AddPermission x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AddPermission x -> AddPermission
$cfrom :: forall x. AddPermission -> Rep AddPermission x
Prelude.Generic)

-- |
-- Create a value of 'AddPermission' 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:
--
-- 'sourceAccount', 'addPermission_sourceAccount' - For Amazon S3, the ID of the account that owns the resource. Use this
-- together with @SourceArn@ to ensure that the resource is owned by the
-- specified account. It is possible for an Amazon S3 bucket to be deleted
-- by its owner and recreated by another account.
--
-- 'eventSourceToken', 'addPermission_eventSourceToken' - For Alexa Smart Home functions, a token that must be supplied by the
-- invoker.
--
-- 'sourceArn', 'addPermission_sourceArn' - For Amazon Web Services services, the ARN of the Amazon Web Services
-- resource that invokes the function. For example, an Amazon S3 bucket or
-- Amazon SNS topic.
--
-- Note that Lambda configures the comparison using the @StringLike@
-- operator.
--
-- 'qualifier', 'addPermission_qualifier' - Specify a version or alias to add permissions to a published version of
-- the function.
--
-- 'revisionId', 'addPermission_revisionId' - Only update the policy if the revision ID matches the ID that\'s
-- specified. Use this option to avoid modifying a policy that has changed
-- since you last read it.
--
-- 'functionName', 'addPermission_functionName' - The name of the Lambda function, version, or alias.
--
-- __Name formats__
--
-- -   __Function name__ - @my-function@ (name-only), @my-function:v1@
--     (with alias).
--
-- -   __Function ARN__ -
--     @arn:aws:lambda:us-west-2:123456789012:function:my-function@.
--
-- -   __Partial ARN__ - @123456789012:function:my-function@.
--
-- You can append a version number or alias to any of the formats. The
-- length constraint applies only to the full ARN. If you specify only the
-- function name, it is limited to 64 characters in length.
--
-- 'statementId', 'addPermission_statementId' - A statement identifier that differentiates the statement from others in
-- the same policy.
--
-- 'action', 'addPermission_action' - The action that the principal can use on the function. For example,
-- @lambda:InvokeFunction@ or @lambda:GetFunction@.
--
-- 'principal', 'addPermission_principal' - The Amazon Web Services service or account that invokes the function. If
-- you specify a service, use @SourceArn@ or @SourceAccount@ to limit who
-- can invoke the function through that service.
newAddPermission ::
  -- | 'functionName'
  Prelude.Text ->
  -- | 'statementId'
  Prelude.Text ->
  -- | 'action'
  Prelude.Text ->
  -- | 'principal'
  Prelude.Text ->
  AddPermission
newAddPermission :: Text -> Text -> Text -> Text -> AddPermission
newAddPermission
  Text
pFunctionName_
  Text
pStatementId_
  Text
pAction_
  Text
pPrincipal_ =
    AddPermission' :: Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Text
-> Text
-> Text
-> Text
-> AddPermission
AddPermission'
      { $sel:sourceAccount:AddPermission' :: Maybe Text
sourceAccount = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:eventSourceToken:AddPermission' :: Maybe Text
eventSourceToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:sourceArn:AddPermission' :: Maybe Text
sourceArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:qualifier:AddPermission' :: Maybe Text
qualifier = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:revisionId:AddPermission' :: Maybe Text
revisionId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:functionName:AddPermission' :: Text
functionName = Text
pFunctionName_,
        $sel:statementId:AddPermission' :: Text
statementId = Text
pStatementId_,
        $sel:action:AddPermission' :: Text
action = Text
pAction_,
        $sel:principal:AddPermission' :: Text
principal = Text
pPrincipal_
      }

-- | For Amazon S3, the ID of the account that owns the resource. Use this
-- together with @SourceArn@ to ensure that the resource is owned by the
-- specified account. It is possible for an Amazon S3 bucket to be deleted
-- by its owner and recreated by another account.
addPermission_sourceAccount :: Lens.Lens' AddPermission (Prelude.Maybe Prelude.Text)
addPermission_sourceAccount :: (Maybe Text -> f (Maybe Text)) -> AddPermission -> f AddPermission
addPermission_sourceAccount = (AddPermission -> Maybe Text)
-> (AddPermission -> Maybe Text -> AddPermission)
-> Lens AddPermission AddPermission (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddPermission' {Maybe Text
sourceAccount :: Maybe Text
$sel:sourceAccount:AddPermission' :: AddPermission -> Maybe Text
sourceAccount} -> Maybe Text
sourceAccount) (\s :: AddPermission
s@AddPermission' {} Maybe Text
a -> AddPermission
s {$sel:sourceAccount:AddPermission' :: Maybe Text
sourceAccount = Maybe Text
a} :: AddPermission)

-- | For Alexa Smart Home functions, a token that must be supplied by the
-- invoker.
addPermission_eventSourceToken :: Lens.Lens' AddPermission (Prelude.Maybe Prelude.Text)
addPermission_eventSourceToken :: (Maybe Text -> f (Maybe Text)) -> AddPermission -> f AddPermission
addPermission_eventSourceToken = (AddPermission -> Maybe Text)
-> (AddPermission -> Maybe Text -> AddPermission)
-> Lens AddPermission AddPermission (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddPermission' {Maybe Text
eventSourceToken :: Maybe Text
$sel:eventSourceToken:AddPermission' :: AddPermission -> Maybe Text
eventSourceToken} -> Maybe Text
eventSourceToken) (\s :: AddPermission
s@AddPermission' {} Maybe Text
a -> AddPermission
s {$sel:eventSourceToken:AddPermission' :: Maybe Text
eventSourceToken = Maybe Text
a} :: AddPermission)

-- | For Amazon Web Services services, the ARN of the Amazon Web Services
-- resource that invokes the function. For example, an Amazon S3 bucket or
-- Amazon SNS topic.
--
-- Note that Lambda configures the comparison using the @StringLike@
-- operator.
addPermission_sourceArn :: Lens.Lens' AddPermission (Prelude.Maybe Prelude.Text)
addPermission_sourceArn :: (Maybe Text -> f (Maybe Text)) -> AddPermission -> f AddPermission
addPermission_sourceArn = (AddPermission -> Maybe Text)
-> (AddPermission -> Maybe Text -> AddPermission)
-> Lens AddPermission AddPermission (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddPermission' {Maybe Text
sourceArn :: Maybe Text
$sel:sourceArn:AddPermission' :: AddPermission -> Maybe Text
sourceArn} -> Maybe Text
sourceArn) (\s :: AddPermission
s@AddPermission' {} Maybe Text
a -> AddPermission
s {$sel:sourceArn:AddPermission' :: Maybe Text
sourceArn = Maybe Text
a} :: AddPermission)

-- | Specify a version or alias to add permissions to a published version of
-- the function.
addPermission_qualifier :: Lens.Lens' AddPermission (Prelude.Maybe Prelude.Text)
addPermission_qualifier :: (Maybe Text -> f (Maybe Text)) -> AddPermission -> f AddPermission
addPermission_qualifier = (AddPermission -> Maybe Text)
-> (AddPermission -> Maybe Text -> AddPermission)
-> Lens AddPermission AddPermission (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddPermission' {Maybe Text
qualifier :: Maybe Text
$sel:qualifier:AddPermission' :: AddPermission -> Maybe Text
qualifier} -> Maybe Text
qualifier) (\s :: AddPermission
s@AddPermission' {} Maybe Text
a -> AddPermission
s {$sel:qualifier:AddPermission' :: Maybe Text
qualifier = Maybe Text
a} :: AddPermission)

-- | Only update the policy if the revision ID matches the ID that\'s
-- specified. Use this option to avoid modifying a policy that has changed
-- since you last read it.
addPermission_revisionId :: Lens.Lens' AddPermission (Prelude.Maybe Prelude.Text)
addPermission_revisionId :: (Maybe Text -> f (Maybe Text)) -> AddPermission -> f AddPermission
addPermission_revisionId = (AddPermission -> Maybe Text)
-> (AddPermission -> Maybe Text -> AddPermission)
-> Lens AddPermission AddPermission (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddPermission' {Maybe Text
revisionId :: Maybe Text
$sel:revisionId:AddPermission' :: AddPermission -> Maybe Text
revisionId} -> Maybe Text
revisionId) (\s :: AddPermission
s@AddPermission' {} Maybe Text
a -> AddPermission
s {$sel:revisionId:AddPermission' :: Maybe Text
revisionId = Maybe Text
a} :: AddPermission)

-- | The name of the Lambda function, version, or alias.
--
-- __Name formats__
--
-- -   __Function name__ - @my-function@ (name-only), @my-function:v1@
--     (with alias).
--
-- -   __Function ARN__ -
--     @arn:aws:lambda:us-west-2:123456789012:function:my-function@.
--
-- -   __Partial ARN__ - @123456789012:function:my-function@.
--
-- You can append a version number or alias to any of the formats. The
-- length constraint applies only to the full ARN. If you specify only the
-- function name, it is limited to 64 characters in length.
addPermission_functionName :: Lens.Lens' AddPermission Prelude.Text
addPermission_functionName :: (Text -> f Text) -> AddPermission -> f AddPermission
addPermission_functionName = (AddPermission -> Text)
-> (AddPermission -> Text -> AddPermission)
-> Lens AddPermission AddPermission Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddPermission' {Text
functionName :: Text
$sel:functionName:AddPermission' :: AddPermission -> Text
functionName} -> Text
functionName) (\s :: AddPermission
s@AddPermission' {} Text
a -> AddPermission
s {$sel:functionName:AddPermission' :: Text
functionName = Text
a} :: AddPermission)

-- | A statement identifier that differentiates the statement from others in
-- the same policy.
addPermission_statementId :: Lens.Lens' AddPermission Prelude.Text
addPermission_statementId :: (Text -> f Text) -> AddPermission -> f AddPermission
addPermission_statementId = (AddPermission -> Text)
-> (AddPermission -> Text -> AddPermission)
-> Lens AddPermission AddPermission Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddPermission' {Text
statementId :: Text
$sel:statementId:AddPermission' :: AddPermission -> Text
statementId} -> Text
statementId) (\s :: AddPermission
s@AddPermission' {} Text
a -> AddPermission
s {$sel:statementId:AddPermission' :: Text
statementId = Text
a} :: AddPermission)

-- | The action that the principal can use on the function. For example,
-- @lambda:InvokeFunction@ or @lambda:GetFunction@.
addPermission_action :: Lens.Lens' AddPermission Prelude.Text
addPermission_action :: (Text -> f Text) -> AddPermission -> f AddPermission
addPermission_action = (AddPermission -> Text)
-> (AddPermission -> Text -> AddPermission)
-> Lens AddPermission AddPermission Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddPermission' {Text
action :: Text
$sel:action:AddPermission' :: AddPermission -> Text
action} -> Text
action) (\s :: AddPermission
s@AddPermission' {} Text
a -> AddPermission
s {$sel:action:AddPermission' :: Text
action = Text
a} :: AddPermission)

-- | The Amazon Web Services service or account that invokes the function. If
-- you specify a service, use @SourceArn@ or @SourceAccount@ to limit who
-- can invoke the function through that service.
addPermission_principal :: Lens.Lens' AddPermission Prelude.Text
addPermission_principal :: (Text -> f Text) -> AddPermission -> f AddPermission
addPermission_principal = (AddPermission -> Text)
-> (AddPermission -> Text -> AddPermission)
-> Lens AddPermission AddPermission Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddPermission' {Text
principal :: Text
$sel:principal:AddPermission' :: AddPermission -> Text
principal} -> Text
principal) (\s :: AddPermission
s@AddPermission' {} Text
a -> AddPermission
s {$sel:principal:AddPermission' :: Text
principal = Text
a} :: AddPermission)

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

instance Prelude.NFData AddPermission

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

instance Core.ToJSON AddPermission where
  toJSON :: AddPermission -> Value
toJSON AddPermission' {Maybe Text
Text
principal :: Text
action :: Text
statementId :: Text
functionName :: Text
revisionId :: Maybe Text
qualifier :: Maybe Text
sourceArn :: Maybe Text
eventSourceToken :: Maybe Text
sourceAccount :: Maybe Text
$sel:principal:AddPermission' :: AddPermission -> Text
$sel:action:AddPermission' :: AddPermission -> Text
$sel:statementId:AddPermission' :: AddPermission -> Text
$sel:functionName:AddPermission' :: AddPermission -> Text
$sel:revisionId:AddPermission' :: AddPermission -> Maybe Text
$sel:qualifier:AddPermission' :: AddPermission -> Maybe Text
$sel:sourceArn:AddPermission' :: AddPermission -> Maybe Text
$sel:eventSourceToken:AddPermission' :: AddPermission -> Maybe Text
$sel:sourceAccount:AddPermission' :: AddPermission -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"SourceAccount" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
sourceAccount,
            (Text
"EventSourceToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
eventSourceToken,
            (Text
"SourceArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
sourceArn,
            (Text
"RevisionId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
revisionId,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"StatementId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
statementId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Action" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
action),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Principal" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
principal)
          ]
      )

instance Core.ToPath AddPermission where
  toPath :: AddPermission -> ByteString
toPath AddPermission' {Maybe Text
Text
principal :: Text
action :: Text
statementId :: Text
functionName :: Text
revisionId :: Maybe Text
qualifier :: Maybe Text
sourceArn :: Maybe Text
eventSourceToken :: Maybe Text
sourceAccount :: Maybe Text
$sel:principal:AddPermission' :: AddPermission -> Text
$sel:action:AddPermission' :: AddPermission -> Text
$sel:statementId:AddPermission' :: AddPermission -> Text
$sel:functionName:AddPermission' :: AddPermission -> Text
$sel:revisionId:AddPermission' :: AddPermission -> Maybe Text
$sel:qualifier:AddPermission' :: AddPermission -> Maybe Text
$sel:sourceArn:AddPermission' :: AddPermission -> Maybe Text
$sel:eventSourceToken:AddPermission' :: AddPermission -> Maybe Text
$sel:sourceAccount:AddPermission' :: AddPermission -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/2015-03-31/functions/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
functionName,
        ByteString
"/policy"
      ]

instance Core.ToQuery AddPermission where
  toQuery :: AddPermission -> QueryString
toQuery AddPermission' {Maybe Text
Text
principal :: Text
action :: Text
statementId :: Text
functionName :: Text
revisionId :: Maybe Text
qualifier :: Maybe Text
sourceArn :: Maybe Text
eventSourceToken :: Maybe Text
sourceAccount :: Maybe Text
$sel:principal:AddPermission' :: AddPermission -> Text
$sel:action:AddPermission' :: AddPermission -> Text
$sel:statementId:AddPermission' :: AddPermission -> Text
$sel:functionName:AddPermission' :: AddPermission -> Text
$sel:revisionId:AddPermission' :: AddPermission -> Maybe Text
$sel:qualifier:AddPermission' :: AddPermission -> Maybe Text
$sel:sourceArn:AddPermission' :: AddPermission -> Maybe Text
$sel:eventSourceToken:AddPermission' :: AddPermission -> Maybe Text
$sel:sourceAccount:AddPermission' :: AddPermission -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"Qualifier" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
qualifier]

-- | /See:/ 'newAddPermissionResponse' smart constructor.
data AddPermissionResponse = AddPermissionResponse'
  { -- | The permission statement that\'s added to the function policy.
    AddPermissionResponse -> Maybe Text
statement :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    AddPermissionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AddPermissionResponse -> AddPermissionResponse -> Bool
(AddPermissionResponse -> AddPermissionResponse -> Bool)
-> (AddPermissionResponse -> AddPermissionResponse -> Bool)
-> Eq AddPermissionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AddPermissionResponse -> AddPermissionResponse -> Bool
$c/= :: AddPermissionResponse -> AddPermissionResponse -> Bool
== :: AddPermissionResponse -> AddPermissionResponse -> Bool
$c== :: AddPermissionResponse -> AddPermissionResponse -> Bool
Prelude.Eq, ReadPrec [AddPermissionResponse]
ReadPrec AddPermissionResponse
Int -> ReadS AddPermissionResponse
ReadS [AddPermissionResponse]
(Int -> ReadS AddPermissionResponse)
-> ReadS [AddPermissionResponse]
-> ReadPrec AddPermissionResponse
-> ReadPrec [AddPermissionResponse]
-> Read AddPermissionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AddPermissionResponse]
$creadListPrec :: ReadPrec [AddPermissionResponse]
readPrec :: ReadPrec AddPermissionResponse
$creadPrec :: ReadPrec AddPermissionResponse
readList :: ReadS [AddPermissionResponse]
$creadList :: ReadS [AddPermissionResponse]
readsPrec :: Int -> ReadS AddPermissionResponse
$creadsPrec :: Int -> ReadS AddPermissionResponse
Prelude.Read, Int -> AddPermissionResponse -> ShowS
[AddPermissionResponse] -> ShowS
AddPermissionResponse -> String
(Int -> AddPermissionResponse -> ShowS)
-> (AddPermissionResponse -> String)
-> ([AddPermissionResponse] -> ShowS)
-> Show AddPermissionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddPermissionResponse] -> ShowS
$cshowList :: [AddPermissionResponse] -> ShowS
show :: AddPermissionResponse -> String
$cshow :: AddPermissionResponse -> String
showsPrec :: Int -> AddPermissionResponse -> ShowS
$cshowsPrec :: Int -> AddPermissionResponse -> ShowS
Prelude.Show, (forall x. AddPermissionResponse -> Rep AddPermissionResponse x)
-> (forall x. Rep AddPermissionResponse x -> AddPermissionResponse)
-> Generic AddPermissionResponse
forall x. Rep AddPermissionResponse x -> AddPermissionResponse
forall x. AddPermissionResponse -> Rep AddPermissionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AddPermissionResponse x -> AddPermissionResponse
$cfrom :: forall x. AddPermissionResponse -> Rep AddPermissionResponse x
Prelude.Generic)

-- |
-- Create a value of 'AddPermissionResponse' 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:
--
-- 'statement', 'addPermissionResponse_statement' - The permission statement that\'s added to the function policy.
--
-- 'httpStatus', 'addPermissionResponse_httpStatus' - The response's http status code.
newAddPermissionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AddPermissionResponse
newAddPermissionResponse :: Int -> AddPermissionResponse
newAddPermissionResponse Int
pHttpStatus_ =
  AddPermissionResponse' :: Maybe Text -> Int -> AddPermissionResponse
AddPermissionResponse'
    { $sel:statement:AddPermissionResponse' :: Maybe Text
statement = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AddPermissionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The permission statement that\'s added to the function policy.
addPermissionResponse_statement :: Lens.Lens' AddPermissionResponse (Prelude.Maybe Prelude.Text)
addPermissionResponse_statement :: (Maybe Text -> f (Maybe Text))
-> AddPermissionResponse -> f AddPermissionResponse
addPermissionResponse_statement = (AddPermissionResponse -> Maybe Text)
-> (AddPermissionResponse -> Maybe Text -> AddPermissionResponse)
-> Lens
     AddPermissionResponse
     AddPermissionResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddPermissionResponse' {Maybe Text
statement :: Maybe Text
$sel:statement:AddPermissionResponse' :: AddPermissionResponse -> Maybe Text
statement} -> Maybe Text
statement) (\s :: AddPermissionResponse
s@AddPermissionResponse' {} Maybe Text
a -> AddPermissionResponse
s {$sel:statement:AddPermissionResponse' :: Maybe Text
statement = Maybe Text
a} :: AddPermissionResponse)

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

instance Prelude.NFData AddPermissionResponse