{-# 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-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.IAM.Types.ContextEntry where

import qualified Amazonka.Core as Core
import Amazonka.IAM.Types.ContextKeyTypeEnum
import qualified Amazonka.Lens as Lens
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 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],
    -- | 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
  }
  deriving (ContextEntry -> ContextEntry -> Bool
(ContextEntry -> ContextEntry -> Bool)
-> (ContextEntry -> ContextEntry -> Bool) -> Eq ContextEntry
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]
(Int -> ReadS ContextEntry)
-> ReadS [ContextEntry]
-> ReadPrec ContextEntry
-> ReadPrec [ContextEntry]
-> Read 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
(Int -> ContextEntry -> ShowS)
-> (ContextEntry -> String)
-> ([ContextEntry] -> ShowS)
-> Show ContextEntry
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. ContextEntry -> Rep ContextEntry x)
-> (forall x. Rep ContextEntry x -> ContextEntry)
-> Generic ContextEntry
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:
--
-- '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.
--
-- '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.
newContextEntry ::
  ContextEntry
newContextEntry :: ContextEntry
newContextEntry =
  ContextEntry' :: Maybe [Text]
-> Maybe Text -> Maybe ContextKeyTypeEnum -> ContextEntry
ContextEntry'
    { $sel:contextKeyValues:ContextEntry' :: Maybe [Text]
contextKeyValues = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:contextKeyName:ContextEntry' :: Maybe Text
contextKeyName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:contextKeyType:ContextEntry' :: Maybe ContextKeyTypeEnum
contextKeyType = Maybe ContextKeyTypeEnum
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe [Text] -> f (Maybe [Text]))
-> ContextEntry -> f ContextEntry
contextEntry_contextKeyValues = (ContextEntry -> Maybe [Text])
-> (ContextEntry -> Maybe [Text] -> ContextEntry)
-> Lens ContextEntry ContextEntry (Maybe [Text]) (Maybe [Text])
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) ((Maybe [Text] -> f (Maybe [Text]))
 -> ContextEntry -> f ContextEntry)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> ContextEntry
-> f ContextEntry
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

-- | 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 :: (Maybe Text -> f (Maybe Text)) -> ContextEntry -> f ContextEntry
contextEntry_contextKeyName = (ContextEntry -> Maybe Text)
-> (ContextEntry -> Maybe Text -> ContextEntry)
-> Lens ContextEntry ContextEntry (Maybe Text) (Maybe Text)
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 :: (Maybe ContextKeyTypeEnum -> f (Maybe ContextKeyTypeEnum))
-> ContextEntry -> f ContextEntry
contextEntry_contextKeyType = (ContextEntry -> Maybe ContextKeyTypeEnum)
-> (ContextEntry -> Maybe ContextKeyTypeEnum -> ContextEntry)
-> Lens
     ContextEntry
     ContextEntry
     (Maybe ContextKeyTypeEnum)
     (Maybe ContextKeyTypeEnum)
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)

instance Prelude.Hashable ContextEntry

instance Prelude.NFData ContextEntry

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