{-# 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.KmsGrantConfiguration
-- 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.KmsGrantConfiguration where

import Amazonka.AccessAnalyzer.Types.KmsGrantConstraints
import Amazonka.AccessAnalyzer.Types.KmsGrantOperation
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

-- | A proposed grant configuration for a KMS key. For more information, see
-- <https://docs.aws.amazon.com/kms/latest/APIReference/API_CreateGrant.html CreateGrant>.
--
-- /See:/ 'newKmsGrantConfiguration' smart constructor.
data KmsGrantConfiguration = KmsGrantConfiguration'
  { -- | 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>.
    KmsGrantConfiguration -> Maybe KmsGrantConstraints
constraints :: Prelude.Maybe KmsGrantConstraints,
    -- | The principal that is given permission to retire the grant by using
    -- <https://docs.aws.amazon.com/kms/latest/APIReference/API_RetireGrant.html RetireGrant>
    -- operation.
    KmsGrantConfiguration -> Maybe Text
retiringPrincipal :: Prelude.Maybe Prelude.Text,
    -- | A list of operations that the grant permits.
    KmsGrantConfiguration -> [KmsGrantOperation]
operations :: [KmsGrantOperation],
    -- | The principal that is given permission to perform the operations that
    -- the grant permits.
    KmsGrantConfiguration -> Text
granteePrincipal :: Prelude.Text,
    -- | The Amazon Web Services account under which the grant was issued. The
    -- account is used to propose KMS grants issued by accounts other than the
    -- owner of the key.
    KmsGrantConfiguration -> Text
issuingAccount :: Prelude.Text
  }
  deriving (KmsGrantConfiguration -> KmsGrantConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: KmsGrantConfiguration -> KmsGrantConfiguration -> Bool
$c/= :: KmsGrantConfiguration -> KmsGrantConfiguration -> Bool
== :: KmsGrantConfiguration -> KmsGrantConfiguration -> Bool
$c== :: KmsGrantConfiguration -> KmsGrantConfiguration -> Bool
Prelude.Eq, ReadPrec [KmsGrantConfiguration]
ReadPrec KmsGrantConfiguration
Int -> ReadS KmsGrantConfiguration
ReadS [KmsGrantConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [KmsGrantConfiguration]
$creadListPrec :: ReadPrec [KmsGrantConfiguration]
readPrec :: ReadPrec KmsGrantConfiguration
$creadPrec :: ReadPrec KmsGrantConfiguration
readList :: ReadS [KmsGrantConfiguration]
$creadList :: ReadS [KmsGrantConfiguration]
readsPrec :: Int -> ReadS KmsGrantConfiguration
$creadsPrec :: Int -> ReadS KmsGrantConfiguration
Prelude.Read, Int -> KmsGrantConfiguration -> ShowS
[KmsGrantConfiguration] -> ShowS
KmsGrantConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [KmsGrantConfiguration] -> ShowS
$cshowList :: [KmsGrantConfiguration] -> ShowS
show :: KmsGrantConfiguration -> String
$cshow :: KmsGrantConfiguration -> String
showsPrec :: Int -> KmsGrantConfiguration -> ShowS
$cshowsPrec :: Int -> KmsGrantConfiguration -> ShowS
Prelude.Show, forall x. Rep KmsGrantConfiguration x -> KmsGrantConfiguration
forall x. KmsGrantConfiguration -> Rep KmsGrantConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep KmsGrantConfiguration x -> KmsGrantConfiguration
$cfrom :: forall x. KmsGrantConfiguration -> Rep KmsGrantConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'KmsGrantConfiguration' 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:
--
-- 'constraints', 'kmsGrantConfiguration_constraints' - 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>.
--
-- 'retiringPrincipal', 'kmsGrantConfiguration_retiringPrincipal' - The principal that is given permission to retire the grant by using
-- <https://docs.aws.amazon.com/kms/latest/APIReference/API_RetireGrant.html RetireGrant>
-- operation.
--
-- 'operations', 'kmsGrantConfiguration_operations' - A list of operations that the grant permits.
--
-- 'granteePrincipal', 'kmsGrantConfiguration_granteePrincipal' - The principal that is given permission to perform the operations that
-- the grant permits.
--
-- 'issuingAccount', 'kmsGrantConfiguration_issuingAccount' - The Amazon Web Services account under which the grant was issued. The
-- account is used to propose KMS grants issued by accounts other than the
-- owner of the key.
newKmsGrantConfiguration ::
  -- | 'granteePrincipal'
  Prelude.Text ->
  -- | 'issuingAccount'
  Prelude.Text ->
  KmsGrantConfiguration
newKmsGrantConfiguration :: Text -> Text -> KmsGrantConfiguration
newKmsGrantConfiguration
  Text
pGranteePrincipal_
  Text
pIssuingAccount_ =
    KmsGrantConfiguration'
      { $sel:constraints:KmsGrantConfiguration' :: Maybe KmsGrantConstraints
constraints =
          forall a. Maybe a
Prelude.Nothing,
        $sel:retiringPrincipal:KmsGrantConfiguration' :: Maybe Text
retiringPrincipal = forall a. Maybe a
Prelude.Nothing,
        $sel:operations:KmsGrantConfiguration' :: [KmsGrantOperation]
operations = forall a. Monoid a => a
Prelude.mempty,
        $sel:granteePrincipal:KmsGrantConfiguration' :: Text
granteePrincipal = Text
pGranteePrincipal_,
        $sel:issuingAccount:KmsGrantConfiguration' :: Text
issuingAccount = Text
pIssuingAccount_
      }

-- | 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>.
kmsGrantConfiguration_constraints :: Lens.Lens' KmsGrantConfiguration (Prelude.Maybe KmsGrantConstraints)
kmsGrantConfiguration_constraints :: Lens' KmsGrantConfiguration (Maybe KmsGrantConstraints)
kmsGrantConfiguration_constraints = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KmsGrantConfiguration' {Maybe KmsGrantConstraints
constraints :: Maybe KmsGrantConstraints
$sel:constraints:KmsGrantConfiguration' :: KmsGrantConfiguration -> Maybe KmsGrantConstraints
constraints} -> Maybe KmsGrantConstraints
constraints) (\s :: KmsGrantConfiguration
s@KmsGrantConfiguration' {} Maybe KmsGrantConstraints
a -> KmsGrantConfiguration
s {$sel:constraints:KmsGrantConfiguration' :: Maybe KmsGrantConstraints
constraints = Maybe KmsGrantConstraints
a} :: KmsGrantConfiguration)

-- | The principal that is given permission to retire the grant by using
-- <https://docs.aws.amazon.com/kms/latest/APIReference/API_RetireGrant.html RetireGrant>
-- operation.
kmsGrantConfiguration_retiringPrincipal :: Lens.Lens' KmsGrantConfiguration (Prelude.Maybe Prelude.Text)
kmsGrantConfiguration_retiringPrincipal :: Lens' KmsGrantConfiguration (Maybe Text)
kmsGrantConfiguration_retiringPrincipal = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KmsGrantConfiguration' {Maybe Text
retiringPrincipal :: Maybe Text
$sel:retiringPrincipal:KmsGrantConfiguration' :: KmsGrantConfiguration -> Maybe Text
retiringPrincipal} -> Maybe Text
retiringPrincipal) (\s :: KmsGrantConfiguration
s@KmsGrantConfiguration' {} Maybe Text
a -> KmsGrantConfiguration
s {$sel:retiringPrincipal:KmsGrantConfiguration' :: Maybe Text
retiringPrincipal = Maybe Text
a} :: KmsGrantConfiguration)

-- | A list of operations that the grant permits.
kmsGrantConfiguration_operations :: Lens.Lens' KmsGrantConfiguration [KmsGrantOperation]
kmsGrantConfiguration_operations :: Lens' KmsGrantConfiguration [KmsGrantOperation]
kmsGrantConfiguration_operations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KmsGrantConfiguration' {[KmsGrantOperation]
operations :: [KmsGrantOperation]
$sel:operations:KmsGrantConfiguration' :: KmsGrantConfiguration -> [KmsGrantOperation]
operations} -> [KmsGrantOperation]
operations) (\s :: KmsGrantConfiguration
s@KmsGrantConfiguration' {} [KmsGrantOperation]
a -> KmsGrantConfiguration
s {$sel:operations:KmsGrantConfiguration' :: [KmsGrantOperation]
operations = [KmsGrantOperation]
a} :: KmsGrantConfiguration) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The principal that is given permission to perform the operations that
-- the grant permits.
kmsGrantConfiguration_granteePrincipal :: Lens.Lens' KmsGrantConfiguration Prelude.Text
kmsGrantConfiguration_granteePrincipal :: Lens' KmsGrantConfiguration Text
kmsGrantConfiguration_granteePrincipal = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KmsGrantConfiguration' {Text
granteePrincipal :: Text
$sel:granteePrincipal:KmsGrantConfiguration' :: KmsGrantConfiguration -> Text
granteePrincipal} -> Text
granteePrincipal) (\s :: KmsGrantConfiguration
s@KmsGrantConfiguration' {} Text
a -> KmsGrantConfiguration
s {$sel:granteePrincipal:KmsGrantConfiguration' :: Text
granteePrincipal = Text
a} :: KmsGrantConfiguration)

-- | The Amazon Web Services account under which the grant was issued. The
-- account is used to propose KMS grants issued by accounts other than the
-- owner of the key.
kmsGrantConfiguration_issuingAccount :: Lens.Lens' KmsGrantConfiguration Prelude.Text
kmsGrantConfiguration_issuingAccount :: Lens' KmsGrantConfiguration Text
kmsGrantConfiguration_issuingAccount = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KmsGrantConfiguration' {Text
issuingAccount :: Text
$sel:issuingAccount:KmsGrantConfiguration' :: KmsGrantConfiguration -> Text
issuingAccount} -> Text
issuingAccount) (\s :: KmsGrantConfiguration
s@KmsGrantConfiguration' {} Text
a -> KmsGrantConfiguration
s {$sel:issuingAccount:KmsGrantConfiguration' :: Text
issuingAccount = Text
a} :: KmsGrantConfiguration)

instance Data.FromJSON KmsGrantConfiguration where
  parseJSON :: Value -> Parser KmsGrantConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"KmsGrantConfiguration"
      ( \Object
x ->
          Maybe KmsGrantConstraints
-> Maybe Text
-> [KmsGrantOperation]
-> Text
-> Text
-> KmsGrantConfiguration
KmsGrantConfiguration'
            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
"constraints")
            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
"retiringPrincipal")
            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
"operations" 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 a
Data..: Key
"granteePrincipal")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"issuingAccount")
      )

instance Prelude.Hashable KmsGrantConfiguration where
  hashWithSalt :: Int -> KmsGrantConfiguration -> Int
hashWithSalt Int
_salt KmsGrantConfiguration' {[KmsGrantOperation]
Maybe Text
Maybe KmsGrantConstraints
Text
issuingAccount :: Text
granteePrincipal :: Text
operations :: [KmsGrantOperation]
retiringPrincipal :: Maybe Text
constraints :: Maybe KmsGrantConstraints
$sel:issuingAccount:KmsGrantConfiguration' :: KmsGrantConfiguration -> Text
$sel:granteePrincipal:KmsGrantConfiguration' :: KmsGrantConfiguration -> Text
$sel:operations:KmsGrantConfiguration' :: KmsGrantConfiguration -> [KmsGrantOperation]
$sel:retiringPrincipal:KmsGrantConfiguration' :: KmsGrantConfiguration -> Maybe Text
$sel:constraints:KmsGrantConfiguration' :: KmsGrantConfiguration -> Maybe KmsGrantConstraints
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe KmsGrantConstraints
constraints
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
retiringPrincipal
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [KmsGrantOperation]
operations
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
granteePrincipal
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
issuingAccount

instance Prelude.NFData KmsGrantConfiguration where
  rnf :: KmsGrantConfiguration -> ()
rnf KmsGrantConfiguration' {[KmsGrantOperation]
Maybe Text
Maybe KmsGrantConstraints
Text
issuingAccount :: Text
granteePrincipal :: Text
operations :: [KmsGrantOperation]
retiringPrincipal :: Maybe Text
constraints :: Maybe KmsGrantConstraints
$sel:issuingAccount:KmsGrantConfiguration' :: KmsGrantConfiguration -> Text
$sel:granteePrincipal:KmsGrantConfiguration' :: KmsGrantConfiguration -> Text
$sel:operations:KmsGrantConfiguration' :: KmsGrantConfiguration -> [KmsGrantOperation]
$sel:retiringPrincipal:KmsGrantConfiguration' :: KmsGrantConfiguration -> Maybe Text
$sel:constraints:KmsGrantConfiguration' :: KmsGrantConfiguration -> Maybe KmsGrantConstraints
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe KmsGrantConstraints
constraints
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
retiringPrincipal
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [KmsGrantOperation]
operations
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
granteePrincipal
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
issuingAccount

instance Data.ToJSON KmsGrantConfiguration where
  toJSON :: KmsGrantConfiguration -> Value
toJSON KmsGrantConfiguration' {[KmsGrantOperation]
Maybe Text
Maybe KmsGrantConstraints
Text
issuingAccount :: Text
granteePrincipal :: Text
operations :: [KmsGrantOperation]
retiringPrincipal :: Maybe Text
constraints :: Maybe KmsGrantConstraints
$sel:issuingAccount:KmsGrantConfiguration' :: KmsGrantConfiguration -> Text
$sel:granteePrincipal:KmsGrantConfiguration' :: KmsGrantConfiguration -> Text
$sel:operations:KmsGrantConfiguration' :: KmsGrantConfiguration -> [KmsGrantOperation]
$sel:retiringPrincipal:KmsGrantConfiguration' :: KmsGrantConfiguration -> Maybe Text
$sel:constraints:KmsGrantConfiguration' :: KmsGrantConfiguration -> Maybe KmsGrantConstraints
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"constraints" 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 KmsGrantConstraints
constraints,
            (Key
"retiringPrincipal" 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 Text
retiringPrincipal,
            forall a. a -> Maybe a
Prelude.Just (Key
"operations" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [KmsGrantOperation]
operations),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"granteePrincipal" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
granteePrincipal),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"issuingAccount" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
issuingAccount)
          ]
      )