{-# 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.Budgets.Types.IamActionDefinition
-- 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.Budgets.Types.IamActionDefinition where

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

-- | The AWS Identity and Access Management (IAM) action definition details.
--
-- /See:/ 'newIamActionDefinition' smart constructor.
data IamActionDefinition = IamActionDefinition'
  { -- | A list of groups to be attached. There must be at least one group.
    IamActionDefinition -> Maybe (NonEmpty Text)
groups :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | A list of roles to be attached. There must be at least one role.
    IamActionDefinition -> Maybe (NonEmpty Text)
roles :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | A list of users to be attached. There must be at least one user.
    IamActionDefinition -> Maybe (NonEmpty Text)
users :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | The Amazon Resource Name (ARN) of the policy to be attached.
    IamActionDefinition -> Text
policyArn :: Prelude.Text
  }
  deriving (IamActionDefinition -> IamActionDefinition -> Bool
(IamActionDefinition -> IamActionDefinition -> Bool)
-> (IamActionDefinition -> IamActionDefinition -> Bool)
-> Eq IamActionDefinition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IamActionDefinition -> IamActionDefinition -> Bool
$c/= :: IamActionDefinition -> IamActionDefinition -> Bool
== :: IamActionDefinition -> IamActionDefinition -> Bool
$c== :: IamActionDefinition -> IamActionDefinition -> Bool
Prelude.Eq, ReadPrec [IamActionDefinition]
ReadPrec IamActionDefinition
Int -> ReadS IamActionDefinition
ReadS [IamActionDefinition]
(Int -> ReadS IamActionDefinition)
-> ReadS [IamActionDefinition]
-> ReadPrec IamActionDefinition
-> ReadPrec [IamActionDefinition]
-> Read IamActionDefinition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IamActionDefinition]
$creadListPrec :: ReadPrec [IamActionDefinition]
readPrec :: ReadPrec IamActionDefinition
$creadPrec :: ReadPrec IamActionDefinition
readList :: ReadS [IamActionDefinition]
$creadList :: ReadS [IamActionDefinition]
readsPrec :: Int -> ReadS IamActionDefinition
$creadsPrec :: Int -> ReadS IamActionDefinition
Prelude.Read, Int -> IamActionDefinition -> ShowS
[IamActionDefinition] -> ShowS
IamActionDefinition -> String
(Int -> IamActionDefinition -> ShowS)
-> (IamActionDefinition -> String)
-> ([IamActionDefinition] -> ShowS)
-> Show IamActionDefinition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IamActionDefinition] -> ShowS
$cshowList :: [IamActionDefinition] -> ShowS
show :: IamActionDefinition -> String
$cshow :: IamActionDefinition -> String
showsPrec :: Int -> IamActionDefinition -> ShowS
$cshowsPrec :: Int -> IamActionDefinition -> ShowS
Prelude.Show, (forall x. IamActionDefinition -> Rep IamActionDefinition x)
-> (forall x. Rep IamActionDefinition x -> IamActionDefinition)
-> Generic IamActionDefinition
forall x. Rep IamActionDefinition x -> IamActionDefinition
forall x. IamActionDefinition -> Rep IamActionDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IamActionDefinition x -> IamActionDefinition
$cfrom :: forall x. IamActionDefinition -> Rep IamActionDefinition x
Prelude.Generic)

-- |
-- Create a value of 'IamActionDefinition' 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:
--
-- 'groups', 'iamActionDefinition_groups' - A list of groups to be attached. There must be at least one group.
--
-- 'roles', 'iamActionDefinition_roles' - A list of roles to be attached. There must be at least one role.
--
-- 'users', 'iamActionDefinition_users' - A list of users to be attached. There must be at least one user.
--
-- 'policyArn', 'iamActionDefinition_policyArn' - The Amazon Resource Name (ARN) of the policy to be attached.
newIamActionDefinition ::
  -- | 'policyArn'
  Prelude.Text ->
  IamActionDefinition
newIamActionDefinition :: Text -> IamActionDefinition
newIamActionDefinition Text
pPolicyArn_ =
  IamActionDefinition' :: Maybe (NonEmpty Text)
-> Maybe (NonEmpty Text)
-> Maybe (NonEmpty Text)
-> Text
-> IamActionDefinition
IamActionDefinition'
    { $sel:groups:IamActionDefinition' :: Maybe (NonEmpty Text)
groups = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:roles:IamActionDefinition' :: Maybe (NonEmpty Text)
roles = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:users:IamActionDefinition' :: Maybe (NonEmpty Text)
users = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:policyArn:IamActionDefinition' :: Text
policyArn = Text
pPolicyArn_
    }

-- | A list of groups to be attached. There must be at least one group.
iamActionDefinition_groups :: Lens.Lens' IamActionDefinition (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
iamActionDefinition_groups :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> IamActionDefinition -> f IamActionDefinition
iamActionDefinition_groups = (IamActionDefinition -> Maybe (NonEmpty Text))
-> (IamActionDefinition
    -> Maybe (NonEmpty Text) -> IamActionDefinition)
-> Lens
     IamActionDefinition
     IamActionDefinition
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IamActionDefinition' {Maybe (NonEmpty Text)
groups :: Maybe (NonEmpty Text)
$sel:groups:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
groups} -> Maybe (NonEmpty Text)
groups) (\s :: IamActionDefinition
s@IamActionDefinition' {} Maybe (NonEmpty Text)
a -> IamActionDefinition
s {$sel:groups:IamActionDefinition' :: Maybe (NonEmpty Text)
groups = Maybe (NonEmpty Text)
a} :: IamActionDefinition) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> IamActionDefinition -> f IamActionDefinition)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> IamActionDefinition
-> f IamActionDefinition
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty 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
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A list of roles to be attached. There must be at least one role.
iamActionDefinition_roles :: Lens.Lens' IamActionDefinition (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
iamActionDefinition_roles :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> IamActionDefinition -> f IamActionDefinition
iamActionDefinition_roles = (IamActionDefinition -> Maybe (NonEmpty Text))
-> (IamActionDefinition
    -> Maybe (NonEmpty Text) -> IamActionDefinition)
-> Lens
     IamActionDefinition
     IamActionDefinition
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IamActionDefinition' {Maybe (NonEmpty Text)
roles :: Maybe (NonEmpty Text)
$sel:roles:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
roles} -> Maybe (NonEmpty Text)
roles) (\s :: IamActionDefinition
s@IamActionDefinition' {} Maybe (NonEmpty Text)
a -> IamActionDefinition
s {$sel:roles:IamActionDefinition' :: Maybe (NonEmpty Text)
roles = Maybe (NonEmpty Text)
a} :: IamActionDefinition) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> IamActionDefinition -> f IamActionDefinition)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> IamActionDefinition
-> f IamActionDefinition
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty 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
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A list of users to be attached. There must be at least one user.
iamActionDefinition_users :: Lens.Lens' IamActionDefinition (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
iamActionDefinition_users :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> IamActionDefinition -> f IamActionDefinition
iamActionDefinition_users = (IamActionDefinition -> Maybe (NonEmpty Text))
-> (IamActionDefinition
    -> Maybe (NonEmpty Text) -> IamActionDefinition)
-> Lens
     IamActionDefinition
     IamActionDefinition
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IamActionDefinition' {Maybe (NonEmpty Text)
users :: Maybe (NonEmpty Text)
$sel:users:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
users} -> Maybe (NonEmpty Text)
users) (\s :: IamActionDefinition
s@IamActionDefinition' {} Maybe (NonEmpty Text)
a -> IamActionDefinition
s {$sel:users:IamActionDefinition' :: Maybe (NonEmpty Text)
users = Maybe (NonEmpty Text)
a} :: IamActionDefinition) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> IamActionDefinition -> f IamActionDefinition)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> IamActionDefinition
-> f IamActionDefinition
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty 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
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The Amazon Resource Name (ARN) of the policy to be attached.
iamActionDefinition_policyArn :: Lens.Lens' IamActionDefinition Prelude.Text
iamActionDefinition_policyArn :: (Text -> f Text) -> IamActionDefinition -> f IamActionDefinition
iamActionDefinition_policyArn = (IamActionDefinition -> Text)
-> (IamActionDefinition -> Text -> IamActionDefinition)
-> Lens IamActionDefinition IamActionDefinition Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IamActionDefinition' {Text
policyArn :: Text
$sel:policyArn:IamActionDefinition' :: IamActionDefinition -> Text
policyArn} -> Text
policyArn) (\s :: IamActionDefinition
s@IamActionDefinition' {} Text
a -> IamActionDefinition
s {$sel:policyArn:IamActionDefinition' :: Text
policyArn = Text
a} :: IamActionDefinition)

instance Core.FromJSON IamActionDefinition where
  parseJSON :: Value -> Parser IamActionDefinition
parseJSON =
    String
-> (Object -> Parser IamActionDefinition)
-> Value
-> Parser IamActionDefinition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"IamActionDefinition"
      ( \Object
x ->
          Maybe (NonEmpty Text)
-> Maybe (NonEmpty Text)
-> Maybe (NonEmpty Text)
-> Text
-> IamActionDefinition
IamActionDefinition'
            (Maybe (NonEmpty Text)
 -> Maybe (NonEmpty Text)
 -> Maybe (NonEmpty Text)
 -> Text
 -> IamActionDefinition)
-> Parser (Maybe (NonEmpty Text))
-> Parser
     (Maybe (NonEmpty Text)
      -> Maybe (NonEmpty Text) -> Text -> IamActionDefinition)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (NonEmpty Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Groups")
            Parser
  (Maybe (NonEmpty Text)
   -> Maybe (NonEmpty Text) -> Text -> IamActionDefinition)
-> Parser (Maybe (NonEmpty Text))
-> Parser (Maybe (NonEmpty Text) -> Text -> IamActionDefinition)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (NonEmpty Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Roles")
            Parser (Maybe (NonEmpty Text) -> Text -> IamActionDefinition)
-> Parser (Maybe (NonEmpty Text))
-> Parser (Text -> IamActionDefinition)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (NonEmpty Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Users")
            Parser (Text -> IamActionDefinition)
-> Parser Text -> Parser IamActionDefinition
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"PolicyArn")
      )

instance Prelude.Hashable IamActionDefinition

instance Prelude.NFData IamActionDefinition

instance Core.ToJSON IamActionDefinition where
  toJSON :: IamActionDefinition -> Value
toJSON IamActionDefinition' {Maybe (NonEmpty Text)
Text
policyArn :: Text
users :: Maybe (NonEmpty Text)
roles :: Maybe (NonEmpty Text)
groups :: Maybe (NonEmpty Text)
$sel:policyArn:IamActionDefinition' :: IamActionDefinition -> Text
$sel:users:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
$sel:roles:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
$sel:groups:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Groups" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty Text -> Pair) -> Maybe (NonEmpty Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
groups,
            (Text
"Roles" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty Text -> Pair) -> Maybe (NonEmpty Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
roles,
            (Text
"Users" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty Text -> Pair) -> Maybe (NonEmpty Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
users,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"PolicyArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
policyArn)
          ]
      )