{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.ApplicationPolicyStatement
-- 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)
module Amazonka.ServerlessApplicationRepository.Types.ApplicationPolicyStatement where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Policy statement applied to the application.
--
-- /See:/ 'newApplicationPolicyStatement' smart constructor.
data ApplicationPolicyStatement = ApplicationPolicyStatement'
  { -- | A unique ID for the statement.
    ApplicationPolicyStatement -> Maybe Text
statementId :: Prelude.Maybe Prelude.Text,
    -- | An array of PrinciplalOrgIDs, which corresponds to AWS IAM
    -- <https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#principal-org-id aws:PrincipalOrgID>
    -- global condition key.
    ApplicationPolicyStatement -> Maybe [Text]
principalOrgIDs :: Prelude.Maybe [Prelude.Text],
    -- | An array of AWS account IDs, or * to make the application public.
    ApplicationPolicyStatement -> [Text]
principals :: [Prelude.Text],
    -- | For the list of actions supported for this operation, see
    -- <https://docs.aws.amazon.com/serverlessrepo/latest/devguide/access-control-resource-based.html#application-permissions Application Permissions>.
    ApplicationPolicyStatement -> [Text]
actions :: [Prelude.Text]
  }
  deriving (ApplicationPolicyStatement -> ApplicationPolicyStatement -> Bool
(ApplicationPolicyStatement -> ApplicationPolicyStatement -> Bool)
-> (ApplicationPolicyStatement
    -> ApplicationPolicyStatement -> Bool)
-> Eq ApplicationPolicyStatement
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ApplicationPolicyStatement -> ApplicationPolicyStatement -> Bool
$c/= :: ApplicationPolicyStatement -> ApplicationPolicyStatement -> Bool
== :: ApplicationPolicyStatement -> ApplicationPolicyStatement -> Bool
$c== :: ApplicationPolicyStatement -> ApplicationPolicyStatement -> Bool
Prelude.Eq, ReadPrec [ApplicationPolicyStatement]
ReadPrec ApplicationPolicyStatement
Int -> ReadS ApplicationPolicyStatement
ReadS [ApplicationPolicyStatement]
(Int -> ReadS ApplicationPolicyStatement)
-> ReadS [ApplicationPolicyStatement]
-> ReadPrec ApplicationPolicyStatement
-> ReadPrec [ApplicationPolicyStatement]
-> Read ApplicationPolicyStatement
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ApplicationPolicyStatement]
$creadListPrec :: ReadPrec [ApplicationPolicyStatement]
readPrec :: ReadPrec ApplicationPolicyStatement
$creadPrec :: ReadPrec ApplicationPolicyStatement
readList :: ReadS [ApplicationPolicyStatement]
$creadList :: ReadS [ApplicationPolicyStatement]
readsPrec :: Int -> ReadS ApplicationPolicyStatement
$creadsPrec :: Int -> ReadS ApplicationPolicyStatement
Prelude.Read, Int -> ApplicationPolicyStatement -> ShowS
[ApplicationPolicyStatement] -> ShowS
ApplicationPolicyStatement -> String
(Int -> ApplicationPolicyStatement -> ShowS)
-> (ApplicationPolicyStatement -> String)
-> ([ApplicationPolicyStatement] -> ShowS)
-> Show ApplicationPolicyStatement
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ApplicationPolicyStatement] -> ShowS
$cshowList :: [ApplicationPolicyStatement] -> ShowS
show :: ApplicationPolicyStatement -> String
$cshow :: ApplicationPolicyStatement -> String
showsPrec :: Int -> ApplicationPolicyStatement -> ShowS
$cshowsPrec :: Int -> ApplicationPolicyStatement -> ShowS
Prelude.Show, (forall x.
 ApplicationPolicyStatement -> Rep ApplicationPolicyStatement x)
-> (forall x.
    Rep ApplicationPolicyStatement x -> ApplicationPolicyStatement)
-> Generic ApplicationPolicyStatement
forall x.
Rep ApplicationPolicyStatement x -> ApplicationPolicyStatement
forall x.
ApplicationPolicyStatement -> Rep ApplicationPolicyStatement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ApplicationPolicyStatement x -> ApplicationPolicyStatement
$cfrom :: forall x.
ApplicationPolicyStatement -> Rep ApplicationPolicyStatement x
Prelude.Generic)

-- |
-- Create a value of 'ApplicationPolicyStatement' 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:
--
-- 'statementId', 'applicationPolicyStatement_statementId' - A unique ID for the statement.
--
-- 'principalOrgIDs', 'applicationPolicyStatement_principalOrgIDs' - An array of PrinciplalOrgIDs, which corresponds to AWS IAM
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#principal-org-id aws:PrincipalOrgID>
-- global condition key.
--
-- 'principals', 'applicationPolicyStatement_principals' - An array of AWS account IDs, or * to make the application public.
--
-- 'actions', 'applicationPolicyStatement_actions' - For the list of actions supported for this operation, see
-- <https://docs.aws.amazon.com/serverlessrepo/latest/devguide/access-control-resource-based.html#application-permissions Application Permissions>.
newApplicationPolicyStatement ::
  ApplicationPolicyStatement
newApplicationPolicyStatement :: ApplicationPolicyStatement
newApplicationPolicyStatement =
  ApplicationPolicyStatement' :: Maybe Text
-> Maybe [Text] -> [Text] -> [Text] -> ApplicationPolicyStatement
ApplicationPolicyStatement'
    { $sel:statementId:ApplicationPolicyStatement' :: Maybe Text
statementId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:principalOrgIDs:ApplicationPolicyStatement' :: Maybe [Text]
principalOrgIDs = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:principals:ApplicationPolicyStatement' :: [Text]
principals = [Text]
forall a. Monoid a => a
Prelude.mempty,
      $sel:actions:ApplicationPolicyStatement' :: [Text]
actions = [Text]
forall a. Monoid a => a
Prelude.mempty
    }

-- | A unique ID for the statement.
applicationPolicyStatement_statementId :: Lens.Lens' ApplicationPolicyStatement (Prelude.Maybe Prelude.Text)
applicationPolicyStatement_statementId :: (Maybe Text -> f (Maybe Text))
-> ApplicationPolicyStatement -> f ApplicationPolicyStatement
applicationPolicyStatement_statementId = (ApplicationPolicyStatement -> Maybe Text)
-> (ApplicationPolicyStatement
    -> Maybe Text -> ApplicationPolicyStatement)
-> Lens
     ApplicationPolicyStatement
     ApplicationPolicyStatement
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApplicationPolicyStatement' {Maybe Text
statementId :: Maybe Text
$sel:statementId:ApplicationPolicyStatement' :: ApplicationPolicyStatement -> Maybe Text
statementId} -> Maybe Text
statementId) (\s :: ApplicationPolicyStatement
s@ApplicationPolicyStatement' {} Maybe Text
a -> ApplicationPolicyStatement
s {$sel:statementId:ApplicationPolicyStatement' :: Maybe Text
statementId = Maybe Text
a} :: ApplicationPolicyStatement)

-- | An array of PrinciplalOrgIDs, which corresponds to AWS IAM
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#principal-org-id aws:PrincipalOrgID>
-- global condition key.
applicationPolicyStatement_principalOrgIDs :: Lens.Lens' ApplicationPolicyStatement (Prelude.Maybe [Prelude.Text])
applicationPolicyStatement_principalOrgIDs :: (Maybe [Text] -> f (Maybe [Text]))
-> ApplicationPolicyStatement -> f ApplicationPolicyStatement
applicationPolicyStatement_principalOrgIDs = (ApplicationPolicyStatement -> Maybe [Text])
-> (ApplicationPolicyStatement
    -> Maybe [Text] -> ApplicationPolicyStatement)
-> Lens
     ApplicationPolicyStatement
     ApplicationPolicyStatement
     (Maybe [Text])
     (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApplicationPolicyStatement' {Maybe [Text]
principalOrgIDs :: Maybe [Text]
$sel:principalOrgIDs:ApplicationPolicyStatement' :: ApplicationPolicyStatement -> Maybe [Text]
principalOrgIDs} -> Maybe [Text]
principalOrgIDs) (\s :: ApplicationPolicyStatement
s@ApplicationPolicyStatement' {} Maybe [Text]
a -> ApplicationPolicyStatement
s {$sel:principalOrgIDs:ApplicationPolicyStatement' :: Maybe [Text]
principalOrgIDs = Maybe [Text]
a} :: ApplicationPolicyStatement) ((Maybe [Text] -> f (Maybe [Text]))
 -> ApplicationPolicyStatement -> f ApplicationPolicyStatement)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> ApplicationPolicyStatement
-> f ApplicationPolicyStatement
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | An array of AWS account IDs, or * to make the application public.
applicationPolicyStatement_principals :: Lens.Lens' ApplicationPolicyStatement [Prelude.Text]
applicationPolicyStatement_principals :: ([Text] -> f [Text])
-> ApplicationPolicyStatement -> f ApplicationPolicyStatement
applicationPolicyStatement_principals = (ApplicationPolicyStatement -> [Text])
-> (ApplicationPolicyStatement
    -> [Text] -> ApplicationPolicyStatement)
-> Lens
     ApplicationPolicyStatement ApplicationPolicyStatement [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApplicationPolicyStatement' {[Text]
principals :: [Text]
$sel:principals:ApplicationPolicyStatement' :: ApplicationPolicyStatement -> [Text]
principals} -> [Text]
principals) (\s :: ApplicationPolicyStatement
s@ApplicationPolicyStatement' {} [Text]
a -> ApplicationPolicyStatement
s {$sel:principals:ApplicationPolicyStatement' :: [Text]
principals = [Text]
a} :: ApplicationPolicyStatement) (([Text] -> f [Text])
 -> ApplicationPolicyStatement -> f ApplicationPolicyStatement)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> ApplicationPolicyStatement
-> f ApplicationPolicyStatement
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | For the list of actions supported for this operation, see
-- <https://docs.aws.amazon.com/serverlessrepo/latest/devguide/access-control-resource-based.html#application-permissions Application Permissions>.
applicationPolicyStatement_actions :: Lens.Lens' ApplicationPolicyStatement [Prelude.Text]
applicationPolicyStatement_actions :: ([Text] -> f [Text])
-> ApplicationPolicyStatement -> f ApplicationPolicyStatement
applicationPolicyStatement_actions = (ApplicationPolicyStatement -> [Text])
-> (ApplicationPolicyStatement
    -> [Text] -> ApplicationPolicyStatement)
-> Lens
     ApplicationPolicyStatement ApplicationPolicyStatement [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApplicationPolicyStatement' {[Text]
actions :: [Text]
$sel:actions:ApplicationPolicyStatement' :: ApplicationPolicyStatement -> [Text]
actions} -> [Text]
actions) (\s :: ApplicationPolicyStatement
s@ApplicationPolicyStatement' {} [Text]
a -> ApplicationPolicyStatement
s {$sel:actions:ApplicationPolicyStatement' :: [Text]
actions = [Text]
a} :: ApplicationPolicyStatement) (([Text] -> f [Text])
 -> ApplicationPolicyStatement -> f ApplicationPolicyStatement)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> ApplicationPolicyStatement
-> f ApplicationPolicyStatement
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON ApplicationPolicyStatement where
  parseJSON :: Value -> Parser ApplicationPolicyStatement
parseJSON =
    String
-> (Object -> Parser ApplicationPolicyStatement)
-> Value
-> Parser ApplicationPolicyStatement
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ApplicationPolicyStatement"
      ( \Object
x ->
          Maybe Text
-> Maybe [Text] -> [Text] -> [Text] -> ApplicationPolicyStatement
ApplicationPolicyStatement'
            (Maybe Text
 -> Maybe [Text] -> [Text] -> [Text] -> ApplicationPolicyStatement)
-> Parser (Maybe Text)
-> Parser
     (Maybe [Text] -> [Text] -> [Text] -> ApplicationPolicyStatement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"statementId")
            Parser
  (Maybe [Text] -> [Text] -> [Text] -> ApplicationPolicyStatement)
-> Parser (Maybe [Text])
-> Parser ([Text] -> [Text] -> ApplicationPolicyStatement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"principalOrgIDs"
                            Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser ([Text] -> [Text] -> ApplicationPolicyStatement)
-> Parser [Text] -> Parser ([Text] -> ApplicationPolicyStatement)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"principals" Parser (Maybe [Text]) -> [Text] -> Parser [Text]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser ([Text] -> ApplicationPolicyStatement)
-> Parser [Text] -> Parser ApplicationPolicyStatement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"actions" Parser (Maybe [Text]) -> [Text] -> Parser [Text]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [Text]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable ApplicationPolicyStatement

instance Prelude.NFData ApplicationPolicyStatement

instance Core.ToJSON ApplicationPolicyStatement where
  toJSON :: ApplicationPolicyStatement -> Value
toJSON ApplicationPolicyStatement' {[Text]
Maybe [Text]
Maybe Text
actions :: [Text]
principals :: [Text]
principalOrgIDs :: Maybe [Text]
statementId :: Maybe Text
$sel:actions:ApplicationPolicyStatement' :: ApplicationPolicyStatement -> [Text]
$sel:principals:ApplicationPolicyStatement' :: ApplicationPolicyStatement -> [Text]
$sel:principalOrgIDs:ApplicationPolicyStatement' :: ApplicationPolicyStatement -> Maybe [Text]
$sel:statementId:ApplicationPolicyStatement' :: ApplicationPolicyStatement -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"statementId" 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
statementId,
            (Text
"principalOrgIDs" 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]
principalOrgIDs,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"principals" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
principals),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"actions" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
actions)
          ]
      )