{-# 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.IAM.Types.ContextEntry
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IAM.Types.ContextEntry where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IAM.Types.ContextKeyTypeEnum
import qualified Amazonka.Prelude as Prelude

-- | Contains information about a condition context key. It includes the name
-- of the key and specifies the value (or values, if the context key
-- supports multiple values) to use in the simulation. This information is
-- used when evaluating the @Condition@ elements of the input policies.
--
-- This data type is used as an input parameter to SimulateCustomPolicy and
-- SimulatePrincipalPolicy.
--
-- /See:/ 'newContextEntry' smart constructor.
data ContextEntry = ContextEntry'
  { -- | The full name of a condition context key, including the service prefix.
    -- For example, @aws:SourceIp@ or @s3:VersionId@.
    ContextEntry -> Maybe Text
contextKeyName :: Prelude.Maybe Prelude.Text,
    -- | The data type of the value (or values) specified in the
    -- @ContextKeyValues@ parameter.
    ContextEntry -> Maybe ContextKeyTypeEnum
contextKeyType :: Prelude.Maybe ContextKeyTypeEnum,
    -- | The value (or values, if the condition context key supports multiple
    -- values) to provide to the simulation when the key is referenced by a
    -- @Condition@ element in an input policy.
    ContextEntry -> Maybe [Text]
contextKeyValues :: Prelude.Maybe [Prelude.Text]
  }
  deriving (ContextEntry -> ContextEntry -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ContextEntry -> ContextEntry -> Bool
$c/= :: ContextEntry -> ContextEntry -> Bool
== :: ContextEntry -> ContextEntry -> Bool
$c== :: ContextEntry -> ContextEntry -> Bool
Prelude.Eq, ReadPrec [ContextEntry]
ReadPrec ContextEntry
Int -> ReadS ContextEntry
ReadS [ContextEntry]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ContextEntry]
$creadListPrec :: ReadPrec [ContextEntry]
readPrec :: ReadPrec ContextEntry
$creadPrec :: ReadPrec ContextEntry
readList :: ReadS [ContextEntry]
$creadList :: ReadS [ContextEntry]
readsPrec :: Int -> ReadS ContextEntry
$creadsPrec :: Int -> ReadS ContextEntry
Prelude.Read, Int -> ContextEntry -> ShowS
[ContextEntry] -> ShowS
ContextEntry -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ContextEntry] -> ShowS
$cshowList :: [ContextEntry] -> ShowS
show :: ContextEntry -> String
$cshow :: ContextEntry -> String
showsPrec :: Int -> ContextEntry -> ShowS
$cshowsPrec :: Int -> ContextEntry -> ShowS
Prelude.Show, forall x. Rep ContextEntry x -> ContextEntry
forall x. ContextEntry -> Rep ContextEntry x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ContextEntry x -> ContextEntry
$cfrom :: forall x. ContextEntry -> Rep ContextEntry x
Prelude.Generic)

-- |
-- Create a value of 'ContextEntry' 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:
--
-- 'contextKeyName', 'contextEntry_contextKeyName' - The full name of a condition context key, including the service prefix.
-- For example, @aws:SourceIp@ or @s3:VersionId@.
--
-- 'contextKeyType', 'contextEntry_contextKeyType' - The data type of the value (or values) specified in the
-- @ContextKeyValues@ parameter.
--
-- 'contextKeyValues', 'contextEntry_contextKeyValues' - The value (or values, if the condition context key supports multiple
-- values) to provide to the simulation when the key is referenced by a
-- @Condition@ element in an input policy.
newContextEntry ::
  ContextEntry
newContextEntry :: ContextEntry
newContextEntry =
  ContextEntry'
    { $sel:contextKeyName:ContextEntry' :: Maybe Text
contextKeyName = forall a. Maybe a
Prelude.Nothing,
      $sel:contextKeyType:ContextEntry' :: Maybe ContextKeyTypeEnum
contextKeyType = forall a. Maybe a
Prelude.Nothing,
      $sel:contextKeyValues:ContextEntry' :: Maybe [Text]
contextKeyValues = forall a. Maybe a
Prelude.Nothing
    }

-- | The full name of a condition context key, including the service prefix.
-- For example, @aws:SourceIp@ or @s3:VersionId@.
contextEntry_contextKeyName :: Lens.Lens' ContextEntry (Prelude.Maybe Prelude.Text)
contextEntry_contextKeyName :: Lens' ContextEntry (Maybe Text)
contextEntry_contextKeyName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ContextEntry' {Maybe Text
contextKeyName :: Maybe Text
$sel:contextKeyName:ContextEntry' :: ContextEntry -> Maybe Text
contextKeyName} -> Maybe Text
contextKeyName) (\s :: ContextEntry
s@ContextEntry' {} Maybe Text
a -> ContextEntry
s {$sel:contextKeyName:ContextEntry' :: Maybe Text
contextKeyName = Maybe Text
a} :: ContextEntry)

-- | The data type of the value (or values) specified in the
-- @ContextKeyValues@ parameter.
contextEntry_contextKeyType :: Lens.Lens' ContextEntry (Prelude.Maybe ContextKeyTypeEnum)
contextEntry_contextKeyType :: Lens' ContextEntry (Maybe ContextKeyTypeEnum)
contextEntry_contextKeyType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ContextEntry' {Maybe ContextKeyTypeEnum
contextKeyType :: Maybe ContextKeyTypeEnum
$sel:contextKeyType:ContextEntry' :: ContextEntry -> Maybe ContextKeyTypeEnum
contextKeyType} -> Maybe ContextKeyTypeEnum
contextKeyType) (\s :: ContextEntry
s@ContextEntry' {} Maybe ContextKeyTypeEnum
a -> ContextEntry
s {$sel:contextKeyType:ContextEntry' :: Maybe ContextKeyTypeEnum
contextKeyType = Maybe ContextKeyTypeEnum
a} :: ContextEntry)

-- | The value (or values, if the condition context key supports multiple
-- values) to provide to the simulation when the key is referenced by a
-- @Condition@ element in an input policy.
contextEntry_contextKeyValues :: Lens.Lens' ContextEntry (Prelude.Maybe [Prelude.Text])
contextEntry_contextKeyValues :: Lens' ContextEntry (Maybe [Text])
contextEntry_contextKeyValues = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ContextEntry' {Maybe [Text]
contextKeyValues :: Maybe [Text]
$sel:contextKeyValues:ContextEntry' :: ContextEntry -> Maybe [Text]
contextKeyValues} -> Maybe [Text]
contextKeyValues) (\s :: ContextEntry
s@ContextEntry' {} Maybe [Text]
a -> ContextEntry
s {$sel:contextKeyValues:ContextEntry' :: Maybe [Text]
contextKeyValues = Maybe [Text]
a} :: ContextEntry) 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

instance Prelude.Hashable ContextEntry where
  hashWithSalt :: Int -> ContextEntry -> Int
hashWithSalt Int
_salt ContextEntry' {Maybe [Text]
Maybe Text
Maybe ContextKeyTypeEnum
contextKeyValues :: Maybe [Text]
contextKeyType :: Maybe ContextKeyTypeEnum
contextKeyName :: Maybe Text
$sel:contextKeyValues:ContextEntry' :: ContextEntry -> Maybe [Text]
$sel:contextKeyType:ContextEntry' :: ContextEntry -> Maybe ContextKeyTypeEnum
$sel:contextKeyName:ContextEntry' :: ContextEntry -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
contextKeyName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ContextKeyTypeEnum
contextKeyType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
contextKeyValues

instance Prelude.NFData ContextEntry where
  rnf :: ContextEntry -> ()
rnf ContextEntry' {Maybe [Text]
Maybe Text
Maybe ContextKeyTypeEnum
contextKeyValues :: Maybe [Text]
contextKeyType :: Maybe ContextKeyTypeEnum
contextKeyName :: Maybe Text
$sel:contextKeyValues:ContextEntry' :: ContextEntry -> Maybe [Text]
$sel:contextKeyType:ContextEntry' :: ContextEntry -> Maybe ContextKeyTypeEnum
$sel:contextKeyName:ContextEntry' :: ContextEntry -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
contextKeyName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ContextKeyTypeEnum
contextKeyType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
contextKeyValues

instance Data.ToQuery ContextEntry where
  toQuery :: ContextEntry -> QueryString
toQuery ContextEntry' {Maybe [Text]
Maybe Text
Maybe ContextKeyTypeEnum
contextKeyValues :: Maybe [Text]
contextKeyType :: Maybe ContextKeyTypeEnum
contextKeyName :: Maybe Text
$sel:contextKeyValues:ContextEntry' :: ContextEntry -> Maybe [Text]
$sel:contextKeyType:ContextEntry' :: ContextEntry -> Maybe ContextKeyTypeEnum
$sel:contextKeyName:ContextEntry' :: ContextEntry -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"ContextKeyName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
contextKeyName,
        ByteString
"ContextKeyType" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe ContextKeyTypeEnum
contextKeyType,
        ByteString
"ContextKeyValues"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: forall a. ToQuery a => a -> QueryString
Data.toQuery
            ( forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Data.toQueryList ByteString
"member"
                forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
contextKeyValues
            )
      ]