{-# 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.DLM.Types.EncryptionConfiguration
-- 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.DLM.Types.EncryptionConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies the encryption settings for shared snapshots that are copied
-- across Regions.
--
-- /See:/ 'newEncryptionConfiguration' smart constructor.
data EncryptionConfiguration = EncryptionConfiguration'
  { -- | The Amazon Resource Name (ARN) of the KMS key to use for EBS encryption.
    -- If this parameter is not specified, the default KMS key for the account
    -- is used.
    EncryptionConfiguration -> Maybe Text
cmkArn :: Prelude.Maybe Prelude.Text,
    -- | To encrypt a copy of an unencrypted snapshot when encryption by default
    -- is not enabled, enable encryption using this parameter. Copies of
    -- encrypted snapshots are encrypted, even if this parameter is false or
    -- when encryption by default is not enabled.
    EncryptionConfiguration -> Bool
encrypted :: Prelude.Bool
  }
  deriving (EncryptionConfiguration -> EncryptionConfiguration -> Bool
(EncryptionConfiguration -> EncryptionConfiguration -> Bool)
-> (EncryptionConfiguration -> EncryptionConfiguration -> Bool)
-> Eq EncryptionConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EncryptionConfiguration -> EncryptionConfiguration -> Bool
$c/= :: EncryptionConfiguration -> EncryptionConfiguration -> Bool
== :: EncryptionConfiguration -> EncryptionConfiguration -> Bool
$c== :: EncryptionConfiguration -> EncryptionConfiguration -> Bool
Prelude.Eq, ReadPrec [EncryptionConfiguration]
ReadPrec EncryptionConfiguration
Int -> ReadS EncryptionConfiguration
ReadS [EncryptionConfiguration]
(Int -> ReadS EncryptionConfiguration)
-> ReadS [EncryptionConfiguration]
-> ReadPrec EncryptionConfiguration
-> ReadPrec [EncryptionConfiguration]
-> Read EncryptionConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EncryptionConfiguration]
$creadListPrec :: ReadPrec [EncryptionConfiguration]
readPrec :: ReadPrec EncryptionConfiguration
$creadPrec :: ReadPrec EncryptionConfiguration
readList :: ReadS [EncryptionConfiguration]
$creadList :: ReadS [EncryptionConfiguration]
readsPrec :: Int -> ReadS EncryptionConfiguration
$creadsPrec :: Int -> ReadS EncryptionConfiguration
Prelude.Read, Int -> EncryptionConfiguration -> ShowS
[EncryptionConfiguration] -> ShowS
EncryptionConfiguration -> String
(Int -> EncryptionConfiguration -> ShowS)
-> (EncryptionConfiguration -> String)
-> ([EncryptionConfiguration] -> ShowS)
-> Show EncryptionConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EncryptionConfiguration] -> ShowS
$cshowList :: [EncryptionConfiguration] -> ShowS
show :: EncryptionConfiguration -> String
$cshow :: EncryptionConfiguration -> String
showsPrec :: Int -> EncryptionConfiguration -> ShowS
$cshowsPrec :: Int -> EncryptionConfiguration -> ShowS
Prelude.Show, (forall x.
 EncryptionConfiguration -> Rep EncryptionConfiguration x)
-> (forall x.
    Rep EncryptionConfiguration x -> EncryptionConfiguration)
-> Generic EncryptionConfiguration
forall x. Rep EncryptionConfiguration x -> EncryptionConfiguration
forall x. EncryptionConfiguration -> Rep EncryptionConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EncryptionConfiguration x -> EncryptionConfiguration
$cfrom :: forall x. EncryptionConfiguration -> Rep EncryptionConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'EncryptionConfiguration' 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:
--
-- 'cmkArn', 'encryptionConfiguration_cmkArn' - The Amazon Resource Name (ARN) of the KMS key to use for EBS encryption.
-- If this parameter is not specified, the default KMS key for the account
-- is used.
--
-- 'encrypted', 'encryptionConfiguration_encrypted' - To encrypt a copy of an unencrypted snapshot when encryption by default
-- is not enabled, enable encryption using this parameter. Copies of
-- encrypted snapshots are encrypted, even if this parameter is false or
-- when encryption by default is not enabled.
newEncryptionConfiguration ::
  -- | 'encrypted'
  Prelude.Bool ->
  EncryptionConfiguration
newEncryptionConfiguration :: Bool -> EncryptionConfiguration
newEncryptionConfiguration Bool
pEncrypted_ =
  EncryptionConfiguration' :: Maybe Text -> Bool -> EncryptionConfiguration
EncryptionConfiguration'
    { $sel:cmkArn:EncryptionConfiguration' :: Maybe Text
cmkArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:encrypted:EncryptionConfiguration' :: Bool
encrypted = Bool
pEncrypted_
    }

-- | The Amazon Resource Name (ARN) of the KMS key to use for EBS encryption.
-- If this parameter is not specified, the default KMS key for the account
-- is used.
encryptionConfiguration_cmkArn :: Lens.Lens' EncryptionConfiguration (Prelude.Maybe Prelude.Text)
encryptionConfiguration_cmkArn :: (Maybe Text -> f (Maybe Text))
-> EncryptionConfiguration -> f EncryptionConfiguration
encryptionConfiguration_cmkArn = (EncryptionConfiguration -> Maybe Text)
-> (EncryptionConfiguration
    -> Maybe Text -> EncryptionConfiguration)
-> Lens
     EncryptionConfiguration
     EncryptionConfiguration
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionConfiguration' {Maybe Text
cmkArn :: Maybe Text
$sel:cmkArn:EncryptionConfiguration' :: EncryptionConfiguration -> Maybe Text
cmkArn} -> Maybe Text
cmkArn) (\s :: EncryptionConfiguration
s@EncryptionConfiguration' {} Maybe Text
a -> EncryptionConfiguration
s {$sel:cmkArn:EncryptionConfiguration' :: Maybe Text
cmkArn = Maybe Text
a} :: EncryptionConfiguration)

-- | To encrypt a copy of an unencrypted snapshot when encryption by default
-- is not enabled, enable encryption using this parameter. Copies of
-- encrypted snapshots are encrypted, even if this parameter is false or
-- when encryption by default is not enabled.
encryptionConfiguration_encrypted :: Lens.Lens' EncryptionConfiguration Prelude.Bool
encryptionConfiguration_encrypted :: (Bool -> f Bool)
-> EncryptionConfiguration -> f EncryptionConfiguration
encryptionConfiguration_encrypted = (EncryptionConfiguration -> Bool)
-> (EncryptionConfiguration -> Bool -> EncryptionConfiguration)
-> Lens EncryptionConfiguration EncryptionConfiguration Bool Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionConfiguration' {Bool
encrypted :: Bool
$sel:encrypted:EncryptionConfiguration' :: EncryptionConfiguration -> Bool
encrypted} -> Bool
encrypted) (\s :: EncryptionConfiguration
s@EncryptionConfiguration' {} Bool
a -> EncryptionConfiguration
s {$sel:encrypted:EncryptionConfiguration' :: Bool
encrypted = Bool
a} :: EncryptionConfiguration)

instance Core.FromJSON EncryptionConfiguration where
  parseJSON :: Value -> Parser EncryptionConfiguration
parseJSON =
    String
-> (Object -> Parser EncryptionConfiguration)
-> Value
-> Parser EncryptionConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EncryptionConfiguration"
      ( \Object
x ->
          Maybe Text -> Bool -> EncryptionConfiguration
EncryptionConfiguration'
            (Maybe Text -> Bool -> EncryptionConfiguration)
-> Parser (Maybe Text) -> Parser (Bool -> EncryptionConfiguration)
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
"CmkArn")
            Parser (Bool -> EncryptionConfiguration)
-> Parser Bool -> Parser EncryptionConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Bool
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Encrypted")
      )

instance Prelude.Hashable EncryptionConfiguration

instance Prelude.NFData EncryptionConfiguration

instance Core.ToJSON EncryptionConfiguration where
  toJSON :: EncryptionConfiguration -> Value
toJSON EncryptionConfiguration' {Bool
Maybe Text
encrypted :: Bool
cmkArn :: Maybe Text
$sel:encrypted:EncryptionConfiguration' :: EncryptionConfiguration -> Bool
$sel:cmkArn:EncryptionConfiguration' :: EncryptionConfiguration -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"CmkArn" 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
cmkArn,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Encrypted" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Bool
encrypted)
          ]
      )