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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(EncryptionOptions -> EncryptionOptions -> Bool)
-> (EncryptionOptions -> EncryptionOptions -> Bool)
-> Eq EncryptionOptions
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]
(Int -> ReadS EncryptionOptions)
-> ReadS [EncryptionOptions]
-> ReadPrec EncryptionOptions
-> ReadPrec [EncryptionOptions]
-> Read 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
(Int -> EncryptionOptions -> ShowS)
-> (EncryptionOptions -> String)
-> ([EncryptionOptions] -> ShowS)
-> Show EncryptionOptions
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. EncryptionOptions -> Rep EncryptionOptions x)
-> (forall x. Rep EncryptionOptions x -> EncryptionOptions)
-> Generic EncryptionOptions
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' :: Maybe Text -> Bool -> EncryptionOptions
EncryptionOptions'
    { $sel:kmsKeyId:EncryptionOptions' :: Maybe Text
kmsKeyId = Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> EncryptionOptions -> f EncryptionOptions
encryptionOptions_kmsKeyId = (EncryptionOptions -> Maybe Text)
-> (EncryptionOptions -> Maybe Text -> EncryptionOptions)
-> Lens
     EncryptionOptions EncryptionOptions (Maybe Text) (Maybe Text)
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 :: (Bool -> f Bool) -> EncryptionOptions -> f EncryptionOptions
encryptionOptions_useAwsOwnedKey = (EncryptionOptions -> Bool)
-> (EncryptionOptions -> Bool -> EncryptionOptions)
-> Lens EncryptionOptions EncryptionOptions Bool Bool
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 Core.FromJSON EncryptionOptions where
  parseJSON :: Value -> Parser EncryptionOptions
parseJSON =
    String
-> (Object -> Parser EncryptionOptions)
-> Value
-> Parser EncryptionOptions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EncryptionOptions"
      ( \Object
x ->
          Maybe Text -> Bool -> EncryptionOptions
EncryptionOptions'
            (Maybe Text -> Bool -> EncryptionOptions)
-> Parser (Maybe Text) -> Parser (Bool -> EncryptionOptions)
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 (Bool -> EncryptionOptions)
-> Parser Bool -> Parser EncryptionOptions
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Bool
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"useAwsOwnedKey")
      )

instance Prelude.Hashable EncryptionOptions

instance Prelude.NFData EncryptionOptions

instance Core.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
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
"useAwsOwnedKey" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Bool
useAwsOwnedKey)
          ]
      )