{-# 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.KeySpaces.Types.EncryptionSpecification
-- 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.KeySpaces.Types.EncryptionSpecification where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.KeySpaces.Types.EncryptionType
import qualified Amazonka.Prelude as Prelude

-- | Amazon Keyspaces encrypts and decrypts the table data at rest
-- transparently and integrates with Key Management Service for storing and
-- managing the encryption key. You can choose one of the following KMS
-- keys (KMS keys):
--
-- • Amazon Web Services owned key - This is the default encryption type.
-- The key is owned by Amazon Keyspaces (no additional charge).
--
-- • Customer managed key - This key is stored in your account and is
-- created, owned, and managed by you. You have full control over the
-- customer managed key (KMS charges apply).
--
-- For more information about encryption at rest in Amazon Keyspaces, see
-- <https://docs.aws.amazon.com/keyspaces/latest/devguide/EncryptionAtRest.html Encryption at rest>
-- in the /Amazon Keyspaces Developer Guide/.
--
-- For more information about KMS, see
-- <https://docs.aws.amazon.com/keyspaces/latest/devguide/EncryptionAtRest.html KMS management service concepts>
-- in the /Key Management Service Developer Guide/.
--
-- /See:/ 'newEncryptionSpecification' smart constructor.
data EncryptionSpecification = EncryptionSpecification'
  { -- | The Amazon Resource Name (ARN) of the customer managed KMS key, for
    -- example @kms_key_identifier:ARN@.
    EncryptionSpecification -> Maybe Text
kmsKeyIdentifier :: Prelude.Maybe Prelude.Text,
    -- | The encryption option specified for the table. You can choose one of the
    -- following KMS keys (KMS keys):
    --
    -- • @type:AWS_OWNED_KMS_KEY@ - This key is owned by Amazon Keyspaces.
    --
    -- • @type:CUSTOMER_MANAGED_KMS_KEY@ - This key is stored in your account
    -- and is created, owned, and managed by you. This option requires the
    -- @kms_key_identifier@ of the KMS key in Amazon Resource Name (ARN) format
    -- as input.
    --
    -- The default is @type:AWS_OWNED_KMS_KEY@.
    --
    -- For more information, see
    -- <https://docs.aws.amazon.com/keyspaces/latest/devguide/EncryptionAtRest.html Encryption at rest>
    -- in the /Amazon Keyspaces Developer Guide/.
    EncryptionSpecification -> EncryptionType
type' :: EncryptionType
  }
  deriving (EncryptionSpecification -> EncryptionSpecification -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EncryptionSpecification -> EncryptionSpecification -> Bool
$c/= :: EncryptionSpecification -> EncryptionSpecification -> Bool
== :: EncryptionSpecification -> EncryptionSpecification -> Bool
$c== :: EncryptionSpecification -> EncryptionSpecification -> Bool
Prelude.Eq, ReadPrec [EncryptionSpecification]
ReadPrec EncryptionSpecification
Int -> ReadS EncryptionSpecification
ReadS [EncryptionSpecification]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EncryptionSpecification]
$creadListPrec :: ReadPrec [EncryptionSpecification]
readPrec :: ReadPrec EncryptionSpecification
$creadPrec :: ReadPrec EncryptionSpecification
readList :: ReadS [EncryptionSpecification]
$creadList :: ReadS [EncryptionSpecification]
readsPrec :: Int -> ReadS EncryptionSpecification
$creadsPrec :: Int -> ReadS EncryptionSpecification
Prelude.Read, Int -> EncryptionSpecification -> ShowS
[EncryptionSpecification] -> ShowS
EncryptionSpecification -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EncryptionSpecification] -> ShowS
$cshowList :: [EncryptionSpecification] -> ShowS
show :: EncryptionSpecification -> String
$cshow :: EncryptionSpecification -> String
showsPrec :: Int -> EncryptionSpecification -> ShowS
$cshowsPrec :: Int -> EncryptionSpecification -> ShowS
Prelude.Show, forall x. Rep EncryptionSpecification x -> EncryptionSpecification
forall x. EncryptionSpecification -> Rep EncryptionSpecification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EncryptionSpecification x -> EncryptionSpecification
$cfrom :: forall x. EncryptionSpecification -> Rep EncryptionSpecification x
Prelude.Generic)

-- |
-- Create a value of 'EncryptionSpecification' 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:
--
-- 'kmsKeyIdentifier', 'encryptionSpecification_kmsKeyIdentifier' - The Amazon Resource Name (ARN) of the customer managed KMS key, for
-- example @kms_key_identifier:ARN@.
--
-- 'type'', 'encryptionSpecification_type' - The encryption option specified for the table. You can choose one of the
-- following KMS keys (KMS keys):
--
-- • @type:AWS_OWNED_KMS_KEY@ - This key is owned by Amazon Keyspaces.
--
-- • @type:CUSTOMER_MANAGED_KMS_KEY@ - This key is stored in your account
-- and is created, owned, and managed by you. This option requires the
-- @kms_key_identifier@ of the KMS key in Amazon Resource Name (ARN) format
-- as input.
--
-- The default is @type:AWS_OWNED_KMS_KEY@.
--
-- For more information, see
-- <https://docs.aws.amazon.com/keyspaces/latest/devguide/EncryptionAtRest.html Encryption at rest>
-- in the /Amazon Keyspaces Developer Guide/.
newEncryptionSpecification ::
  -- | 'type''
  EncryptionType ->
  EncryptionSpecification
newEncryptionSpecification :: EncryptionType -> EncryptionSpecification
newEncryptionSpecification EncryptionType
pType_ =
  EncryptionSpecification'
    { $sel:kmsKeyIdentifier:EncryptionSpecification' :: Maybe Text
kmsKeyIdentifier =
        forall a. Maybe a
Prelude.Nothing,
      $sel:type':EncryptionSpecification' :: EncryptionType
type' = EncryptionType
pType_
    }

-- | The Amazon Resource Name (ARN) of the customer managed KMS key, for
-- example @kms_key_identifier:ARN@.
encryptionSpecification_kmsKeyIdentifier :: Lens.Lens' EncryptionSpecification (Prelude.Maybe Prelude.Text)
encryptionSpecification_kmsKeyIdentifier :: Lens' EncryptionSpecification (Maybe Text)
encryptionSpecification_kmsKeyIdentifier = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionSpecification' {Maybe Text
kmsKeyIdentifier :: Maybe Text
$sel:kmsKeyIdentifier:EncryptionSpecification' :: EncryptionSpecification -> Maybe Text
kmsKeyIdentifier} -> Maybe Text
kmsKeyIdentifier) (\s :: EncryptionSpecification
s@EncryptionSpecification' {} Maybe Text
a -> EncryptionSpecification
s {$sel:kmsKeyIdentifier:EncryptionSpecification' :: Maybe Text
kmsKeyIdentifier = Maybe Text
a} :: EncryptionSpecification)

-- | The encryption option specified for the table. You can choose one of the
-- following KMS keys (KMS keys):
--
-- • @type:AWS_OWNED_KMS_KEY@ - This key is owned by Amazon Keyspaces.
--
-- • @type:CUSTOMER_MANAGED_KMS_KEY@ - This key is stored in your account
-- and is created, owned, and managed by you. This option requires the
-- @kms_key_identifier@ of the KMS key in Amazon Resource Name (ARN) format
-- as input.
--
-- The default is @type:AWS_OWNED_KMS_KEY@.
--
-- For more information, see
-- <https://docs.aws.amazon.com/keyspaces/latest/devguide/EncryptionAtRest.html Encryption at rest>
-- in the /Amazon Keyspaces Developer Guide/.
encryptionSpecification_type :: Lens.Lens' EncryptionSpecification EncryptionType
encryptionSpecification_type :: Lens' EncryptionSpecification EncryptionType
encryptionSpecification_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionSpecification' {EncryptionType
type' :: EncryptionType
$sel:type':EncryptionSpecification' :: EncryptionSpecification -> EncryptionType
type'} -> EncryptionType
type') (\s :: EncryptionSpecification
s@EncryptionSpecification' {} EncryptionType
a -> EncryptionSpecification
s {$sel:type':EncryptionSpecification' :: EncryptionType
type' = EncryptionType
a} :: EncryptionSpecification)

instance Data.FromJSON EncryptionSpecification where
  parseJSON :: Value -> Parser EncryptionSpecification
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"EncryptionSpecification"
      ( \Object
x ->
          Maybe Text -> EncryptionType -> EncryptionSpecification
EncryptionSpecification'
            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
"kmsKeyIdentifier")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"type")
      )

instance Prelude.Hashable EncryptionSpecification where
  hashWithSalt :: Int -> EncryptionSpecification -> Int
hashWithSalt Int
_salt EncryptionSpecification' {Maybe Text
EncryptionType
type' :: EncryptionType
kmsKeyIdentifier :: Maybe Text
$sel:type':EncryptionSpecification' :: EncryptionSpecification -> EncryptionType
$sel:kmsKeyIdentifier:EncryptionSpecification' :: EncryptionSpecification -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
kmsKeyIdentifier
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` EncryptionType
type'

instance Prelude.NFData EncryptionSpecification where
  rnf :: EncryptionSpecification -> ()
rnf EncryptionSpecification' {Maybe Text
EncryptionType
type' :: EncryptionType
kmsKeyIdentifier :: Maybe Text
$sel:type':EncryptionSpecification' :: EncryptionSpecification -> EncryptionType
$sel:kmsKeyIdentifier:EncryptionSpecification' :: EncryptionSpecification -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
kmsKeyIdentifier
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf EncryptionType
type'

instance Data.ToJSON EncryptionSpecification where
  toJSON :: EncryptionSpecification -> Value
toJSON EncryptionSpecification' {Maybe Text
EncryptionType
type' :: EncryptionType
kmsKeyIdentifier :: Maybe Text
$sel:type':EncryptionSpecification' :: EncryptionSpecification -> EncryptionType
$sel:kmsKeyIdentifier:EncryptionSpecification' :: EncryptionSpecification -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"kmsKeyIdentifier" 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
kmsKeyIdentifier,
            forall a. a -> Maybe a
Prelude.Just (Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= EncryptionType
type')
          ]
      )