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

import Amazonka.AccessAnalyzer.Types.KmsGrantConstraints
import Amazonka.AccessAnalyzer.Types.KmsGrantOperation
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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'
  { -- | 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,
    -- | 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 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,
    -- | A list of operations that the grant permits.
    KmsGrantConfiguration -> [KmsGrantOperation]
operations :: [KmsGrantOperation]
  }
  deriving (KmsGrantConfiguration -> KmsGrantConfiguration -> Bool
(KmsGrantConfiguration -> KmsGrantConfiguration -> Bool)
-> (KmsGrantConfiguration -> KmsGrantConfiguration -> Bool)
-> Eq KmsGrantConfiguration
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]
(Int -> ReadS KmsGrantConfiguration)
-> ReadS [KmsGrantConfiguration]
-> ReadPrec KmsGrantConfiguration
-> ReadPrec [KmsGrantConfiguration]
-> Read 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
(Int -> KmsGrantConfiguration -> ShowS)
-> (KmsGrantConfiguration -> String)
-> ([KmsGrantConfiguration] -> ShowS)
-> Show KmsGrantConfiguration
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. KmsGrantConfiguration -> Rep KmsGrantConfiguration x)
-> (forall x. Rep KmsGrantConfiguration x -> KmsGrantConfiguration)
-> Generic KmsGrantConfiguration
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:
--
-- '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.
--
-- '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>.
--
-- '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.
--
-- 'operations', 'kmsGrantConfiguration_operations' - A list of operations that the grant permits.
newKmsGrantConfiguration ::
  -- | 'granteePrincipal'
  Prelude.Text ->
  -- | 'issuingAccount'
  Prelude.Text ->
  KmsGrantConfiguration
newKmsGrantConfiguration :: Text -> Text -> KmsGrantConfiguration
newKmsGrantConfiguration
  Text
pGranteePrincipal_
  Text
pIssuingAccount_ =
    KmsGrantConfiguration' :: Maybe Text
-> Maybe KmsGrantConstraints
-> Text
-> Text
-> [KmsGrantOperation]
-> KmsGrantConfiguration
KmsGrantConfiguration'
      { $sel:retiringPrincipal:KmsGrantConfiguration' :: Maybe Text
retiringPrincipal =
          Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:constraints:KmsGrantConfiguration' :: Maybe KmsGrantConstraints
constraints = Maybe KmsGrantConstraints
forall a. Maybe a
Prelude.Nothing,
        $sel:granteePrincipal:KmsGrantConfiguration' :: Text
granteePrincipal = Text
pGranteePrincipal_,
        $sel:issuingAccount:KmsGrantConfiguration' :: Text
issuingAccount = Text
pIssuingAccount_,
        $sel:operations:KmsGrantConfiguration' :: [KmsGrantOperation]
operations = [KmsGrantOperation]
forall a. Monoid a => a
Prelude.mempty
      }

-- | 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 :: (Maybe Text -> f (Maybe Text))
-> KmsGrantConfiguration -> f KmsGrantConfiguration
kmsGrantConfiguration_retiringPrincipal = (KmsGrantConfiguration -> Maybe Text)
-> (KmsGrantConfiguration -> Maybe Text -> KmsGrantConfiguration)
-> Lens
     KmsGrantConfiguration
     KmsGrantConfiguration
     (Maybe Text)
     (Maybe Text)
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)

-- | 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 :: (Maybe KmsGrantConstraints -> f (Maybe KmsGrantConstraints))
-> KmsGrantConfiguration -> f KmsGrantConfiguration
kmsGrantConfiguration_constraints = (KmsGrantConfiguration -> Maybe KmsGrantConstraints)
-> (KmsGrantConfiguration
    -> Maybe KmsGrantConstraints -> KmsGrantConfiguration)
-> Lens
     KmsGrantConfiguration
     KmsGrantConfiguration
     (Maybe KmsGrantConstraints)
     (Maybe KmsGrantConstraints)
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 perform the operations that
-- the grant permits.
kmsGrantConfiguration_granteePrincipal :: Lens.Lens' KmsGrantConfiguration Prelude.Text
kmsGrantConfiguration_granteePrincipal :: (Text -> f Text)
-> KmsGrantConfiguration -> f KmsGrantConfiguration
kmsGrantConfiguration_granteePrincipal = (KmsGrantConfiguration -> Text)
-> (KmsGrantConfiguration -> Text -> KmsGrantConfiguration)
-> Lens KmsGrantConfiguration KmsGrantConfiguration Text Text
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 :: (Text -> f Text)
-> KmsGrantConfiguration -> f KmsGrantConfiguration
kmsGrantConfiguration_issuingAccount = (KmsGrantConfiguration -> Text)
-> (KmsGrantConfiguration -> Text -> KmsGrantConfiguration)
-> Lens KmsGrantConfiguration KmsGrantConfiguration Text Text
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)

-- | A list of operations that the grant permits.
kmsGrantConfiguration_operations :: Lens.Lens' KmsGrantConfiguration [KmsGrantOperation]
kmsGrantConfiguration_operations :: ([KmsGrantOperation] -> f [KmsGrantOperation])
-> KmsGrantConfiguration -> f KmsGrantConfiguration
kmsGrantConfiguration_operations = (KmsGrantConfiguration -> [KmsGrantOperation])
-> (KmsGrantConfiguration
    -> [KmsGrantOperation] -> KmsGrantConfiguration)
-> Lens
     KmsGrantConfiguration
     KmsGrantConfiguration
     [KmsGrantOperation]
     [KmsGrantOperation]
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) (([KmsGrantOperation] -> f [KmsGrantOperation])
 -> KmsGrantConfiguration -> f KmsGrantConfiguration)
-> (([KmsGrantOperation] -> f [KmsGrantOperation])
    -> [KmsGrantOperation] -> f [KmsGrantOperation])
-> ([KmsGrantOperation] -> f [KmsGrantOperation])
-> KmsGrantConfiguration
-> f KmsGrantConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([KmsGrantOperation] -> f [KmsGrantOperation])
-> [KmsGrantOperation] -> f [KmsGrantOperation]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON KmsGrantConfiguration where
  parseJSON :: Value -> Parser KmsGrantConfiguration
parseJSON =
    String
-> (Object -> Parser KmsGrantConfiguration)
-> Value
-> Parser KmsGrantConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"KmsGrantConfiguration"
      ( \Object
x ->
          Maybe Text
-> Maybe KmsGrantConstraints
-> Text
-> Text
-> [KmsGrantOperation]
-> KmsGrantConfiguration
KmsGrantConfiguration'
            (Maybe Text
 -> Maybe KmsGrantConstraints
 -> Text
 -> Text
 -> [KmsGrantOperation]
 -> KmsGrantConfiguration)
-> Parser (Maybe Text)
-> Parser
     (Maybe KmsGrantConstraints
      -> Text -> Text -> [KmsGrantOperation] -> KmsGrantConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"retiringPrincipal")
            Parser
  (Maybe KmsGrantConstraints
   -> Text -> Text -> [KmsGrantOperation] -> KmsGrantConfiguration)
-> Parser (Maybe KmsGrantConstraints)
-> Parser
     (Text -> Text -> [KmsGrantOperation] -> KmsGrantConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe KmsGrantConstraints)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"constraints")
            Parser
  (Text -> Text -> [KmsGrantOperation] -> KmsGrantConfiguration)
-> Parser Text
-> Parser (Text -> [KmsGrantOperation] -> KmsGrantConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"granteePrincipal")
            Parser (Text -> [KmsGrantOperation] -> KmsGrantConfiguration)
-> Parser Text
-> Parser ([KmsGrantOperation] -> KmsGrantConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"issuingAccount")
            Parser ([KmsGrantOperation] -> KmsGrantConfiguration)
-> Parser [KmsGrantOperation] -> Parser KmsGrantConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [KmsGrantOperation])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"operations" Parser (Maybe [KmsGrantOperation])
-> [KmsGrantOperation] -> Parser [KmsGrantOperation]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [KmsGrantOperation]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable KmsGrantConfiguration

instance Prelude.NFData KmsGrantConfiguration

instance Core.ToJSON KmsGrantConfiguration where
  toJSON :: KmsGrantConfiguration -> Value
toJSON KmsGrantConfiguration' {[KmsGrantOperation]
Maybe Text
Maybe KmsGrantConstraints
Text
operations :: [KmsGrantOperation]
issuingAccount :: Text
granteePrincipal :: Text
constraints :: Maybe KmsGrantConstraints
retiringPrincipal :: Maybe Text
$sel:operations:KmsGrantConfiguration' :: KmsGrantConfiguration -> [KmsGrantOperation]
$sel:issuingAccount:KmsGrantConfiguration' :: KmsGrantConfiguration -> Text
$sel:granteePrincipal:KmsGrantConfiguration' :: KmsGrantConfiguration -> Text
$sel:constraints:KmsGrantConfiguration' :: KmsGrantConfiguration -> Maybe KmsGrantConstraints
$sel:retiringPrincipal:KmsGrantConfiguration' :: KmsGrantConfiguration -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"retiringPrincipal" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
retiringPrincipal,
            (Text
"constraints" Text -> KmsGrantConstraints -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (KmsGrantConstraints -> Pair)
-> Maybe KmsGrantConstraints -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe KmsGrantConstraints
constraints,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"granteePrincipal" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
granteePrincipal),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"issuingAccount" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
issuingAccount),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"operations" Text -> [KmsGrantOperation] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [KmsGrantOperation]
operations)
          ]
      )