{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.AssociateEncryptionConfig
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Associate encryption configuration to an existing cluster.
--
-- You can use this API to enable encryption on existing clusters which do
-- not have encryption already enabled. This allows you to implement a
-- defense-in-depth security strategy without migrating applications to new
-- Amazon EKS clusters.
module Amazonka.EKS.AssociateEncryptionConfig
  ( -- * Creating a Request
    AssociateEncryptionConfig (..),
    newAssociateEncryptionConfig,

    -- * Request Lenses
    associateEncryptionConfig_clientRequestToken,
    associateEncryptionConfig_clusterName,
    associateEncryptionConfig_encryptionConfig,

    -- * Destructuring the Response
    AssociateEncryptionConfigResponse (..),
    newAssociateEncryptionConfigResponse,

    -- * Response Lenses
    associateEncryptionConfigResponse_update,
    associateEncryptionConfigResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.EKS.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newAssociateEncryptionConfig' smart constructor.
data AssociateEncryptionConfig = AssociateEncryptionConfig'
  { -- | The client request token you are using with the encryption
    -- configuration.
    AssociateEncryptionConfig -> Maybe Text
clientRequestToken :: Prelude.Maybe Prelude.Text,
    -- | The name of the cluster that you are associating with encryption
    -- configuration.
    AssociateEncryptionConfig -> Text
clusterName :: Prelude.Text,
    -- | The configuration you are using for encryption.
    AssociateEncryptionConfig -> [EncryptionConfig]
encryptionConfig :: [EncryptionConfig]
  }
  deriving (AssociateEncryptionConfig -> AssociateEncryptionConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateEncryptionConfig -> AssociateEncryptionConfig -> Bool
$c/= :: AssociateEncryptionConfig -> AssociateEncryptionConfig -> Bool
== :: AssociateEncryptionConfig -> AssociateEncryptionConfig -> Bool
$c== :: AssociateEncryptionConfig -> AssociateEncryptionConfig -> Bool
Prelude.Eq, ReadPrec [AssociateEncryptionConfig]
ReadPrec AssociateEncryptionConfig
Int -> ReadS AssociateEncryptionConfig
ReadS [AssociateEncryptionConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateEncryptionConfig]
$creadListPrec :: ReadPrec [AssociateEncryptionConfig]
readPrec :: ReadPrec AssociateEncryptionConfig
$creadPrec :: ReadPrec AssociateEncryptionConfig
readList :: ReadS [AssociateEncryptionConfig]
$creadList :: ReadS [AssociateEncryptionConfig]
readsPrec :: Int -> ReadS AssociateEncryptionConfig
$creadsPrec :: Int -> ReadS AssociateEncryptionConfig
Prelude.Read, Int -> AssociateEncryptionConfig -> ShowS
[AssociateEncryptionConfig] -> ShowS
AssociateEncryptionConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateEncryptionConfig] -> ShowS
$cshowList :: [AssociateEncryptionConfig] -> ShowS
show :: AssociateEncryptionConfig -> String
$cshow :: AssociateEncryptionConfig -> String
showsPrec :: Int -> AssociateEncryptionConfig -> ShowS
$cshowsPrec :: Int -> AssociateEncryptionConfig -> ShowS
Prelude.Show, forall x.
Rep AssociateEncryptionConfig x -> AssociateEncryptionConfig
forall x.
AssociateEncryptionConfig -> Rep AssociateEncryptionConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AssociateEncryptionConfig x -> AssociateEncryptionConfig
$cfrom :: forall x.
AssociateEncryptionConfig -> Rep AssociateEncryptionConfig x
Prelude.Generic)

-- |
-- Create a value of 'AssociateEncryptionConfig' 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:
--
-- 'clientRequestToken', 'associateEncryptionConfig_clientRequestToken' - The client request token you are using with the encryption
-- configuration.
--
-- 'clusterName', 'associateEncryptionConfig_clusterName' - The name of the cluster that you are associating with encryption
-- configuration.
--
-- 'encryptionConfig', 'associateEncryptionConfig_encryptionConfig' - The configuration you are using for encryption.
newAssociateEncryptionConfig ::
  -- | 'clusterName'
  Prelude.Text ->
  AssociateEncryptionConfig
newAssociateEncryptionConfig :: Text -> AssociateEncryptionConfig
newAssociateEncryptionConfig Text
pClusterName_ =
  AssociateEncryptionConfig'
    { $sel:clientRequestToken:AssociateEncryptionConfig' :: Maybe Text
clientRequestToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:clusterName:AssociateEncryptionConfig' :: Text
clusterName = Text
pClusterName_,
      $sel:encryptionConfig:AssociateEncryptionConfig' :: [EncryptionConfig]
encryptionConfig = forall a. Monoid a => a
Prelude.mempty
    }

-- | The client request token you are using with the encryption
-- configuration.
associateEncryptionConfig_clientRequestToken :: Lens.Lens' AssociateEncryptionConfig (Prelude.Maybe Prelude.Text)
associateEncryptionConfig_clientRequestToken :: Lens' AssociateEncryptionConfig (Maybe Text)
associateEncryptionConfig_clientRequestToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateEncryptionConfig' {Maybe Text
clientRequestToken :: Maybe Text
$sel:clientRequestToken:AssociateEncryptionConfig' :: AssociateEncryptionConfig -> Maybe Text
clientRequestToken} -> Maybe Text
clientRequestToken) (\s :: AssociateEncryptionConfig
s@AssociateEncryptionConfig' {} Maybe Text
a -> AssociateEncryptionConfig
s {$sel:clientRequestToken:AssociateEncryptionConfig' :: Maybe Text
clientRequestToken = Maybe Text
a} :: AssociateEncryptionConfig)

-- | The name of the cluster that you are associating with encryption
-- configuration.
associateEncryptionConfig_clusterName :: Lens.Lens' AssociateEncryptionConfig Prelude.Text
associateEncryptionConfig_clusterName :: Lens' AssociateEncryptionConfig Text
associateEncryptionConfig_clusterName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateEncryptionConfig' {Text
clusterName :: Text
$sel:clusterName:AssociateEncryptionConfig' :: AssociateEncryptionConfig -> Text
clusterName} -> Text
clusterName) (\s :: AssociateEncryptionConfig
s@AssociateEncryptionConfig' {} Text
a -> AssociateEncryptionConfig
s {$sel:clusterName:AssociateEncryptionConfig' :: Text
clusterName = Text
a} :: AssociateEncryptionConfig)

-- | The configuration you are using for encryption.
associateEncryptionConfig_encryptionConfig :: Lens.Lens' AssociateEncryptionConfig [EncryptionConfig]
associateEncryptionConfig_encryptionConfig :: Lens' AssociateEncryptionConfig [EncryptionConfig]
associateEncryptionConfig_encryptionConfig = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateEncryptionConfig' {[EncryptionConfig]
encryptionConfig :: [EncryptionConfig]
$sel:encryptionConfig:AssociateEncryptionConfig' :: AssociateEncryptionConfig -> [EncryptionConfig]
encryptionConfig} -> [EncryptionConfig]
encryptionConfig) (\s :: AssociateEncryptionConfig
s@AssociateEncryptionConfig' {} [EncryptionConfig]
a -> AssociateEncryptionConfig
s {$sel:encryptionConfig:AssociateEncryptionConfig' :: [EncryptionConfig]
encryptionConfig = [EncryptionConfig]
a} :: AssociateEncryptionConfig) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest AssociateEncryptionConfig where
  type
    AWSResponse AssociateEncryptionConfig =
      AssociateEncryptionConfigResponse
  request :: (Service -> Service)
-> AssociateEncryptionConfig -> Request AssociateEncryptionConfig
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy AssociateEncryptionConfig
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AssociateEncryptionConfig)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Update -> Int -> AssociateEncryptionConfigResponse
AssociateEncryptionConfigResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"update")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable AssociateEncryptionConfig where
  hashWithSalt :: Int -> AssociateEncryptionConfig -> Int
hashWithSalt Int
_salt AssociateEncryptionConfig' {[EncryptionConfig]
Maybe Text
Text
encryptionConfig :: [EncryptionConfig]
clusterName :: Text
clientRequestToken :: Maybe Text
$sel:encryptionConfig:AssociateEncryptionConfig' :: AssociateEncryptionConfig -> [EncryptionConfig]
$sel:clusterName:AssociateEncryptionConfig' :: AssociateEncryptionConfig -> Text
$sel:clientRequestToken:AssociateEncryptionConfig' :: AssociateEncryptionConfig -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
clientRequestToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
clusterName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [EncryptionConfig]
encryptionConfig

instance Prelude.NFData AssociateEncryptionConfig where
  rnf :: AssociateEncryptionConfig -> ()
rnf AssociateEncryptionConfig' {[EncryptionConfig]
Maybe Text
Text
encryptionConfig :: [EncryptionConfig]
clusterName :: Text
clientRequestToken :: Maybe Text
$sel:encryptionConfig:AssociateEncryptionConfig' :: AssociateEncryptionConfig -> [EncryptionConfig]
$sel:clusterName:AssociateEncryptionConfig' :: AssociateEncryptionConfig -> Text
$sel:clientRequestToken:AssociateEncryptionConfig' :: AssociateEncryptionConfig -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
clientRequestToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
clusterName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [EncryptionConfig]
encryptionConfig

instance Data.ToHeaders AssociateEncryptionConfig where
  toHeaders :: AssociateEncryptionConfig -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

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

instance Data.ToPath AssociateEncryptionConfig where
  toPath :: AssociateEncryptionConfig -> ByteString
toPath AssociateEncryptionConfig' {[EncryptionConfig]
Maybe Text
Text
encryptionConfig :: [EncryptionConfig]
clusterName :: Text
clientRequestToken :: Maybe Text
$sel:encryptionConfig:AssociateEncryptionConfig' :: AssociateEncryptionConfig -> [EncryptionConfig]
$sel:clusterName:AssociateEncryptionConfig' :: AssociateEncryptionConfig -> Text
$sel:clientRequestToken:AssociateEncryptionConfig' :: AssociateEncryptionConfig -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/clusters/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
clusterName,
        ByteString
"/encryption-config/associate"
      ]

instance Data.ToQuery AssociateEncryptionConfig where
  toQuery :: AssociateEncryptionConfig -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newAssociateEncryptionConfigResponse' smart constructor.
data AssociateEncryptionConfigResponse = AssociateEncryptionConfigResponse'
  { AssociateEncryptionConfigResponse -> Maybe Update
update :: Prelude.Maybe Update,
    -- | The response's http status code.
    AssociateEncryptionConfigResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AssociateEncryptionConfigResponse
-> AssociateEncryptionConfigResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssociateEncryptionConfigResponse
-> AssociateEncryptionConfigResponse -> Bool
$c/= :: AssociateEncryptionConfigResponse
-> AssociateEncryptionConfigResponse -> Bool
== :: AssociateEncryptionConfigResponse
-> AssociateEncryptionConfigResponse -> Bool
$c== :: AssociateEncryptionConfigResponse
-> AssociateEncryptionConfigResponse -> Bool
Prelude.Eq, ReadPrec [AssociateEncryptionConfigResponse]
ReadPrec AssociateEncryptionConfigResponse
Int -> ReadS AssociateEncryptionConfigResponse
ReadS [AssociateEncryptionConfigResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssociateEncryptionConfigResponse]
$creadListPrec :: ReadPrec [AssociateEncryptionConfigResponse]
readPrec :: ReadPrec AssociateEncryptionConfigResponse
$creadPrec :: ReadPrec AssociateEncryptionConfigResponse
readList :: ReadS [AssociateEncryptionConfigResponse]
$creadList :: ReadS [AssociateEncryptionConfigResponse]
readsPrec :: Int -> ReadS AssociateEncryptionConfigResponse
$creadsPrec :: Int -> ReadS AssociateEncryptionConfigResponse
Prelude.Read, Int -> AssociateEncryptionConfigResponse -> ShowS
[AssociateEncryptionConfigResponse] -> ShowS
AssociateEncryptionConfigResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssociateEncryptionConfigResponse] -> ShowS
$cshowList :: [AssociateEncryptionConfigResponse] -> ShowS
show :: AssociateEncryptionConfigResponse -> String
$cshow :: AssociateEncryptionConfigResponse -> String
showsPrec :: Int -> AssociateEncryptionConfigResponse -> ShowS
$cshowsPrec :: Int -> AssociateEncryptionConfigResponse -> ShowS
Prelude.Show, forall x.
Rep AssociateEncryptionConfigResponse x
-> AssociateEncryptionConfigResponse
forall x.
AssociateEncryptionConfigResponse
-> Rep AssociateEncryptionConfigResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AssociateEncryptionConfigResponse x
-> AssociateEncryptionConfigResponse
$cfrom :: forall x.
AssociateEncryptionConfigResponse
-> Rep AssociateEncryptionConfigResponse x
Prelude.Generic)

-- |
-- Create a value of 'AssociateEncryptionConfigResponse' 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:
--
-- 'update', 'associateEncryptionConfigResponse_update' - Undocumented member.
--
-- 'httpStatus', 'associateEncryptionConfigResponse_httpStatus' - The response's http status code.
newAssociateEncryptionConfigResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AssociateEncryptionConfigResponse
newAssociateEncryptionConfigResponse :: Int -> AssociateEncryptionConfigResponse
newAssociateEncryptionConfigResponse Int
pHttpStatus_ =
  AssociateEncryptionConfigResponse'
    { $sel:update:AssociateEncryptionConfigResponse' :: Maybe Update
update =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AssociateEncryptionConfigResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Undocumented member.
associateEncryptionConfigResponse_update :: Lens.Lens' AssociateEncryptionConfigResponse (Prelude.Maybe Update)
associateEncryptionConfigResponse_update :: Lens' AssociateEncryptionConfigResponse (Maybe Update)
associateEncryptionConfigResponse_update = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateEncryptionConfigResponse' {Maybe Update
update :: Maybe Update
$sel:update:AssociateEncryptionConfigResponse' :: AssociateEncryptionConfigResponse -> Maybe Update
update} -> Maybe Update
update) (\s :: AssociateEncryptionConfigResponse
s@AssociateEncryptionConfigResponse' {} Maybe Update
a -> AssociateEncryptionConfigResponse
s {$sel:update:AssociateEncryptionConfigResponse' :: Maybe Update
update = Maybe Update
a} :: AssociateEncryptionConfigResponse)

-- | The response's http status code.
associateEncryptionConfigResponse_httpStatus :: Lens.Lens' AssociateEncryptionConfigResponse Prelude.Int
associateEncryptionConfigResponse_httpStatus :: Lens' AssociateEncryptionConfigResponse Int
associateEncryptionConfigResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssociateEncryptionConfigResponse' {Int
httpStatus :: Int
$sel:httpStatus:AssociateEncryptionConfigResponse' :: AssociateEncryptionConfigResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: AssociateEncryptionConfigResponse
s@AssociateEncryptionConfigResponse' {} Int
a -> AssociateEncryptionConfigResponse
s {$sel:httpStatus:AssociateEncryptionConfigResponse' :: Int
httpStatus = Int
a} :: AssociateEncryptionConfigResponse)

instance
  Prelude.NFData
    AssociateEncryptionConfigResponse
  where
  rnf :: AssociateEncryptionConfigResponse -> ()
rnf AssociateEncryptionConfigResponse' {Int
Maybe Update
httpStatus :: Int
update :: Maybe Update
$sel:httpStatus:AssociateEncryptionConfigResponse' :: AssociateEncryptionConfigResponse -> Int
$sel:update:AssociateEncryptionConfigResponse' :: AssociateEncryptionConfigResponse -> Maybe Update
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Update
update
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus