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

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

-- | 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
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]
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
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. 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'
    { $sel:grants:KmsKeyConfiguration' :: Maybe [KmsGrantConfiguration]
grants = forall a. Maybe a
Prelude.Nothing,
      $sel:keyPolicies:KmsKeyConfiguration' :: Maybe (HashMap Text Text)
keyPolicies = 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 :: Lens' KmsKeyConfiguration (Maybe [KmsGrantConfiguration])
kmsKeyConfiguration_grants = 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) 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

-- | 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 :: Lens' KmsKeyConfiguration (Maybe (HashMap Text Text))
kmsKeyConfiguration_keyPolicies = 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) 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 KmsKeyConfiguration where
  parseJSON :: Value -> Parser KmsKeyConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"KmsKeyConfiguration"
      ( \Object
x ->
          Maybe [KmsGrantConfiguration]
-> Maybe (HashMap Text Text) -> KmsKeyConfiguration
KmsKeyConfiguration'
            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
"grants" 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
"keyPolicies" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable KmsKeyConfiguration where
  hashWithSalt :: Int -> KmsKeyConfiguration -> Int
hashWithSalt Int
_salt 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]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [KmsGrantConfiguration]
grants
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
keyPolicies

instance Prelude.NFData KmsKeyConfiguration where
  rnf :: KmsKeyConfiguration -> ()
rnf 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]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [KmsGrantConfiguration]
grants
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
keyPolicies

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"grants" 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 [KmsGrantConfiguration]
grants,
            (Key
"keyPolicies" 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)
keyPolicies
          ]
      )