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

import Amazonka.AccessAnalyzer.Types.KmsGrantConfiguration
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Proposed access control configuration for a KMS key. You can propose a
-- configuration for a new KMS key or an existing KMS key that you own by
-- specifying the key policy and KMS grant configuration. If the
-- configuration is for an existing key and you do not specify the key
-- policy, the access preview uses the existing policy for the key. If the
-- access preview is for a new resource and you do not specify the key
-- policy, then the access preview uses the default key policy. The
-- proposed key policy cannot be an empty string. For more information, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default Default key policy>.
-- For more information about key policy limits, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/resource-limits.html Resource quotas>.
--
-- /See:/ 'newKmsKeyConfiguration' smart constructor.
data KmsKeyConfiguration = KmsKeyConfiguration'
  { -- | A list of proposed grant configurations for the KMS key. If the proposed
    -- grant configuration is for an existing key, the access preview uses the
    -- proposed list of grant configurations in place of the existing grants.
    -- Otherwise, the access preview uses the existing grants for the key.
    KmsKeyConfiguration -> Maybe [KmsGrantConfiguration]
grants :: Prelude.Maybe [KmsGrantConfiguration],
    -- | Resource policy configuration for the KMS key. The only valid value for
    -- the name of the key policy is @default@. For more information, see
    -- <https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default Default key policy>.
    KmsKeyConfiguration -> Maybe (HashMap Text Text)
keyPolicies :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text)
  }
  deriving (KmsKeyConfiguration -> KmsKeyConfiguration -> Bool
(KmsKeyConfiguration -> KmsKeyConfiguration -> Bool)
-> (KmsKeyConfiguration -> KmsKeyConfiguration -> Bool)
-> Eq KmsKeyConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: KmsKeyConfiguration -> KmsKeyConfiguration -> Bool
$c/= :: KmsKeyConfiguration -> KmsKeyConfiguration -> Bool
== :: KmsKeyConfiguration -> KmsKeyConfiguration -> Bool
$c== :: KmsKeyConfiguration -> KmsKeyConfiguration -> Bool
Prelude.Eq, ReadPrec [KmsKeyConfiguration]
ReadPrec KmsKeyConfiguration
Int -> ReadS KmsKeyConfiguration
ReadS [KmsKeyConfiguration]
(Int -> ReadS KmsKeyConfiguration)
-> ReadS [KmsKeyConfiguration]
-> ReadPrec KmsKeyConfiguration
-> ReadPrec [KmsKeyConfiguration]
-> Read KmsKeyConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [KmsKeyConfiguration]
$creadListPrec :: ReadPrec [KmsKeyConfiguration]
readPrec :: ReadPrec KmsKeyConfiguration
$creadPrec :: ReadPrec KmsKeyConfiguration
readList :: ReadS [KmsKeyConfiguration]
$creadList :: ReadS [KmsKeyConfiguration]
readsPrec :: Int -> ReadS KmsKeyConfiguration
$creadsPrec :: Int -> ReadS KmsKeyConfiguration
Prelude.Read, Int -> KmsKeyConfiguration -> ShowS
[KmsKeyConfiguration] -> ShowS
KmsKeyConfiguration -> String
(Int -> KmsKeyConfiguration -> ShowS)
-> (KmsKeyConfiguration -> String)
-> ([KmsKeyConfiguration] -> ShowS)
-> Show KmsKeyConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [KmsKeyConfiguration] -> ShowS
$cshowList :: [KmsKeyConfiguration] -> ShowS
show :: KmsKeyConfiguration -> String
$cshow :: KmsKeyConfiguration -> String
showsPrec :: Int -> KmsKeyConfiguration -> ShowS
$cshowsPrec :: Int -> KmsKeyConfiguration -> ShowS
Prelude.Show, (forall x. KmsKeyConfiguration -> Rep KmsKeyConfiguration x)
-> (forall x. Rep KmsKeyConfiguration x -> KmsKeyConfiguration)
-> Generic KmsKeyConfiguration
forall x. Rep KmsKeyConfiguration x -> KmsKeyConfiguration
forall x. KmsKeyConfiguration -> Rep KmsKeyConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep KmsKeyConfiguration x -> KmsKeyConfiguration
$cfrom :: forall x. KmsKeyConfiguration -> Rep KmsKeyConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'KmsKeyConfiguration' 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:
--
-- 'grants', 'kmsKeyConfiguration_grants' - A list of proposed grant configurations for the KMS key. If the proposed
-- grant configuration is for an existing key, the access preview uses the
-- proposed list of grant configurations in place of the existing grants.
-- Otherwise, the access preview uses the existing grants for the key.
--
-- 'keyPolicies', 'kmsKeyConfiguration_keyPolicies' - Resource policy configuration for the KMS key. The only valid value for
-- the name of the key policy is @default@. For more information, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default Default key policy>.
newKmsKeyConfiguration ::
  KmsKeyConfiguration
newKmsKeyConfiguration :: KmsKeyConfiguration
newKmsKeyConfiguration =
  KmsKeyConfiguration' :: Maybe [KmsGrantConfiguration]
-> Maybe (HashMap Text Text) -> KmsKeyConfiguration
KmsKeyConfiguration'
    { $sel:grants:KmsKeyConfiguration' :: Maybe [KmsGrantConfiguration]
grants = Maybe [KmsGrantConfiguration]
forall a. Maybe a
Prelude.Nothing,
      $sel:keyPolicies:KmsKeyConfiguration' :: Maybe (HashMap Text Text)
keyPolicies = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing
    }

-- | A list of proposed grant configurations for the KMS key. If the proposed
-- grant configuration is for an existing key, the access preview uses the
-- proposed list of grant configurations in place of the existing grants.
-- Otherwise, the access preview uses the existing grants for the key.
kmsKeyConfiguration_grants :: Lens.Lens' KmsKeyConfiguration (Prelude.Maybe [KmsGrantConfiguration])
kmsKeyConfiguration_grants :: (Maybe [KmsGrantConfiguration]
 -> f (Maybe [KmsGrantConfiguration]))
-> KmsKeyConfiguration -> f KmsKeyConfiguration
kmsKeyConfiguration_grants = (KmsKeyConfiguration -> Maybe [KmsGrantConfiguration])
-> (KmsKeyConfiguration
    -> Maybe [KmsGrantConfiguration] -> KmsKeyConfiguration)
-> Lens
     KmsKeyConfiguration
     KmsKeyConfiguration
     (Maybe [KmsGrantConfiguration])
     (Maybe [KmsGrantConfiguration])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KmsKeyConfiguration' {Maybe [KmsGrantConfiguration]
grants :: Maybe [KmsGrantConfiguration]
$sel:grants:KmsKeyConfiguration' :: KmsKeyConfiguration -> Maybe [KmsGrantConfiguration]
grants} -> Maybe [KmsGrantConfiguration]
grants) (\s :: KmsKeyConfiguration
s@KmsKeyConfiguration' {} Maybe [KmsGrantConfiguration]
a -> KmsKeyConfiguration
s {$sel:grants:KmsKeyConfiguration' :: Maybe [KmsGrantConfiguration]
grants = Maybe [KmsGrantConfiguration]
a} :: KmsKeyConfiguration) ((Maybe [KmsGrantConfiguration]
  -> f (Maybe [KmsGrantConfiguration]))
 -> KmsKeyConfiguration -> f KmsKeyConfiguration)
-> ((Maybe [KmsGrantConfiguration]
     -> f (Maybe [KmsGrantConfiguration]))
    -> Maybe [KmsGrantConfiguration]
    -> f (Maybe [KmsGrantConfiguration]))
-> (Maybe [KmsGrantConfiguration]
    -> f (Maybe [KmsGrantConfiguration]))
-> KmsKeyConfiguration
-> f KmsKeyConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [KmsGrantConfiguration]
  [KmsGrantConfiguration]
  [KmsGrantConfiguration]
  [KmsGrantConfiguration]
-> Iso
     (Maybe [KmsGrantConfiguration])
     (Maybe [KmsGrantConfiguration])
     (Maybe [KmsGrantConfiguration])
     (Maybe [KmsGrantConfiguration])
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
  [KmsGrantConfiguration]
  [KmsGrantConfiguration]
  [KmsGrantConfiguration]
  [KmsGrantConfiguration]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Resource policy configuration for the KMS key. The only valid value for
-- the name of the key policy is @default@. For more information, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default Default key policy>.
kmsKeyConfiguration_keyPolicies :: Lens.Lens' KmsKeyConfiguration (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
kmsKeyConfiguration_keyPolicies :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> KmsKeyConfiguration -> f KmsKeyConfiguration
kmsKeyConfiguration_keyPolicies = (KmsKeyConfiguration -> Maybe (HashMap Text Text))
-> (KmsKeyConfiguration
    -> Maybe (HashMap Text Text) -> KmsKeyConfiguration)
-> Lens
     KmsKeyConfiguration
     KmsKeyConfiguration
     (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 (\KmsKeyConfiguration' {Maybe (HashMap Text Text)
keyPolicies :: Maybe (HashMap Text Text)
$sel:keyPolicies:KmsKeyConfiguration' :: KmsKeyConfiguration -> Maybe (HashMap Text Text)
keyPolicies} -> Maybe (HashMap Text Text)
keyPolicies) (\s :: KmsKeyConfiguration
s@KmsKeyConfiguration' {} Maybe (HashMap Text Text)
a -> KmsKeyConfiguration
s {$sel:keyPolicies:KmsKeyConfiguration' :: Maybe (HashMap Text Text)
keyPolicies = Maybe (HashMap Text Text)
a} :: KmsKeyConfiguration) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> KmsKeyConfiguration -> f KmsKeyConfiguration)
-> ((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)))
-> KmsKeyConfiguration
-> f KmsKeyConfiguration
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 KmsKeyConfiguration where
  parseJSON :: Value -> Parser KmsKeyConfiguration
parseJSON =
    String
-> (Object -> Parser KmsKeyConfiguration)
-> Value
-> Parser KmsKeyConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"KmsKeyConfiguration"
      ( \Object
x ->
          Maybe [KmsGrantConfiguration]
-> Maybe (HashMap Text Text) -> KmsKeyConfiguration
KmsKeyConfiguration'
            (Maybe [KmsGrantConfiguration]
 -> Maybe (HashMap Text Text) -> KmsKeyConfiguration)
-> Parser (Maybe [KmsGrantConfiguration])
-> Parser (Maybe (HashMap Text Text) -> KmsKeyConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [KmsGrantConfiguration]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"grants" Parser (Maybe (Maybe [KmsGrantConfiguration]))
-> Maybe [KmsGrantConfiguration]
-> Parser (Maybe [KmsGrantConfiguration])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [KmsGrantConfiguration]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe (HashMap Text Text) -> KmsKeyConfiguration)
-> Parser (Maybe (HashMap Text Text)) -> Parser KmsKeyConfiguration
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
"keyPolicies" 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 KmsKeyConfiguration

instance Prelude.NFData KmsKeyConfiguration

instance Core.ToJSON KmsKeyConfiguration where
  toJSON :: KmsKeyConfiguration -> Value
toJSON KmsKeyConfiguration' {Maybe [KmsGrantConfiguration]
Maybe (HashMap Text Text)
keyPolicies :: Maybe (HashMap Text Text)
grants :: Maybe [KmsGrantConfiguration]
$sel:keyPolicies:KmsKeyConfiguration' :: KmsKeyConfiguration -> Maybe (HashMap Text Text)
$sel:grants:KmsKeyConfiguration' :: KmsKeyConfiguration -> Maybe [KmsGrantConfiguration]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"grants" Text -> [KmsGrantConfiguration] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([KmsGrantConfiguration] -> Pair)
-> Maybe [KmsGrantConfiguration] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [KmsGrantConfiguration]
grants,
            (Text
"keyPolicies" 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)
keyPolicies
          ]
      )