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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $sel:encryptionContextEquals:KmsGrantConstraints' :: Maybe (HashMap Text Text)
encryptionContextEquals =
        forall a. Maybe a
Prelude.Nothing,
      $sel:encryptionContextSubset:KmsGrantConstraints' :: Maybe (HashMap Text Text)
encryptionContextSubset = 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 :: Lens' KmsGrantConstraints (Maybe (HashMap Text Text))
kmsGrantConstraints_encryptionContextEquals = 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) 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

-- | 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 :: Lens' KmsGrantConstraints (Maybe (HashMap Text Text))
kmsGrantConstraints_encryptionContextSubset = 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) 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 Data.FromJSON KmsGrantConstraints where
  parseJSON :: Value -> Parser KmsGrantConstraints
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"KmsGrantConstraints"
      ( \Object
x ->
          Maybe (HashMap Text Text)
-> Maybe (HashMap Text Text) -> KmsGrantConstraints
KmsGrantConstraints'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"encryptionContextEquals"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"encryptionContextSubset"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable KmsGrantConstraints where
  hashWithSalt :: Int -> KmsGrantConstraints -> Int
hashWithSalt Int
_salt 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)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
encryptionContextEquals
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
encryptionContextSubset

instance Prelude.NFData KmsGrantConstraints where
  rnf :: KmsGrantConstraints -> ()
rnf 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)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
encryptionContextEquals
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
encryptionContextSubset

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"encryptionContextEquals" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
encryptionContextEquals,
            (Key
"encryptionContextSubset" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
encryptionContextSubset
          ]
      )