{-# 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.QLDB.Types.S3EncryptionConfiguration
-- 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.QLDB.Types.S3EncryptionConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.QLDB.Types.S3ObjectEncryptionType

-- | The encryption settings that are used by a journal export job to write
-- data in an Amazon Simple Storage Service (Amazon S3) bucket.
--
-- /See:/ 'newS3EncryptionConfiguration' smart constructor.
data S3EncryptionConfiguration = S3EncryptionConfiguration'
  { -- | The Amazon Resource Name (ARN) of a symmetric customer master key (CMK)
    -- in Key Management Service (KMS). Amazon S3 does not support asymmetric
    -- CMKs.
    --
    -- You must provide a @KmsKeyArn@ if you specify @SSE_KMS@ as the
    -- @ObjectEncryptionType@.
    --
    -- @KmsKeyArn@ is not required if you specify @SSE_S3@ as the
    -- @ObjectEncryptionType@.
    S3EncryptionConfiguration -> Maybe Text
kmsKeyArn :: Prelude.Maybe Prelude.Text,
    -- | The Amazon S3 object encryption type.
    --
    -- To learn more about server-side encryption options in Amazon S3, see
    -- <https://docs.aws.amazon.com/AmazonS3/latest/dev/serv-side-encryption.html Protecting Data Using Server-Side Encryption>
    -- in the /Amazon S3 Developer Guide/.
    S3EncryptionConfiguration -> S3ObjectEncryptionType
objectEncryptionType :: S3ObjectEncryptionType
  }
  deriving (S3EncryptionConfiguration -> S3EncryptionConfiguration -> Bool
(S3EncryptionConfiguration -> S3EncryptionConfiguration -> Bool)
-> (S3EncryptionConfiguration -> S3EncryptionConfiguration -> Bool)
-> Eq S3EncryptionConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: S3EncryptionConfiguration -> S3EncryptionConfiguration -> Bool
$c/= :: S3EncryptionConfiguration -> S3EncryptionConfiguration -> Bool
== :: S3EncryptionConfiguration -> S3EncryptionConfiguration -> Bool
$c== :: S3EncryptionConfiguration -> S3EncryptionConfiguration -> Bool
Prelude.Eq, ReadPrec [S3EncryptionConfiguration]
ReadPrec S3EncryptionConfiguration
Int -> ReadS S3EncryptionConfiguration
ReadS [S3EncryptionConfiguration]
(Int -> ReadS S3EncryptionConfiguration)
-> ReadS [S3EncryptionConfiguration]
-> ReadPrec S3EncryptionConfiguration
-> ReadPrec [S3EncryptionConfiguration]
-> Read S3EncryptionConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [S3EncryptionConfiguration]
$creadListPrec :: ReadPrec [S3EncryptionConfiguration]
readPrec :: ReadPrec S3EncryptionConfiguration
$creadPrec :: ReadPrec S3EncryptionConfiguration
readList :: ReadS [S3EncryptionConfiguration]
$creadList :: ReadS [S3EncryptionConfiguration]
readsPrec :: Int -> ReadS S3EncryptionConfiguration
$creadsPrec :: Int -> ReadS S3EncryptionConfiguration
Prelude.Read, Int -> S3EncryptionConfiguration -> ShowS
[S3EncryptionConfiguration] -> ShowS
S3EncryptionConfiguration -> String
(Int -> S3EncryptionConfiguration -> ShowS)
-> (S3EncryptionConfiguration -> String)
-> ([S3EncryptionConfiguration] -> ShowS)
-> Show S3EncryptionConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [S3EncryptionConfiguration] -> ShowS
$cshowList :: [S3EncryptionConfiguration] -> ShowS
show :: S3EncryptionConfiguration -> String
$cshow :: S3EncryptionConfiguration -> String
showsPrec :: Int -> S3EncryptionConfiguration -> ShowS
$cshowsPrec :: Int -> S3EncryptionConfiguration -> ShowS
Prelude.Show, (forall x.
 S3EncryptionConfiguration -> Rep S3EncryptionConfiguration x)
-> (forall x.
    Rep S3EncryptionConfiguration x -> S3EncryptionConfiguration)
-> Generic S3EncryptionConfiguration
forall x.
Rep S3EncryptionConfiguration x -> S3EncryptionConfiguration
forall x.
S3EncryptionConfiguration -> Rep S3EncryptionConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep S3EncryptionConfiguration x -> S3EncryptionConfiguration
$cfrom :: forall x.
S3EncryptionConfiguration -> Rep S3EncryptionConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'S3EncryptionConfiguration' 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:
--
-- 'kmsKeyArn', 's3EncryptionConfiguration_kmsKeyArn' - The Amazon Resource Name (ARN) of a symmetric customer master key (CMK)
-- in Key Management Service (KMS). Amazon S3 does not support asymmetric
-- CMKs.
--
-- You must provide a @KmsKeyArn@ if you specify @SSE_KMS@ as the
-- @ObjectEncryptionType@.
--
-- @KmsKeyArn@ is not required if you specify @SSE_S3@ as the
-- @ObjectEncryptionType@.
--
-- 'objectEncryptionType', 's3EncryptionConfiguration_objectEncryptionType' - The Amazon S3 object encryption type.
--
-- To learn more about server-side encryption options in Amazon S3, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/serv-side-encryption.html Protecting Data Using Server-Side Encryption>
-- in the /Amazon S3 Developer Guide/.
newS3EncryptionConfiguration ::
  -- | 'objectEncryptionType'
  S3ObjectEncryptionType ->
  S3EncryptionConfiguration
newS3EncryptionConfiguration :: S3ObjectEncryptionType -> S3EncryptionConfiguration
newS3EncryptionConfiguration S3ObjectEncryptionType
pObjectEncryptionType_ =
  S3EncryptionConfiguration' :: Maybe Text -> S3ObjectEncryptionType -> S3EncryptionConfiguration
S3EncryptionConfiguration'
    { $sel:kmsKeyArn:S3EncryptionConfiguration' :: Maybe Text
kmsKeyArn =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:objectEncryptionType:S3EncryptionConfiguration' :: S3ObjectEncryptionType
objectEncryptionType = S3ObjectEncryptionType
pObjectEncryptionType_
    }

-- | The Amazon Resource Name (ARN) of a symmetric customer master key (CMK)
-- in Key Management Service (KMS). Amazon S3 does not support asymmetric
-- CMKs.
--
-- You must provide a @KmsKeyArn@ if you specify @SSE_KMS@ as the
-- @ObjectEncryptionType@.
--
-- @KmsKeyArn@ is not required if you specify @SSE_S3@ as the
-- @ObjectEncryptionType@.
s3EncryptionConfiguration_kmsKeyArn :: Lens.Lens' S3EncryptionConfiguration (Prelude.Maybe Prelude.Text)
s3EncryptionConfiguration_kmsKeyArn :: (Maybe Text -> f (Maybe Text))
-> S3EncryptionConfiguration -> f S3EncryptionConfiguration
s3EncryptionConfiguration_kmsKeyArn = (S3EncryptionConfiguration -> Maybe Text)
-> (S3EncryptionConfiguration
    -> Maybe Text -> S3EncryptionConfiguration)
-> Lens
     S3EncryptionConfiguration
     S3EncryptionConfiguration
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3EncryptionConfiguration' {Maybe Text
kmsKeyArn :: Maybe Text
$sel:kmsKeyArn:S3EncryptionConfiguration' :: S3EncryptionConfiguration -> Maybe Text
kmsKeyArn} -> Maybe Text
kmsKeyArn) (\s :: S3EncryptionConfiguration
s@S3EncryptionConfiguration' {} Maybe Text
a -> S3EncryptionConfiguration
s {$sel:kmsKeyArn:S3EncryptionConfiguration' :: Maybe Text
kmsKeyArn = Maybe Text
a} :: S3EncryptionConfiguration)

-- | The Amazon S3 object encryption type.
--
-- To learn more about server-side encryption options in Amazon S3, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/serv-side-encryption.html Protecting Data Using Server-Side Encryption>
-- in the /Amazon S3 Developer Guide/.
s3EncryptionConfiguration_objectEncryptionType :: Lens.Lens' S3EncryptionConfiguration S3ObjectEncryptionType
s3EncryptionConfiguration_objectEncryptionType :: (S3ObjectEncryptionType -> f S3ObjectEncryptionType)
-> S3EncryptionConfiguration -> f S3EncryptionConfiguration
s3EncryptionConfiguration_objectEncryptionType = (S3EncryptionConfiguration -> S3ObjectEncryptionType)
-> (S3EncryptionConfiguration
    -> S3ObjectEncryptionType -> S3EncryptionConfiguration)
-> Lens
     S3EncryptionConfiguration
     S3EncryptionConfiguration
     S3ObjectEncryptionType
     S3ObjectEncryptionType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\S3EncryptionConfiguration' {S3ObjectEncryptionType
objectEncryptionType :: S3ObjectEncryptionType
$sel:objectEncryptionType:S3EncryptionConfiguration' :: S3EncryptionConfiguration -> S3ObjectEncryptionType
objectEncryptionType} -> S3ObjectEncryptionType
objectEncryptionType) (\s :: S3EncryptionConfiguration
s@S3EncryptionConfiguration' {} S3ObjectEncryptionType
a -> S3EncryptionConfiguration
s {$sel:objectEncryptionType:S3EncryptionConfiguration' :: S3ObjectEncryptionType
objectEncryptionType = S3ObjectEncryptionType
a} :: S3EncryptionConfiguration)

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

instance Prelude.Hashable S3EncryptionConfiguration

instance Prelude.NFData S3EncryptionConfiguration

instance Core.ToJSON S3EncryptionConfiguration where
  toJSON :: S3EncryptionConfiguration -> Value
toJSON S3EncryptionConfiguration' {Maybe Text
S3ObjectEncryptionType
objectEncryptionType :: S3ObjectEncryptionType
kmsKeyArn :: Maybe Text
$sel:objectEncryptionType:S3EncryptionConfiguration' :: S3EncryptionConfiguration -> S3ObjectEncryptionType
$sel:kmsKeyArn:S3EncryptionConfiguration' :: S3EncryptionConfiguration -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"KmsKeyArn" 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
kmsKeyArn,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"ObjectEncryptionType"
                  Text -> S3ObjectEncryptionType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= S3ObjectEncryptionType
objectEncryptionType
              )
          ]
      )