{-# 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.HealthLake.Types.KmsEncryptionConfig
-- 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.HealthLake.Types.KmsEncryptionConfig where

import qualified Amazonka.Core as Core
import Amazonka.HealthLake.Types.CmkType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The customer-managed-key(CMK) used when creating a Data Store. If a
-- customer owned key is not specified, an AWS owned key will be used for
-- encryption.
--
-- /See:/ 'newKmsEncryptionConfig' smart constructor.
data KmsEncryptionConfig = KmsEncryptionConfig'
  { -- | The KMS encryption key id\/alias used to encrypt the Data Store contents
    -- at rest.
    KmsEncryptionConfig -> Maybe Text
kmsKeyId :: Prelude.Maybe Prelude.Text,
    -- | The type of customer-managed-key(CMK) used for encyrption. The two types
    -- of supported CMKs are customer owned CMKs and AWS owned CMKs.
    KmsEncryptionConfig -> CmkType
cmkType :: CmkType
  }
  deriving (KmsEncryptionConfig -> KmsEncryptionConfig -> Bool
(KmsEncryptionConfig -> KmsEncryptionConfig -> Bool)
-> (KmsEncryptionConfig -> KmsEncryptionConfig -> Bool)
-> Eq KmsEncryptionConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: KmsEncryptionConfig -> KmsEncryptionConfig -> Bool
$c/= :: KmsEncryptionConfig -> KmsEncryptionConfig -> Bool
== :: KmsEncryptionConfig -> KmsEncryptionConfig -> Bool
$c== :: KmsEncryptionConfig -> KmsEncryptionConfig -> Bool
Prelude.Eq, ReadPrec [KmsEncryptionConfig]
ReadPrec KmsEncryptionConfig
Int -> ReadS KmsEncryptionConfig
ReadS [KmsEncryptionConfig]
(Int -> ReadS KmsEncryptionConfig)
-> ReadS [KmsEncryptionConfig]
-> ReadPrec KmsEncryptionConfig
-> ReadPrec [KmsEncryptionConfig]
-> Read KmsEncryptionConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [KmsEncryptionConfig]
$creadListPrec :: ReadPrec [KmsEncryptionConfig]
readPrec :: ReadPrec KmsEncryptionConfig
$creadPrec :: ReadPrec KmsEncryptionConfig
readList :: ReadS [KmsEncryptionConfig]
$creadList :: ReadS [KmsEncryptionConfig]
readsPrec :: Int -> ReadS KmsEncryptionConfig
$creadsPrec :: Int -> ReadS KmsEncryptionConfig
Prelude.Read, Int -> KmsEncryptionConfig -> ShowS
[KmsEncryptionConfig] -> ShowS
KmsEncryptionConfig -> String
(Int -> KmsEncryptionConfig -> ShowS)
-> (KmsEncryptionConfig -> String)
-> ([KmsEncryptionConfig] -> ShowS)
-> Show KmsEncryptionConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [KmsEncryptionConfig] -> ShowS
$cshowList :: [KmsEncryptionConfig] -> ShowS
show :: KmsEncryptionConfig -> String
$cshow :: KmsEncryptionConfig -> String
showsPrec :: Int -> KmsEncryptionConfig -> ShowS
$cshowsPrec :: Int -> KmsEncryptionConfig -> ShowS
Prelude.Show, (forall x. KmsEncryptionConfig -> Rep KmsEncryptionConfig x)
-> (forall x. Rep KmsEncryptionConfig x -> KmsEncryptionConfig)
-> Generic KmsEncryptionConfig
forall x. Rep KmsEncryptionConfig x -> KmsEncryptionConfig
forall x. KmsEncryptionConfig -> Rep KmsEncryptionConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep KmsEncryptionConfig x -> KmsEncryptionConfig
$cfrom :: forall x. KmsEncryptionConfig -> Rep KmsEncryptionConfig x
Prelude.Generic)

-- |
-- Create a value of 'KmsEncryptionConfig' 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:
--
-- 'kmsKeyId', 'kmsEncryptionConfig_kmsKeyId' - The KMS encryption key id\/alias used to encrypt the Data Store contents
-- at rest.
--
-- 'cmkType', 'kmsEncryptionConfig_cmkType' - The type of customer-managed-key(CMK) used for encyrption. The two types
-- of supported CMKs are customer owned CMKs and AWS owned CMKs.
newKmsEncryptionConfig ::
  -- | 'cmkType'
  CmkType ->
  KmsEncryptionConfig
newKmsEncryptionConfig :: CmkType -> KmsEncryptionConfig
newKmsEncryptionConfig CmkType
pCmkType_ =
  KmsEncryptionConfig' :: Maybe Text -> CmkType -> KmsEncryptionConfig
KmsEncryptionConfig'
    { $sel:kmsKeyId:KmsEncryptionConfig' :: Maybe Text
kmsKeyId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:cmkType:KmsEncryptionConfig' :: CmkType
cmkType = CmkType
pCmkType_
    }

-- | The KMS encryption key id\/alias used to encrypt the Data Store contents
-- at rest.
kmsEncryptionConfig_kmsKeyId :: Lens.Lens' KmsEncryptionConfig (Prelude.Maybe Prelude.Text)
kmsEncryptionConfig_kmsKeyId :: (Maybe Text -> f (Maybe Text))
-> KmsEncryptionConfig -> f KmsEncryptionConfig
kmsEncryptionConfig_kmsKeyId = (KmsEncryptionConfig -> Maybe Text)
-> (KmsEncryptionConfig -> Maybe Text -> KmsEncryptionConfig)
-> Lens
     KmsEncryptionConfig KmsEncryptionConfig (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KmsEncryptionConfig' {Maybe Text
kmsKeyId :: Maybe Text
$sel:kmsKeyId:KmsEncryptionConfig' :: KmsEncryptionConfig -> Maybe Text
kmsKeyId} -> Maybe Text
kmsKeyId) (\s :: KmsEncryptionConfig
s@KmsEncryptionConfig' {} Maybe Text
a -> KmsEncryptionConfig
s {$sel:kmsKeyId:KmsEncryptionConfig' :: Maybe Text
kmsKeyId = Maybe Text
a} :: KmsEncryptionConfig)

-- | The type of customer-managed-key(CMK) used for encyrption. The two types
-- of supported CMKs are customer owned CMKs and AWS owned CMKs.
kmsEncryptionConfig_cmkType :: Lens.Lens' KmsEncryptionConfig CmkType
kmsEncryptionConfig_cmkType :: (CmkType -> f CmkType)
-> KmsEncryptionConfig -> f KmsEncryptionConfig
kmsEncryptionConfig_cmkType = (KmsEncryptionConfig -> CmkType)
-> (KmsEncryptionConfig -> CmkType -> KmsEncryptionConfig)
-> Lens KmsEncryptionConfig KmsEncryptionConfig CmkType CmkType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KmsEncryptionConfig' {CmkType
cmkType :: CmkType
$sel:cmkType:KmsEncryptionConfig' :: KmsEncryptionConfig -> CmkType
cmkType} -> CmkType
cmkType) (\s :: KmsEncryptionConfig
s@KmsEncryptionConfig' {} CmkType
a -> KmsEncryptionConfig
s {$sel:cmkType:KmsEncryptionConfig' :: CmkType
cmkType = CmkType
a} :: KmsEncryptionConfig)

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

instance Prelude.Hashable KmsEncryptionConfig

instance Prelude.NFData KmsEncryptionConfig

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