{-# 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.SSOAdmin.Types.AccessControlAttribute
-- 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.SSOAdmin.Types.AccessControlAttribute where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SSOAdmin.Types.AccessControlAttributeValue

-- | These are Amazon Web Services SSO identity store attributes that you can
-- configure for use in attributes-based access control (ABAC). You can
-- create permissions policies that determine who can access your Amazon
-- Web Services resources based upon the configured attribute values. When
-- you enable ABAC and specify @AccessControlAttributes@, Amazon Web
-- Services SSO passes the attribute values of the authenticated user into
-- IAM for use in policy evaluation.
--
-- /See:/ 'newAccessControlAttribute' smart constructor.
data AccessControlAttribute = AccessControlAttribute'
  { -- | The name of the attribute associated with your identities in your
    -- identity source. This is used to map a specified attribute in your
    -- identity source with an attribute in Amazon Web Services SSO.
    AccessControlAttribute -> Text
key :: Prelude.Text,
    -- | The value used for mapping a specified attribute to an identity source.
    AccessControlAttribute -> AccessControlAttributeValue
value :: AccessControlAttributeValue
  }
  deriving (AccessControlAttribute -> AccessControlAttribute -> Bool
(AccessControlAttribute -> AccessControlAttribute -> Bool)
-> (AccessControlAttribute -> AccessControlAttribute -> Bool)
-> Eq AccessControlAttribute
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AccessControlAttribute -> AccessControlAttribute -> Bool
$c/= :: AccessControlAttribute -> AccessControlAttribute -> Bool
== :: AccessControlAttribute -> AccessControlAttribute -> Bool
$c== :: AccessControlAttribute -> AccessControlAttribute -> Bool
Prelude.Eq, ReadPrec [AccessControlAttribute]
ReadPrec AccessControlAttribute
Int -> ReadS AccessControlAttribute
ReadS [AccessControlAttribute]
(Int -> ReadS AccessControlAttribute)
-> ReadS [AccessControlAttribute]
-> ReadPrec AccessControlAttribute
-> ReadPrec [AccessControlAttribute]
-> Read AccessControlAttribute
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AccessControlAttribute]
$creadListPrec :: ReadPrec [AccessControlAttribute]
readPrec :: ReadPrec AccessControlAttribute
$creadPrec :: ReadPrec AccessControlAttribute
readList :: ReadS [AccessControlAttribute]
$creadList :: ReadS [AccessControlAttribute]
readsPrec :: Int -> ReadS AccessControlAttribute
$creadsPrec :: Int -> ReadS AccessControlAttribute
Prelude.Read, Int -> AccessControlAttribute -> ShowS
[AccessControlAttribute] -> ShowS
AccessControlAttribute -> String
(Int -> AccessControlAttribute -> ShowS)
-> (AccessControlAttribute -> String)
-> ([AccessControlAttribute] -> ShowS)
-> Show AccessControlAttribute
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AccessControlAttribute] -> ShowS
$cshowList :: [AccessControlAttribute] -> ShowS
show :: AccessControlAttribute -> String
$cshow :: AccessControlAttribute -> String
showsPrec :: Int -> AccessControlAttribute -> ShowS
$cshowsPrec :: Int -> AccessControlAttribute -> ShowS
Prelude.Show, (forall x. AccessControlAttribute -> Rep AccessControlAttribute x)
-> (forall x.
    Rep AccessControlAttribute x -> AccessControlAttribute)
-> Generic AccessControlAttribute
forall x. Rep AccessControlAttribute x -> AccessControlAttribute
forall x. AccessControlAttribute -> Rep AccessControlAttribute x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AccessControlAttribute x -> AccessControlAttribute
$cfrom :: forall x. AccessControlAttribute -> Rep AccessControlAttribute x
Prelude.Generic)

-- |
-- Create a value of 'AccessControlAttribute' 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:
--
-- 'key', 'accessControlAttribute_key' - The name of the attribute associated with your identities in your
-- identity source. This is used to map a specified attribute in your
-- identity source with an attribute in Amazon Web Services SSO.
--
-- 'value', 'accessControlAttribute_value' - The value used for mapping a specified attribute to an identity source.
newAccessControlAttribute ::
  -- | 'key'
  Prelude.Text ->
  -- | 'value'
  AccessControlAttributeValue ->
  AccessControlAttribute
newAccessControlAttribute :: Text -> AccessControlAttributeValue -> AccessControlAttribute
newAccessControlAttribute Text
pKey_ AccessControlAttributeValue
pValue_ =
  AccessControlAttribute' :: Text -> AccessControlAttributeValue -> AccessControlAttribute
AccessControlAttribute'
    { $sel:key:AccessControlAttribute' :: Text
key = Text
pKey_,
      $sel:value:AccessControlAttribute' :: AccessControlAttributeValue
value = AccessControlAttributeValue
pValue_
    }

-- | The name of the attribute associated with your identities in your
-- identity source. This is used to map a specified attribute in your
-- identity source with an attribute in Amazon Web Services SSO.
accessControlAttribute_key :: Lens.Lens' AccessControlAttribute Prelude.Text
accessControlAttribute_key :: (Text -> f Text)
-> AccessControlAttribute -> f AccessControlAttribute
accessControlAttribute_key = (AccessControlAttribute -> Text)
-> (AccessControlAttribute -> Text -> AccessControlAttribute)
-> Lens AccessControlAttribute AccessControlAttribute Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessControlAttribute' {Text
key :: Text
$sel:key:AccessControlAttribute' :: AccessControlAttribute -> Text
key} -> Text
key) (\s :: AccessControlAttribute
s@AccessControlAttribute' {} Text
a -> AccessControlAttribute
s {$sel:key:AccessControlAttribute' :: Text
key = Text
a} :: AccessControlAttribute)

-- | The value used for mapping a specified attribute to an identity source.
accessControlAttribute_value :: Lens.Lens' AccessControlAttribute AccessControlAttributeValue
accessControlAttribute_value :: (AccessControlAttributeValue -> f AccessControlAttributeValue)
-> AccessControlAttribute -> f AccessControlAttribute
accessControlAttribute_value = (AccessControlAttribute -> AccessControlAttributeValue)
-> (AccessControlAttribute
    -> AccessControlAttributeValue -> AccessControlAttribute)
-> Lens
     AccessControlAttribute
     AccessControlAttribute
     AccessControlAttributeValue
     AccessControlAttributeValue
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessControlAttribute' {AccessControlAttributeValue
value :: AccessControlAttributeValue
$sel:value:AccessControlAttribute' :: AccessControlAttribute -> AccessControlAttributeValue
value} -> AccessControlAttributeValue
value) (\s :: AccessControlAttribute
s@AccessControlAttribute' {} AccessControlAttributeValue
a -> AccessControlAttribute
s {$sel:value:AccessControlAttribute' :: AccessControlAttributeValue
value = AccessControlAttributeValue
a} :: AccessControlAttribute)

instance Core.FromJSON AccessControlAttribute where
  parseJSON :: Value -> Parser AccessControlAttribute
parseJSON =
    String
-> (Object -> Parser AccessControlAttribute)
-> Value
-> Parser AccessControlAttribute
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AccessControlAttribute"
      ( \Object
x ->
          Text -> AccessControlAttributeValue -> AccessControlAttribute
AccessControlAttribute'
            (Text -> AccessControlAttributeValue -> AccessControlAttribute)
-> Parser Text
-> Parser (AccessControlAttributeValue -> AccessControlAttribute)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Key") Parser (AccessControlAttributeValue -> AccessControlAttribute)
-> Parser AccessControlAttributeValue
-> Parser AccessControlAttribute
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser AccessControlAttributeValue
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Value")
      )

instance Prelude.Hashable AccessControlAttribute

instance Prelude.NFData AccessControlAttribute

instance Core.ToJSON AccessControlAttribute where
  toJSON :: AccessControlAttribute -> Value
toJSON AccessControlAttribute' {Text
AccessControlAttributeValue
value :: AccessControlAttributeValue
key :: Text
$sel:value:AccessControlAttribute' :: AccessControlAttribute -> AccessControlAttributeValue
$sel:key:AccessControlAttribute' :: AccessControlAttribute -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Key" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
key),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Value" Text -> AccessControlAttributeValue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= AccessControlAttributeValue
value)
          ]
      )