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

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

-- | The proposed access control configuration for an Amazon RDS DB snapshot.
-- You can propose a configuration for a new Amazon RDS DB snapshot or an
-- Amazon RDS DB snapshot that you own by specifying the
-- @RdsDbSnapshotAttributeValue@ and optional KMS encryption key. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_ModifyDBSnapshotAttribute.html ModifyDBSnapshotAttribute>.
--
-- /See:/ 'newRdsDbSnapshotConfiguration' smart constructor.
data RdsDbSnapshotConfiguration = RdsDbSnapshotConfiguration'
  { -- | The names and values of manual DB snapshot attributes. Manual DB
    -- snapshot attributes are used to authorize other Amazon Web Services
    -- accounts to restore a manual DB snapshot. The only valid value for
    -- @attributeName@ for the attribute map is restore.
    RdsDbSnapshotConfiguration
-> Maybe (HashMap Text RdsDbSnapshotAttributeValue)
attributes :: Prelude.Maybe (Prelude.HashMap Prelude.Text RdsDbSnapshotAttributeValue),
    -- | The KMS key identifier for an encrypted Amazon RDS DB snapshot. The KMS
    -- key identifier is the key ARN, key ID, alias ARN, or alias name for the
    -- KMS key.
    --
    -- -   If the configuration is for an existing Amazon RDS DB snapshot and
    --     you do not specify the @kmsKeyId@, or you specify an empty string,
    --     then the access preview uses the existing @kmsKeyId@ of the
    --     snapshot.
    --
    -- -   If the access preview is for a new resource and you do not specify
    --     the specify the @kmsKeyId@, then the access preview considers the
    --     snapshot as unencrypted.
    RdsDbSnapshotConfiguration -> Maybe Text
kmsKeyId :: Prelude.Maybe Prelude.Text
  }
  deriving (RdsDbSnapshotConfiguration -> RdsDbSnapshotConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RdsDbSnapshotConfiguration -> RdsDbSnapshotConfiguration -> Bool
$c/= :: RdsDbSnapshotConfiguration -> RdsDbSnapshotConfiguration -> Bool
== :: RdsDbSnapshotConfiguration -> RdsDbSnapshotConfiguration -> Bool
$c== :: RdsDbSnapshotConfiguration -> RdsDbSnapshotConfiguration -> Bool
Prelude.Eq, ReadPrec [RdsDbSnapshotConfiguration]
ReadPrec RdsDbSnapshotConfiguration
Int -> ReadS RdsDbSnapshotConfiguration
ReadS [RdsDbSnapshotConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RdsDbSnapshotConfiguration]
$creadListPrec :: ReadPrec [RdsDbSnapshotConfiguration]
readPrec :: ReadPrec RdsDbSnapshotConfiguration
$creadPrec :: ReadPrec RdsDbSnapshotConfiguration
readList :: ReadS [RdsDbSnapshotConfiguration]
$creadList :: ReadS [RdsDbSnapshotConfiguration]
readsPrec :: Int -> ReadS RdsDbSnapshotConfiguration
$creadsPrec :: Int -> ReadS RdsDbSnapshotConfiguration
Prelude.Read, Int -> RdsDbSnapshotConfiguration -> ShowS
[RdsDbSnapshotConfiguration] -> ShowS
RdsDbSnapshotConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RdsDbSnapshotConfiguration] -> ShowS
$cshowList :: [RdsDbSnapshotConfiguration] -> ShowS
show :: RdsDbSnapshotConfiguration -> String
$cshow :: RdsDbSnapshotConfiguration -> String
showsPrec :: Int -> RdsDbSnapshotConfiguration -> ShowS
$cshowsPrec :: Int -> RdsDbSnapshotConfiguration -> ShowS
Prelude.Show, forall x.
Rep RdsDbSnapshotConfiguration x -> RdsDbSnapshotConfiguration
forall x.
RdsDbSnapshotConfiguration -> Rep RdsDbSnapshotConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep RdsDbSnapshotConfiguration x -> RdsDbSnapshotConfiguration
$cfrom :: forall x.
RdsDbSnapshotConfiguration -> Rep RdsDbSnapshotConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'RdsDbSnapshotConfiguration' 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:
--
-- 'attributes', 'rdsDbSnapshotConfiguration_attributes' - The names and values of manual DB snapshot attributes. Manual DB
-- snapshot attributes are used to authorize other Amazon Web Services
-- accounts to restore a manual DB snapshot. The only valid value for
-- @attributeName@ for the attribute map is restore.
--
-- 'kmsKeyId', 'rdsDbSnapshotConfiguration_kmsKeyId' - The KMS key identifier for an encrypted Amazon RDS DB snapshot. The KMS
-- key identifier is the key ARN, key ID, alias ARN, or alias name for the
-- KMS key.
--
-- -   If the configuration is for an existing Amazon RDS DB snapshot and
--     you do not specify the @kmsKeyId@, or you specify an empty string,
--     then the access preview uses the existing @kmsKeyId@ of the
--     snapshot.
--
-- -   If the access preview is for a new resource and you do not specify
--     the specify the @kmsKeyId@, then the access preview considers the
--     snapshot as unencrypted.
newRdsDbSnapshotConfiguration ::
  RdsDbSnapshotConfiguration
newRdsDbSnapshotConfiguration :: RdsDbSnapshotConfiguration
newRdsDbSnapshotConfiguration =
  RdsDbSnapshotConfiguration'
    { $sel:attributes:RdsDbSnapshotConfiguration' :: Maybe (HashMap Text RdsDbSnapshotAttributeValue)
attributes =
        forall a. Maybe a
Prelude.Nothing,
      $sel:kmsKeyId:RdsDbSnapshotConfiguration' :: Maybe Text
kmsKeyId = forall a. Maybe a
Prelude.Nothing
    }

-- | The names and values of manual DB snapshot attributes. Manual DB
-- snapshot attributes are used to authorize other Amazon Web Services
-- accounts to restore a manual DB snapshot. The only valid value for
-- @attributeName@ for the attribute map is restore.
rdsDbSnapshotConfiguration_attributes :: Lens.Lens' RdsDbSnapshotConfiguration (Prelude.Maybe (Prelude.HashMap Prelude.Text RdsDbSnapshotAttributeValue))
rdsDbSnapshotConfiguration_attributes :: Lens'
  RdsDbSnapshotConfiguration
  (Maybe (HashMap Text RdsDbSnapshotAttributeValue))
rdsDbSnapshotConfiguration_attributes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RdsDbSnapshotConfiguration' {Maybe (HashMap Text RdsDbSnapshotAttributeValue)
attributes :: Maybe (HashMap Text RdsDbSnapshotAttributeValue)
$sel:attributes:RdsDbSnapshotConfiguration' :: RdsDbSnapshotConfiguration
-> Maybe (HashMap Text RdsDbSnapshotAttributeValue)
attributes} -> Maybe (HashMap Text RdsDbSnapshotAttributeValue)
attributes) (\s :: RdsDbSnapshotConfiguration
s@RdsDbSnapshotConfiguration' {} Maybe (HashMap Text RdsDbSnapshotAttributeValue)
a -> RdsDbSnapshotConfiguration
s {$sel:attributes:RdsDbSnapshotConfiguration' :: Maybe (HashMap Text RdsDbSnapshotAttributeValue)
attributes = Maybe (HashMap Text RdsDbSnapshotAttributeValue)
a} :: RdsDbSnapshotConfiguration) 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

-- | The KMS key identifier for an encrypted Amazon RDS DB snapshot. The KMS
-- key identifier is the key ARN, key ID, alias ARN, or alias name for the
-- KMS key.
--
-- -   If the configuration is for an existing Amazon RDS DB snapshot and
--     you do not specify the @kmsKeyId@, or you specify an empty string,
--     then the access preview uses the existing @kmsKeyId@ of the
--     snapshot.
--
-- -   If the access preview is for a new resource and you do not specify
--     the specify the @kmsKeyId@, then the access preview considers the
--     snapshot as unencrypted.
rdsDbSnapshotConfiguration_kmsKeyId :: Lens.Lens' RdsDbSnapshotConfiguration (Prelude.Maybe Prelude.Text)
rdsDbSnapshotConfiguration_kmsKeyId :: Lens' RdsDbSnapshotConfiguration (Maybe Text)
rdsDbSnapshotConfiguration_kmsKeyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RdsDbSnapshotConfiguration' {Maybe Text
kmsKeyId :: Maybe Text
$sel:kmsKeyId:RdsDbSnapshotConfiguration' :: RdsDbSnapshotConfiguration -> Maybe Text
kmsKeyId} -> Maybe Text
kmsKeyId) (\s :: RdsDbSnapshotConfiguration
s@RdsDbSnapshotConfiguration' {} Maybe Text
a -> RdsDbSnapshotConfiguration
s {$sel:kmsKeyId:RdsDbSnapshotConfiguration' :: Maybe Text
kmsKeyId = Maybe Text
a} :: RdsDbSnapshotConfiguration)

instance Data.FromJSON RdsDbSnapshotConfiguration where
  parseJSON :: Value -> Parser RdsDbSnapshotConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RdsDbSnapshotConfiguration"
      ( \Object
x ->
          Maybe (HashMap Text RdsDbSnapshotAttributeValue)
-> Maybe Text -> RdsDbSnapshotConfiguration
RdsDbSnapshotConfiguration'
            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
"attributes" 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
"kmsKeyId")
      )

instance Prelude.Hashable RdsDbSnapshotConfiguration where
  hashWithSalt :: Int -> RdsDbSnapshotConfiguration -> Int
hashWithSalt Int
_salt RdsDbSnapshotConfiguration' {Maybe Text
Maybe (HashMap Text RdsDbSnapshotAttributeValue)
kmsKeyId :: Maybe Text
attributes :: Maybe (HashMap Text RdsDbSnapshotAttributeValue)
$sel:kmsKeyId:RdsDbSnapshotConfiguration' :: RdsDbSnapshotConfiguration -> Maybe Text
$sel:attributes:RdsDbSnapshotConfiguration' :: RdsDbSnapshotConfiguration
-> Maybe (HashMap Text RdsDbSnapshotAttributeValue)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text RdsDbSnapshotAttributeValue)
attributes
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
kmsKeyId

instance Prelude.NFData RdsDbSnapshotConfiguration where
  rnf :: RdsDbSnapshotConfiguration -> ()
rnf RdsDbSnapshotConfiguration' {Maybe Text
Maybe (HashMap Text RdsDbSnapshotAttributeValue)
kmsKeyId :: Maybe Text
attributes :: Maybe (HashMap Text RdsDbSnapshotAttributeValue)
$sel:kmsKeyId:RdsDbSnapshotConfiguration' :: RdsDbSnapshotConfiguration -> Maybe Text
$sel:attributes:RdsDbSnapshotConfiguration' :: RdsDbSnapshotConfiguration
-> Maybe (HashMap Text RdsDbSnapshotAttributeValue)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text RdsDbSnapshotAttributeValue)
attributes
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
kmsKeyId

instance Data.ToJSON RdsDbSnapshotConfiguration where
  toJSON :: RdsDbSnapshotConfiguration -> Value
toJSON RdsDbSnapshotConfiguration' {Maybe Text
Maybe (HashMap Text RdsDbSnapshotAttributeValue)
kmsKeyId :: Maybe Text
attributes :: Maybe (HashMap Text RdsDbSnapshotAttributeValue)
$sel:kmsKeyId:RdsDbSnapshotConfiguration' :: RdsDbSnapshotConfiguration -> Maybe Text
$sel:attributes:RdsDbSnapshotConfiguration' :: RdsDbSnapshotConfiguration
-> Maybe (HashMap Text RdsDbSnapshotAttributeValue)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"attributes" 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 RdsDbSnapshotAttributeValue)
attributes,
            (Key
"kmsKeyId" 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
kmsKeyId
          ]
      )