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

import Amazonka.Athena.Types.EncryptionOption
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | If query results are encrypted in Amazon S3, indicates the encryption
-- option used (for example, @SSE-KMS@ or @CSE-KMS@) and key information.
--
-- /See:/ 'newEncryptionConfiguration' smart constructor.
data EncryptionConfiguration = EncryptionConfiguration'
  { -- | For @SSE-KMS@ and @CSE-KMS@, this is the KMS key ARN or ID.
    EncryptionConfiguration -> Maybe Text
kmsKey :: Prelude.Maybe Prelude.Text,
    -- | Indicates whether Amazon S3 server-side encryption with Amazon
    -- S3-managed keys (@SSE-S3@), server-side encryption with KMS-managed keys
    -- (@SSE-KMS@), or client-side encryption with KMS-managed keys (CSE-KMS)
    -- is used.
    --
    -- If a query runs in a workgroup and the workgroup overrides client-side
    -- settings, then the workgroup\'s setting for encryption is used. It
    -- specifies whether query results must be encrypted, for all queries that
    -- run in this workgroup.
    EncryptionConfiguration -> EncryptionOption
encryptionOption :: EncryptionOption
  }
  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:
--
-- 'kmsKey', 'encryptionConfiguration_kmsKey' - For @SSE-KMS@ and @CSE-KMS@, this is the KMS key ARN or ID.
--
-- 'encryptionOption', 'encryptionConfiguration_encryptionOption' - Indicates whether Amazon S3 server-side encryption with Amazon
-- S3-managed keys (@SSE-S3@), server-side encryption with KMS-managed keys
-- (@SSE-KMS@), or client-side encryption with KMS-managed keys (CSE-KMS)
-- is used.
--
-- If a query runs in a workgroup and the workgroup overrides client-side
-- settings, then the workgroup\'s setting for encryption is used. It
-- specifies whether query results must be encrypted, for all queries that
-- run in this workgroup.
newEncryptionConfiguration ::
  -- | 'encryptionOption'
  EncryptionOption ->
  EncryptionConfiguration
newEncryptionConfiguration :: EncryptionOption -> EncryptionConfiguration
newEncryptionConfiguration EncryptionOption
pEncryptionOption_ =
  EncryptionConfiguration' :: Maybe Text -> EncryptionOption -> EncryptionConfiguration
EncryptionConfiguration'
    { $sel:kmsKey:EncryptionConfiguration' :: Maybe Text
kmsKey = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:encryptionOption:EncryptionConfiguration' :: EncryptionOption
encryptionOption = EncryptionOption
pEncryptionOption_
    }

-- | For @SSE-KMS@ and @CSE-KMS@, this is the KMS key ARN or ID.
encryptionConfiguration_kmsKey :: Lens.Lens' EncryptionConfiguration (Prelude.Maybe Prelude.Text)
encryptionConfiguration_kmsKey :: (Maybe Text -> f (Maybe Text))
-> EncryptionConfiguration -> f EncryptionConfiguration
encryptionConfiguration_kmsKey = (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
kmsKey :: Maybe Text
$sel:kmsKey:EncryptionConfiguration' :: EncryptionConfiguration -> Maybe Text
kmsKey} -> Maybe Text
kmsKey) (\s :: EncryptionConfiguration
s@EncryptionConfiguration' {} Maybe Text
a -> EncryptionConfiguration
s {$sel:kmsKey:EncryptionConfiguration' :: Maybe Text
kmsKey = Maybe Text
a} :: EncryptionConfiguration)

-- | Indicates whether Amazon S3 server-side encryption with Amazon
-- S3-managed keys (@SSE-S3@), server-side encryption with KMS-managed keys
-- (@SSE-KMS@), or client-side encryption with KMS-managed keys (CSE-KMS)
-- is used.
--
-- If a query runs in a workgroup and the workgroup overrides client-side
-- settings, then the workgroup\'s setting for encryption is used. It
-- specifies whether query results must be encrypted, for all queries that
-- run in this workgroup.
encryptionConfiguration_encryptionOption :: Lens.Lens' EncryptionConfiguration EncryptionOption
encryptionConfiguration_encryptionOption :: (EncryptionOption -> f EncryptionOption)
-> EncryptionConfiguration -> f EncryptionConfiguration
encryptionConfiguration_encryptionOption = (EncryptionConfiguration -> EncryptionOption)
-> (EncryptionConfiguration
    -> EncryptionOption -> EncryptionConfiguration)
-> Lens
     EncryptionConfiguration
     EncryptionConfiguration
     EncryptionOption
     EncryptionOption
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionConfiguration' {EncryptionOption
encryptionOption :: EncryptionOption
$sel:encryptionOption:EncryptionConfiguration' :: EncryptionConfiguration -> EncryptionOption
encryptionOption} -> EncryptionOption
encryptionOption) (\s :: EncryptionConfiguration
s@EncryptionConfiguration' {} EncryptionOption
a -> EncryptionConfiguration
s {$sel:encryptionOption:EncryptionConfiguration' :: EncryptionOption
encryptionOption = EncryptionOption
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 -> EncryptionOption -> EncryptionConfiguration
EncryptionConfiguration'
            (Maybe Text -> EncryptionOption -> EncryptionConfiguration)
-> Parser (Maybe Text)
-> Parser (EncryptionOption -> 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
"KmsKey")
            Parser (EncryptionOption -> EncryptionConfiguration)
-> Parser EncryptionOption -> Parser EncryptionConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser EncryptionOption
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"EncryptionOption")
      )

instance Prelude.Hashable EncryptionConfiguration

instance Prelude.NFData EncryptionConfiguration

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