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

import qualified Amazonka.Core as Core
import Amazonka.Firehose.Types.KMSEncryptionConfig
import Amazonka.Firehose.Types.NoEncryptionConfig
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes the encryption for a destination in Amazon S3.
--
-- /See:/ 'newEncryptionConfiguration' smart constructor.
data EncryptionConfiguration = EncryptionConfiguration'
  { -- | Specifically override existing encryption information to ensure that no
    -- encryption is used.
    EncryptionConfiguration -> Maybe NoEncryptionConfig
noEncryptionConfig :: Prelude.Maybe NoEncryptionConfig,
    -- | The encryption key.
    EncryptionConfiguration -> Maybe KMSEncryptionConfig
kmsEncryptionConfig :: Prelude.Maybe KMSEncryptionConfig
  }
  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:
--
-- 'noEncryptionConfig', 'encryptionConfiguration_noEncryptionConfig' - Specifically override existing encryption information to ensure that no
-- encryption is used.
--
-- 'kmsEncryptionConfig', 'encryptionConfiguration_kmsEncryptionConfig' - The encryption key.
newEncryptionConfiguration ::
  EncryptionConfiguration
newEncryptionConfiguration :: EncryptionConfiguration
newEncryptionConfiguration =
  EncryptionConfiguration' :: Maybe NoEncryptionConfig
-> Maybe KMSEncryptionConfig -> EncryptionConfiguration
EncryptionConfiguration'
    { $sel:noEncryptionConfig:EncryptionConfiguration' :: Maybe NoEncryptionConfig
noEncryptionConfig =
        Maybe NoEncryptionConfig
forall a. Maybe a
Prelude.Nothing,
      $sel:kmsEncryptionConfig:EncryptionConfiguration' :: Maybe KMSEncryptionConfig
kmsEncryptionConfig = Maybe KMSEncryptionConfig
forall a. Maybe a
Prelude.Nothing
    }

-- | Specifically override existing encryption information to ensure that no
-- encryption is used.
encryptionConfiguration_noEncryptionConfig :: Lens.Lens' EncryptionConfiguration (Prelude.Maybe NoEncryptionConfig)
encryptionConfiguration_noEncryptionConfig :: (Maybe NoEncryptionConfig -> f (Maybe NoEncryptionConfig))
-> EncryptionConfiguration -> f EncryptionConfiguration
encryptionConfiguration_noEncryptionConfig = (EncryptionConfiguration -> Maybe NoEncryptionConfig)
-> (EncryptionConfiguration
    -> Maybe NoEncryptionConfig -> EncryptionConfiguration)
-> Lens
     EncryptionConfiguration
     EncryptionConfiguration
     (Maybe NoEncryptionConfig)
     (Maybe NoEncryptionConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionConfiguration' {Maybe NoEncryptionConfig
noEncryptionConfig :: Maybe NoEncryptionConfig
$sel:noEncryptionConfig:EncryptionConfiguration' :: EncryptionConfiguration -> Maybe NoEncryptionConfig
noEncryptionConfig} -> Maybe NoEncryptionConfig
noEncryptionConfig) (\s :: EncryptionConfiguration
s@EncryptionConfiguration' {} Maybe NoEncryptionConfig
a -> EncryptionConfiguration
s {$sel:noEncryptionConfig:EncryptionConfiguration' :: Maybe NoEncryptionConfig
noEncryptionConfig = Maybe NoEncryptionConfig
a} :: EncryptionConfiguration)

-- | The encryption key.
encryptionConfiguration_kmsEncryptionConfig :: Lens.Lens' EncryptionConfiguration (Prelude.Maybe KMSEncryptionConfig)
encryptionConfiguration_kmsEncryptionConfig :: (Maybe KMSEncryptionConfig -> f (Maybe KMSEncryptionConfig))
-> EncryptionConfiguration -> f EncryptionConfiguration
encryptionConfiguration_kmsEncryptionConfig = (EncryptionConfiguration -> Maybe KMSEncryptionConfig)
-> (EncryptionConfiguration
    -> Maybe KMSEncryptionConfig -> EncryptionConfiguration)
-> Lens
     EncryptionConfiguration
     EncryptionConfiguration
     (Maybe KMSEncryptionConfig)
     (Maybe KMSEncryptionConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionConfiguration' {Maybe KMSEncryptionConfig
kmsEncryptionConfig :: Maybe KMSEncryptionConfig
$sel:kmsEncryptionConfig:EncryptionConfiguration' :: EncryptionConfiguration -> Maybe KMSEncryptionConfig
kmsEncryptionConfig} -> Maybe KMSEncryptionConfig
kmsEncryptionConfig) (\s :: EncryptionConfiguration
s@EncryptionConfiguration' {} Maybe KMSEncryptionConfig
a -> EncryptionConfiguration
s {$sel:kmsEncryptionConfig:EncryptionConfiguration' :: Maybe KMSEncryptionConfig
kmsEncryptionConfig = Maybe KMSEncryptionConfig
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 NoEncryptionConfig
-> Maybe KMSEncryptionConfig -> EncryptionConfiguration
EncryptionConfiguration'
            (Maybe NoEncryptionConfig
 -> Maybe KMSEncryptionConfig -> EncryptionConfiguration)
-> Parser (Maybe NoEncryptionConfig)
-> Parser (Maybe KMSEncryptionConfig -> EncryptionConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe NoEncryptionConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"NoEncryptionConfig")
            Parser (Maybe KMSEncryptionConfig -> EncryptionConfiguration)
-> Parser (Maybe KMSEncryptionConfig)
-> Parser EncryptionConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe KMSEncryptionConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"KMSEncryptionConfig")
      )

instance Prelude.Hashable EncryptionConfiguration

instance Prelude.NFData EncryptionConfiguration

instance Core.ToJSON EncryptionConfiguration where
  toJSON :: EncryptionConfiguration -> Value
toJSON EncryptionConfiguration' {Maybe KMSEncryptionConfig
Maybe NoEncryptionConfig
kmsEncryptionConfig :: Maybe KMSEncryptionConfig
noEncryptionConfig :: Maybe NoEncryptionConfig
$sel:kmsEncryptionConfig:EncryptionConfiguration' :: EncryptionConfiguration -> Maybe KMSEncryptionConfig
$sel:noEncryptionConfig:EncryptionConfiguration' :: EncryptionConfiguration -> Maybe NoEncryptionConfig
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"NoEncryptionConfig" Text -> NoEncryptionConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NoEncryptionConfig -> Pair)
-> Maybe NoEncryptionConfig -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe NoEncryptionConfig
noEncryptionConfig,
            (Text
"KMSEncryptionConfig" Text -> KMSEncryptionConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (KMSEncryptionConfig -> Pair)
-> Maybe KMSEncryptionConfig -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe KMSEncryptionConfig
kmsEncryptionConfig
          ]
      )