{-# 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.EKS.Types.EncryptionConfig
-- 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.EKS.Types.EncryptionConfig where

import qualified Amazonka.Core as Core
import Amazonka.EKS.Types.Provider
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The encryption configuration for the cluster.
--
-- /See:/ 'newEncryptionConfig' smart constructor.
data EncryptionConfig = EncryptionConfig'
  { -- | Specifies the resources to be encrypted. The only supported value is
    -- \"secrets\".
    EncryptionConfig -> Maybe [Text]
resources :: Prelude.Maybe [Prelude.Text],
    -- | Key Management Service (KMS) key. Either the ARN or the alias can be
    -- used.
    EncryptionConfig -> Maybe Provider
provider :: Prelude.Maybe Provider
  }
  deriving (EncryptionConfig -> EncryptionConfig -> Bool
(EncryptionConfig -> EncryptionConfig -> Bool)
-> (EncryptionConfig -> EncryptionConfig -> Bool)
-> Eq EncryptionConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EncryptionConfig -> EncryptionConfig -> Bool
$c/= :: EncryptionConfig -> EncryptionConfig -> Bool
== :: EncryptionConfig -> EncryptionConfig -> Bool
$c== :: EncryptionConfig -> EncryptionConfig -> Bool
Prelude.Eq, ReadPrec [EncryptionConfig]
ReadPrec EncryptionConfig
Int -> ReadS EncryptionConfig
ReadS [EncryptionConfig]
(Int -> ReadS EncryptionConfig)
-> ReadS [EncryptionConfig]
-> ReadPrec EncryptionConfig
-> ReadPrec [EncryptionConfig]
-> Read EncryptionConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EncryptionConfig]
$creadListPrec :: ReadPrec [EncryptionConfig]
readPrec :: ReadPrec EncryptionConfig
$creadPrec :: ReadPrec EncryptionConfig
readList :: ReadS [EncryptionConfig]
$creadList :: ReadS [EncryptionConfig]
readsPrec :: Int -> ReadS EncryptionConfig
$creadsPrec :: Int -> ReadS EncryptionConfig
Prelude.Read, Int -> EncryptionConfig -> ShowS
[EncryptionConfig] -> ShowS
EncryptionConfig -> String
(Int -> EncryptionConfig -> ShowS)
-> (EncryptionConfig -> String)
-> ([EncryptionConfig] -> ShowS)
-> Show EncryptionConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EncryptionConfig] -> ShowS
$cshowList :: [EncryptionConfig] -> ShowS
show :: EncryptionConfig -> String
$cshow :: EncryptionConfig -> String
showsPrec :: Int -> EncryptionConfig -> ShowS
$cshowsPrec :: Int -> EncryptionConfig -> ShowS
Prelude.Show, (forall x. EncryptionConfig -> Rep EncryptionConfig x)
-> (forall x. Rep EncryptionConfig x -> EncryptionConfig)
-> Generic EncryptionConfig
forall x. Rep EncryptionConfig x -> EncryptionConfig
forall x. EncryptionConfig -> Rep EncryptionConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EncryptionConfig x -> EncryptionConfig
$cfrom :: forall x. EncryptionConfig -> Rep EncryptionConfig x
Prelude.Generic)

-- |
-- Create a value of 'EncryptionConfig' 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:
--
-- 'resources', 'encryptionConfig_resources' - Specifies the resources to be encrypted. The only supported value is
-- \"secrets\".
--
-- 'provider', 'encryptionConfig_provider' - Key Management Service (KMS) key. Either the ARN or the alias can be
-- used.
newEncryptionConfig ::
  EncryptionConfig
newEncryptionConfig :: EncryptionConfig
newEncryptionConfig =
  EncryptionConfig' :: Maybe [Text] -> Maybe Provider -> EncryptionConfig
EncryptionConfig'
    { $sel:resources:EncryptionConfig' :: Maybe [Text]
resources = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:provider:EncryptionConfig' :: Maybe Provider
provider = Maybe Provider
forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies the resources to be encrypted. The only supported value is
-- \"secrets\".
encryptionConfig_resources :: Lens.Lens' EncryptionConfig (Prelude.Maybe [Prelude.Text])
encryptionConfig_resources :: (Maybe [Text] -> f (Maybe [Text]))
-> EncryptionConfig -> f EncryptionConfig
encryptionConfig_resources = (EncryptionConfig -> Maybe [Text])
-> (EncryptionConfig -> Maybe [Text] -> EncryptionConfig)
-> Lens
     EncryptionConfig EncryptionConfig (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionConfig' {Maybe [Text]
resources :: Maybe [Text]
$sel:resources:EncryptionConfig' :: EncryptionConfig -> Maybe [Text]
resources} -> Maybe [Text]
resources) (\s :: EncryptionConfig
s@EncryptionConfig' {} Maybe [Text]
a -> EncryptionConfig
s {$sel:resources:EncryptionConfig' :: Maybe [Text]
resources = Maybe [Text]
a} :: EncryptionConfig) ((Maybe [Text] -> f (Maybe [Text]))
 -> EncryptionConfig -> f EncryptionConfig)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> EncryptionConfig
-> f EncryptionConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Key Management Service (KMS) key. Either the ARN or the alias can be
-- used.
encryptionConfig_provider :: Lens.Lens' EncryptionConfig (Prelude.Maybe Provider)
encryptionConfig_provider :: (Maybe Provider -> f (Maybe Provider))
-> EncryptionConfig -> f EncryptionConfig
encryptionConfig_provider = (EncryptionConfig -> Maybe Provider)
-> (EncryptionConfig -> Maybe Provider -> EncryptionConfig)
-> Lens
     EncryptionConfig EncryptionConfig (Maybe Provider) (Maybe Provider)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EncryptionConfig' {Maybe Provider
provider :: Maybe Provider
$sel:provider:EncryptionConfig' :: EncryptionConfig -> Maybe Provider
provider} -> Maybe Provider
provider) (\s :: EncryptionConfig
s@EncryptionConfig' {} Maybe Provider
a -> EncryptionConfig
s {$sel:provider:EncryptionConfig' :: Maybe Provider
provider = Maybe Provider
a} :: EncryptionConfig)

instance Core.FromJSON EncryptionConfig where
  parseJSON :: Value -> Parser EncryptionConfig
parseJSON =
    String
-> (Object -> Parser EncryptionConfig)
-> Value
-> Parser EncryptionConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EncryptionConfig"
      ( \Object
x ->
          Maybe [Text] -> Maybe Provider -> EncryptionConfig
EncryptionConfig'
            (Maybe [Text] -> Maybe Provider -> EncryptionConfig)
-> Parser (Maybe [Text])
-> Parser (Maybe Provider -> EncryptionConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"resources" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Provider -> EncryptionConfig)
-> Parser (Maybe Provider) -> Parser EncryptionConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Provider)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"provider")
      )

instance Prelude.Hashable EncryptionConfig

instance Prelude.NFData EncryptionConfig

instance Core.ToJSON EncryptionConfig where
  toJSON :: EncryptionConfig -> Value
toJSON EncryptionConfig' {Maybe [Text]
Maybe Provider
provider :: Maybe Provider
resources :: Maybe [Text]
$sel:provider:EncryptionConfig' :: EncryptionConfig -> Maybe Provider
$sel:resources:EncryptionConfig' :: EncryptionConfig -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"resources" 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]
resources,
            (Text
"provider" Text -> Provider -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Provider -> Pair) -> Maybe Provider -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Provider
provider
          ]
      )