{-# 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.MQ.Types.EncryptionOptions
-- 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.MQ.Types.EncryptionOptions where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Does not apply to RabbitMQ brokers.
--
-- Encryption options for the broker.
--
-- /See:/ 'newEncryptionOptions' smart constructor.
data EncryptionOptions = EncryptionOptions'
  { -- | The customer master key (CMK) to use for the AWS Key Management Service
    -- (KMS). This key is used to encrypt your data at rest. If not provided,
    -- Amazon MQ will use a default CMK to encrypt your data.
    EncryptionOptions -> Maybe Text
kmsKeyId :: Prelude.Maybe Prelude.Text,
    -- | Enables the use of an AWS owned CMK using AWS Key Management Service
    -- (KMS). Set to true by default, if no value is provided, for example, for
    -- RabbitMQ brokers.
    EncryptionOptions -> Bool
useAwsOwnedKey :: Prelude.Bool
  }
  deriving (EncryptionOptions -> EncryptionOptions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EncryptionOptions -> EncryptionOptions -> Bool
$c/= :: EncryptionOptions -> EncryptionOptions -> Bool
== :: EncryptionOptions -> EncryptionOptions -> Bool
$c== :: EncryptionOptions -> EncryptionOptions -> Bool
Prelude.Eq, ReadPrec [EncryptionOptions]
ReadPrec EncryptionOptions
Int -> ReadS EncryptionOptions
ReadS [EncryptionOptions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EncryptionOptions]
$creadListPrec :: ReadPrec [EncryptionOptions]
readPrec :: ReadPrec EncryptionOptions
$creadPrec :: ReadPrec EncryptionOptions
readList :: ReadS [EncryptionOptions]
$creadList :: ReadS [EncryptionOptions]
readsPrec :: Int -> ReadS EncryptionOptions
$creadsPrec :: Int -> ReadS EncryptionOptions
Prelude.Read, Int -> EncryptionOptions -> ShowS
[EncryptionOptions] -> ShowS
EncryptionOptions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EncryptionOptions] -> ShowS
$cshowList :: [EncryptionOptions] -> ShowS
show :: EncryptionOptions -> String
$cshow :: EncryptionOptions -> String
showsPrec :: Int -> EncryptionOptions -> ShowS
$cshowsPrec :: Int -> EncryptionOptions -> ShowS
Prelude.Show, forall x. Rep EncryptionOptions x -> EncryptionOptions
forall x. EncryptionOptions -> Rep EncryptionOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EncryptionOptions x -> EncryptionOptions
$cfrom :: forall x. EncryptionOptions -> Rep EncryptionOptions x
Prelude.Generic)

-- |
-- Create a value of 'EncryptionOptions' 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', 'encryptionOptions_kmsKeyId' - The customer master key (CMK) to use for the AWS Key Management Service
-- (KMS). This key is used to encrypt your data at rest. If not provided,
-- Amazon MQ will use a default CMK to encrypt your data.
--
-- 'useAwsOwnedKey', 'encryptionOptions_useAwsOwnedKey' - Enables the use of an AWS owned CMK using AWS Key Management Service
-- (KMS). Set to true by default, if no value is provided, for example, for
-- RabbitMQ brokers.
newEncryptionOptions ::
  -- | 'useAwsOwnedKey'
  Prelude.Bool ->
  EncryptionOptions
newEncryptionOptions :: Bool -> EncryptionOptions
newEncryptionOptions Bool
pUseAwsOwnedKey_ =
  EncryptionOptions'
    { $sel:kmsKeyId:EncryptionOptions' :: Maybe Text
kmsKeyId = forall a. Maybe a
Prelude.Nothing,
      $sel:useAwsOwnedKey:EncryptionOptions' :: Bool
useAwsOwnedKey = Bool
pUseAwsOwnedKey_
    }

-- | The customer master key (CMK) to use for the AWS Key Management Service
-- (KMS). This key is used to encrypt your data at rest. If not provided,
-- Amazon MQ will use a default CMK to encrypt your data.
encryptionOptions_kmsKeyId :: Lens.Lens' EncryptionOptions (Prelude.Maybe Prelude.Text)
encryptionOptions_kmsKeyId :: Lens' EncryptionOptions (Maybe Text)
encryptionOptions_kmsKeyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionOptions' {Maybe Text
kmsKeyId :: Maybe Text
$sel:kmsKeyId:EncryptionOptions' :: EncryptionOptions -> Maybe Text
kmsKeyId} -> Maybe Text
kmsKeyId) (\s :: EncryptionOptions
s@EncryptionOptions' {} Maybe Text
a -> EncryptionOptions
s {$sel:kmsKeyId:EncryptionOptions' :: Maybe Text
kmsKeyId = Maybe Text
a} :: EncryptionOptions)

-- | Enables the use of an AWS owned CMK using AWS Key Management Service
-- (KMS). Set to true by default, if no value is provided, for example, for
-- RabbitMQ brokers.
encryptionOptions_useAwsOwnedKey :: Lens.Lens' EncryptionOptions Prelude.Bool
encryptionOptions_useAwsOwnedKey :: Lens' EncryptionOptions Bool
encryptionOptions_useAwsOwnedKey = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionOptions' {Bool
useAwsOwnedKey :: Bool
$sel:useAwsOwnedKey:EncryptionOptions' :: EncryptionOptions -> Bool
useAwsOwnedKey} -> Bool
useAwsOwnedKey) (\s :: EncryptionOptions
s@EncryptionOptions' {} Bool
a -> EncryptionOptions
s {$sel:useAwsOwnedKey:EncryptionOptions' :: Bool
useAwsOwnedKey = Bool
a} :: EncryptionOptions)

instance Data.FromJSON EncryptionOptions where
  parseJSON :: Value -> Parser EncryptionOptions
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"EncryptionOptions"
      ( \Object
x ->
          Maybe Text -> Bool -> EncryptionOptions
EncryptionOptions'
            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
"kmsKeyId")
            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
"useAwsOwnedKey")
      )

instance Prelude.Hashable EncryptionOptions where
  hashWithSalt :: Int -> EncryptionOptions -> Int
hashWithSalt Int
_salt EncryptionOptions' {Bool
Maybe Text
useAwsOwnedKey :: Bool
kmsKeyId :: Maybe Text
$sel:useAwsOwnedKey:EncryptionOptions' :: EncryptionOptions -> Bool
$sel:kmsKeyId:EncryptionOptions' :: EncryptionOptions -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
kmsKeyId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Bool
useAwsOwnedKey

instance Prelude.NFData EncryptionOptions where
  rnf :: EncryptionOptions -> ()
rnf EncryptionOptions' {Bool
Maybe Text
useAwsOwnedKey :: Bool
kmsKeyId :: Maybe Text
$sel:useAwsOwnedKey:EncryptionOptions' :: EncryptionOptions -> Bool
$sel:kmsKeyId:EncryptionOptions' :: EncryptionOptions -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
kmsKeyId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Bool
useAwsOwnedKey

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