{-# 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.AccessAnalyzer.Types.KmsGrantConstraints
-- 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.AccessAnalyzer.Types.KmsGrantConstraints where

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

-- | Use this structure to propose allowing
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#cryptographic-operations cryptographic operations>
-- in the grant only when the operation request includes the specified
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#encrypt_context encryption context>.
-- You can specify only one type of encryption context. An empty map is
-- treated as not specified. For more information, see
-- <https://docs.aws.amazon.com/kms/latest/APIReference/API_GrantConstraints.html GrantConstraints>.
--
-- /See:/ 'newKmsGrantConstraints' smart constructor.
data KmsGrantConstraints = KmsGrantConstraints'
  { -- | A list of key-value pairs that must match the encryption context in the
    -- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#cryptographic-operations cryptographic operation>
    -- request. The grant allows the operation only when the encryption context
    -- in the request is the same as the encryption context specified in this
    -- constraint.
    KmsGrantConstraints -> Maybe (HashMap Text Text)
encryptionContextEquals :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | A list of key-value pairs that must be included in the encryption
    -- context of the
    -- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#cryptographic-operations cryptographic operation>
    -- request. The grant allows the cryptographic operation only when the
    -- encryption context in the request includes the key-value pairs specified
    -- in this constraint, although it can include additional key-value pairs.
    KmsGrantConstraints -> Maybe (HashMap Text Text)
encryptionContextSubset :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text)
  }
  deriving (KmsGrantConstraints -> KmsGrantConstraints -> Bool
(KmsGrantConstraints -> KmsGrantConstraints -> Bool)
-> (KmsGrantConstraints -> KmsGrantConstraints -> Bool)
-> Eq KmsGrantConstraints
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: KmsGrantConstraints -> KmsGrantConstraints -> Bool
$c/= :: KmsGrantConstraints -> KmsGrantConstraints -> Bool
== :: KmsGrantConstraints -> KmsGrantConstraints -> Bool
$c== :: KmsGrantConstraints -> KmsGrantConstraints -> Bool
Prelude.Eq, ReadPrec [KmsGrantConstraints]
ReadPrec KmsGrantConstraints
Int -> ReadS KmsGrantConstraints
ReadS [KmsGrantConstraints]
(Int -> ReadS KmsGrantConstraints)
-> ReadS [KmsGrantConstraints]
-> ReadPrec KmsGrantConstraints
-> ReadPrec [KmsGrantConstraints]
-> Read KmsGrantConstraints
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [KmsGrantConstraints]
$creadListPrec :: ReadPrec [KmsGrantConstraints]
readPrec :: ReadPrec KmsGrantConstraints
$creadPrec :: ReadPrec KmsGrantConstraints
readList :: ReadS [KmsGrantConstraints]
$creadList :: ReadS [KmsGrantConstraints]
readsPrec :: Int -> ReadS KmsGrantConstraints
$creadsPrec :: Int -> ReadS KmsGrantConstraints
Prelude.Read, Int -> KmsGrantConstraints -> ShowS
[KmsGrantConstraints] -> ShowS
KmsGrantConstraints -> String
(Int -> KmsGrantConstraints -> ShowS)
-> (KmsGrantConstraints -> String)
-> ([KmsGrantConstraints] -> ShowS)
-> Show KmsGrantConstraints
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [KmsGrantConstraints] -> ShowS
$cshowList :: [KmsGrantConstraints] -> ShowS
show :: KmsGrantConstraints -> String
$cshow :: KmsGrantConstraints -> String
showsPrec :: Int -> KmsGrantConstraints -> ShowS
$cshowsPrec :: Int -> KmsGrantConstraints -> ShowS
Prelude.Show, (forall x. KmsGrantConstraints -> Rep KmsGrantConstraints x)
-> (forall x. Rep KmsGrantConstraints x -> KmsGrantConstraints)
-> Generic KmsGrantConstraints
forall x. Rep KmsGrantConstraints x -> KmsGrantConstraints
forall x. KmsGrantConstraints -> Rep KmsGrantConstraints x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep KmsGrantConstraints x -> KmsGrantConstraints
$cfrom :: forall x. KmsGrantConstraints -> Rep KmsGrantConstraints x
Prelude.Generic)

-- |
-- Create a value of 'KmsGrantConstraints' 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:
--
-- 'encryptionContextEquals', 'kmsGrantConstraints_encryptionContextEquals' - A list of key-value pairs that must match the encryption context in the
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#cryptographic-operations cryptographic operation>
-- request. The grant allows the operation only when the encryption context
-- in the request is the same as the encryption context specified in this
-- constraint.
--
-- 'encryptionContextSubset', 'kmsGrantConstraints_encryptionContextSubset' - A list of key-value pairs that must be included in the encryption
-- context of the
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#cryptographic-operations cryptographic operation>
-- request. The grant allows the cryptographic operation only when the
-- encryption context in the request includes the key-value pairs specified
-- in this constraint, although it can include additional key-value pairs.
newKmsGrantConstraints ::
  KmsGrantConstraints
newKmsGrantConstraints :: KmsGrantConstraints
newKmsGrantConstraints =
  KmsGrantConstraints' :: Maybe (HashMap Text Text)
-> Maybe (HashMap Text Text) -> KmsGrantConstraints
KmsGrantConstraints'
    { $sel:encryptionContextEquals:KmsGrantConstraints' :: Maybe (HashMap Text Text)
encryptionContextEquals =
        Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:encryptionContextSubset:KmsGrantConstraints' :: Maybe (HashMap Text Text)
encryptionContextSubset = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing
    }

-- | A list of key-value pairs that must match the encryption context in the
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#cryptographic-operations cryptographic operation>
-- request. The grant allows the operation only when the encryption context
-- in the request is the same as the encryption context specified in this
-- constraint.
kmsGrantConstraints_encryptionContextEquals :: Lens.Lens' KmsGrantConstraints (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
kmsGrantConstraints_encryptionContextEquals :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> KmsGrantConstraints -> f KmsGrantConstraints
kmsGrantConstraints_encryptionContextEquals = (KmsGrantConstraints -> Maybe (HashMap Text Text))
-> (KmsGrantConstraints
    -> Maybe (HashMap Text Text) -> KmsGrantConstraints)
-> Lens
     KmsGrantConstraints
     KmsGrantConstraints
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KmsGrantConstraints' {Maybe (HashMap Text Text)
encryptionContextEquals :: Maybe (HashMap Text Text)
$sel:encryptionContextEquals:KmsGrantConstraints' :: KmsGrantConstraints -> Maybe (HashMap Text Text)
encryptionContextEquals} -> Maybe (HashMap Text Text)
encryptionContextEquals) (\s :: KmsGrantConstraints
s@KmsGrantConstraints' {} Maybe (HashMap Text Text)
a -> KmsGrantConstraints
s {$sel:encryptionContextEquals:KmsGrantConstraints' :: Maybe (HashMap Text Text)
encryptionContextEquals = Maybe (HashMap Text Text)
a} :: KmsGrantConstraints) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> KmsGrantConstraints -> f KmsGrantConstraints)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> KmsGrantConstraints
-> f KmsGrantConstraints
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text 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
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A list of key-value pairs that must be included in the encryption
-- context of the
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#cryptographic-operations cryptographic operation>
-- request. The grant allows the cryptographic operation only when the
-- encryption context in the request includes the key-value pairs specified
-- in this constraint, although it can include additional key-value pairs.
kmsGrantConstraints_encryptionContextSubset :: Lens.Lens' KmsGrantConstraints (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
kmsGrantConstraints_encryptionContextSubset :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> KmsGrantConstraints -> f KmsGrantConstraints
kmsGrantConstraints_encryptionContextSubset = (KmsGrantConstraints -> Maybe (HashMap Text Text))
-> (KmsGrantConstraints
    -> Maybe (HashMap Text Text) -> KmsGrantConstraints)
-> Lens
     KmsGrantConstraints
     KmsGrantConstraints
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KmsGrantConstraints' {Maybe (HashMap Text Text)
encryptionContextSubset :: Maybe (HashMap Text Text)
$sel:encryptionContextSubset:KmsGrantConstraints' :: KmsGrantConstraints -> Maybe (HashMap Text Text)
encryptionContextSubset} -> Maybe (HashMap Text Text)
encryptionContextSubset) (\s :: KmsGrantConstraints
s@KmsGrantConstraints' {} Maybe (HashMap Text Text)
a -> KmsGrantConstraints
s {$sel:encryptionContextSubset:KmsGrantConstraints' :: Maybe (HashMap Text Text)
encryptionContextSubset = Maybe (HashMap Text Text)
a} :: KmsGrantConstraints) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> KmsGrantConstraints -> f KmsGrantConstraints)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> KmsGrantConstraints
-> f KmsGrantConstraints
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text 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
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON KmsGrantConstraints where
  parseJSON :: Value -> Parser KmsGrantConstraints
parseJSON =
    String
-> (Object -> Parser KmsGrantConstraints)
-> Value
-> Parser KmsGrantConstraints
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"KmsGrantConstraints"
      ( \Object
x ->
          Maybe (HashMap Text Text)
-> Maybe (HashMap Text Text) -> KmsGrantConstraints
KmsGrantConstraints'
            (Maybe (HashMap Text Text)
 -> Maybe (HashMap Text Text) -> KmsGrantConstraints)
-> Parser (Maybe (HashMap Text Text))
-> Parser (Maybe (HashMap Text Text) -> KmsGrantConstraints)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"encryptionContextEquals"
                            Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe (HashMap Text Text) -> KmsGrantConstraints)
-> Parser (Maybe (HashMap Text Text)) -> Parser KmsGrantConstraints
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"encryptionContextSubset"
                            Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable KmsGrantConstraints

instance Prelude.NFData KmsGrantConstraints

instance Core.ToJSON KmsGrantConstraints where
  toJSON :: KmsGrantConstraints -> Value
toJSON KmsGrantConstraints' {Maybe (HashMap Text Text)
encryptionContextSubset :: Maybe (HashMap Text Text)
encryptionContextEquals :: Maybe (HashMap Text Text)
$sel:encryptionContextSubset:KmsGrantConstraints' :: KmsGrantConstraints -> Maybe (HashMap Text Text)
$sel:encryptionContextEquals:KmsGrantConstraints' :: KmsGrantConstraints -> Maybe (HashMap Text Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"encryptionContextEquals" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
encryptionContextEquals,
            (Text
"encryptionContextSubset" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
encryptionContextSubset
          ]
      )