{-# 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.Kinesis.StartStreamEncryption
-- 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)
--
-- Enables or updates server-side encryption using an AWS KMS key for a
-- specified stream.
--
-- Starting encryption is an asynchronous operation. Upon receiving the
-- request, Kinesis Data Streams returns immediately and sets the status of
-- the stream to @UPDATING@. After the update is complete, Kinesis Data
-- Streams sets the status of the stream back to @ACTIVE@. Updating or
-- applying encryption normally takes a few seconds to complete, but it can
-- take minutes. You can continue to read and write data to your stream
-- while its status is @UPDATING@. Once the status of the stream is
-- @ACTIVE@, encryption begins for records written to the stream.
--
-- API Limits: You can successfully apply a new AWS KMS key for server-side
-- encryption 25 times in a rolling 24-hour period.
--
-- Note: It can take up to 5 seconds after the stream is in an @ACTIVE@
-- status before all records written to the stream are encrypted. After you
-- enable encryption, you can verify that encryption is applied by
-- inspecting the API response from @PutRecord@ or @PutRecords@.
module Amazonka.Kinesis.StartStreamEncryption
  ( -- * Creating a Request
    StartStreamEncryption (..),
    newStartStreamEncryption,

    -- * Request Lenses
    startStreamEncryption_streamName,
    startStreamEncryption_encryptionType,
    startStreamEncryption_keyId,

    -- * Destructuring the Response
    StartStreamEncryptionResponse (..),
    newStartStreamEncryptionResponse,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.Kinesis.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newStartStreamEncryption' smart constructor.
data StartStreamEncryption = StartStreamEncryption'
  { -- | The name of the stream for which to start encrypting records.
    StartStreamEncryption -> Text
streamName :: Prelude.Text,
    -- | The encryption type to use. The only valid value is @KMS@.
    StartStreamEncryption -> EncryptionType
encryptionType :: EncryptionType,
    -- | The GUID for the customer-managed AWS KMS key to use for encryption.
    -- This value can be a globally unique identifier, a fully specified Amazon
    -- Resource Name (ARN) to either an alias or a key, or an alias name
    -- prefixed by \"alias\/\".You can also use a master key owned by Kinesis
    -- Data Streams by specifying the alias @aws\/kinesis@.
    --
    -- -   Key ARN example:
    --     @arn:aws:kms:us-east-1:123456789012:key\/12345678-1234-1234-1234-123456789012@
    --
    -- -   Alias ARN example:
    --     @arn:aws:kms:us-east-1:123456789012:alias\/MyAliasName@
    --
    -- -   Globally unique key ID example:
    --     @12345678-1234-1234-1234-123456789012@
    --
    -- -   Alias name example: @alias\/MyAliasName@
    --
    -- -   Master key owned by Kinesis Data Streams: @alias\/aws\/kinesis@
    StartStreamEncryption -> Text
keyId :: Prelude.Text
  }
  deriving (StartStreamEncryption -> StartStreamEncryption -> Bool
(StartStreamEncryption -> StartStreamEncryption -> Bool)
-> (StartStreamEncryption -> StartStreamEncryption -> Bool)
-> Eq StartStreamEncryption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartStreamEncryption -> StartStreamEncryption -> Bool
$c/= :: StartStreamEncryption -> StartStreamEncryption -> Bool
== :: StartStreamEncryption -> StartStreamEncryption -> Bool
$c== :: StartStreamEncryption -> StartStreamEncryption -> Bool
Prelude.Eq, ReadPrec [StartStreamEncryption]
ReadPrec StartStreamEncryption
Int -> ReadS StartStreamEncryption
ReadS [StartStreamEncryption]
(Int -> ReadS StartStreamEncryption)
-> ReadS [StartStreamEncryption]
-> ReadPrec StartStreamEncryption
-> ReadPrec [StartStreamEncryption]
-> Read StartStreamEncryption
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartStreamEncryption]
$creadListPrec :: ReadPrec [StartStreamEncryption]
readPrec :: ReadPrec StartStreamEncryption
$creadPrec :: ReadPrec StartStreamEncryption
readList :: ReadS [StartStreamEncryption]
$creadList :: ReadS [StartStreamEncryption]
readsPrec :: Int -> ReadS StartStreamEncryption
$creadsPrec :: Int -> ReadS StartStreamEncryption
Prelude.Read, Int -> StartStreamEncryption -> ShowS
[StartStreamEncryption] -> ShowS
StartStreamEncryption -> String
(Int -> StartStreamEncryption -> ShowS)
-> (StartStreamEncryption -> String)
-> ([StartStreamEncryption] -> ShowS)
-> Show StartStreamEncryption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartStreamEncryption] -> ShowS
$cshowList :: [StartStreamEncryption] -> ShowS
show :: StartStreamEncryption -> String
$cshow :: StartStreamEncryption -> String
showsPrec :: Int -> StartStreamEncryption -> ShowS
$cshowsPrec :: Int -> StartStreamEncryption -> ShowS
Prelude.Show, (forall x. StartStreamEncryption -> Rep StartStreamEncryption x)
-> (forall x. Rep StartStreamEncryption x -> StartStreamEncryption)
-> Generic StartStreamEncryption
forall x. Rep StartStreamEncryption x -> StartStreamEncryption
forall x. StartStreamEncryption -> Rep StartStreamEncryption x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartStreamEncryption x -> StartStreamEncryption
$cfrom :: forall x. StartStreamEncryption -> Rep StartStreamEncryption x
Prelude.Generic)

-- |
-- Create a value of 'StartStreamEncryption' 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:
--
-- 'streamName', 'startStreamEncryption_streamName' - The name of the stream for which to start encrypting records.
--
-- 'encryptionType', 'startStreamEncryption_encryptionType' - The encryption type to use. The only valid value is @KMS@.
--
-- 'keyId', 'startStreamEncryption_keyId' - The GUID for the customer-managed AWS KMS key to use for encryption.
-- This value can be a globally unique identifier, a fully specified Amazon
-- Resource Name (ARN) to either an alias or a key, or an alias name
-- prefixed by \"alias\/\".You can also use a master key owned by Kinesis
-- Data Streams by specifying the alias @aws\/kinesis@.
--
-- -   Key ARN example:
--     @arn:aws:kms:us-east-1:123456789012:key\/12345678-1234-1234-1234-123456789012@
--
-- -   Alias ARN example:
--     @arn:aws:kms:us-east-1:123456789012:alias\/MyAliasName@
--
-- -   Globally unique key ID example:
--     @12345678-1234-1234-1234-123456789012@
--
-- -   Alias name example: @alias\/MyAliasName@
--
-- -   Master key owned by Kinesis Data Streams: @alias\/aws\/kinesis@
newStartStreamEncryption ::
  -- | 'streamName'
  Prelude.Text ->
  -- | 'encryptionType'
  EncryptionType ->
  -- | 'keyId'
  Prelude.Text ->
  StartStreamEncryption
newStartStreamEncryption :: Text -> EncryptionType -> Text -> StartStreamEncryption
newStartStreamEncryption
  Text
pStreamName_
  EncryptionType
pEncryptionType_
  Text
pKeyId_ =
    StartStreamEncryption' :: Text -> EncryptionType -> Text -> StartStreamEncryption
StartStreamEncryption'
      { $sel:streamName:StartStreamEncryption' :: Text
streamName = Text
pStreamName_,
        $sel:encryptionType:StartStreamEncryption' :: EncryptionType
encryptionType = EncryptionType
pEncryptionType_,
        $sel:keyId:StartStreamEncryption' :: Text
keyId = Text
pKeyId_
      }

-- | The name of the stream for which to start encrypting records.
startStreamEncryption_streamName :: Lens.Lens' StartStreamEncryption Prelude.Text
startStreamEncryption_streamName :: (Text -> f Text)
-> StartStreamEncryption -> f StartStreamEncryption
startStreamEncryption_streamName = (StartStreamEncryption -> Text)
-> (StartStreamEncryption -> Text -> StartStreamEncryption)
-> Lens StartStreamEncryption StartStreamEncryption Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartStreamEncryption' {Text
streamName :: Text
$sel:streamName:StartStreamEncryption' :: StartStreamEncryption -> Text
streamName} -> Text
streamName) (\s :: StartStreamEncryption
s@StartStreamEncryption' {} Text
a -> StartStreamEncryption
s {$sel:streamName:StartStreamEncryption' :: Text
streamName = Text
a} :: StartStreamEncryption)

-- | The encryption type to use. The only valid value is @KMS@.
startStreamEncryption_encryptionType :: Lens.Lens' StartStreamEncryption EncryptionType
startStreamEncryption_encryptionType :: (EncryptionType -> f EncryptionType)
-> StartStreamEncryption -> f StartStreamEncryption
startStreamEncryption_encryptionType = (StartStreamEncryption -> EncryptionType)
-> (StartStreamEncryption
    -> EncryptionType -> StartStreamEncryption)
-> Lens
     StartStreamEncryption
     StartStreamEncryption
     EncryptionType
     EncryptionType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartStreamEncryption' {EncryptionType
encryptionType :: EncryptionType
$sel:encryptionType:StartStreamEncryption' :: StartStreamEncryption -> EncryptionType
encryptionType} -> EncryptionType
encryptionType) (\s :: StartStreamEncryption
s@StartStreamEncryption' {} EncryptionType
a -> StartStreamEncryption
s {$sel:encryptionType:StartStreamEncryption' :: EncryptionType
encryptionType = EncryptionType
a} :: StartStreamEncryption)

-- | The GUID for the customer-managed AWS KMS key to use for encryption.
-- This value can be a globally unique identifier, a fully specified Amazon
-- Resource Name (ARN) to either an alias or a key, or an alias name
-- prefixed by \"alias\/\".You can also use a master key owned by Kinesis
-- Data Streams by specifying the alias @aws\/kinesis@.
--
-- -   Key ARN example:
--     @arn:aws:kms:us-east-1:123456789012:key\/12345678-1234-1234-1234-123456789012@
--
-- -   Alias ARN example:
--     @arn:aws:kms:us-east-1:123456789012:alias\/MyAliasName@
--
-- -   Globally unique key ID example:
--     @12345678-1234-1234-1234-123456789012@
--
-- -   Alias name example: @alias\/MyAliasName@
--
-- -   Master key owned by Kinesis Data Streams: @alias\/aws\/kinesis@
startStreamEncryption_keyId :: Lens.Lens' StartStreamEncryption Prelude.Text
startStreamEncryption_keyId :: (Text -> f Text)
-> StartStreamEncryption -> f StartStreamEncryption
startStreamEncryption_keyId = (StartStreamEncryption -> Text)
-> (StartStreamEncryption -> Text -> StartStreamEncryption)
-> Lens StartStreamEncryption StartStreamEncryption Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartStreamEncryption' {Text
keyId :: Text
$sel:keyId:StartStreamEncryption' :: StartStreamEncryption -> Text
keyId} -> Text
keyId) (\s :: StartStreamEncryption
s@StartStreamEncryption' {} Text
a -> StartStreamEncryption
s {$sel:keyId:StartStreamEncryption' :: Text
keyId = Text
a} :: StartStreamEncryption)

instance Core.AWSRequest StartStreamEncryption where
  type
    AWSResponse StartStreamEncryption =
      StartStreamEncryptionResponse
  request :: StartStreamEncryption -> Request StartStreamEncryption
request = Service -> StartStreamEncryption -> Request StartStreamEncryption
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StartStreamEncryption
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StartStreamEncryption)))
response =
    AWSResponse StartStreamEncryption
-> Logger
-> Service
-> Proxy StartStreamEncryption
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StartStreamEncryption)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse StartStreamEncryption
StartStreamEncryptionResponse
StartStreamEncryptionResponse'

instance Prelude.Hashable StartStreamEncryption

instance Prelude.NFData StartStreamEncryption

instance Core.ToHeaders StartStreamEncryption where
  toHeaders :: StartStreamEncryption -> [Header]
toHeaders =
    [Header] -> StartStreamEncryption -> [Header]
forall a b. a -> b -> a
Prelude.const
      ( [[Header]] -> [Header]
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> [Header]
forall a. ToHeader a => HeaderName -> a -> [Header]
Core.=# ( ByteString
"Kinesis_20131202.StartStreamEncryption" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> [Header]
forall a. ToHeader a => HeaderName -> a -> [Header]
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON StartStreamEncryption where
  toJSON :: StartStreamEncryption -> Value
toJSON StartStreamEncryption' {Text
EncryptionType
keyId :: Text
encryptionType :: EncryptionType
streamName :: Text
$sel:keyId:StartStreamEncryption' :: StartStreamEncryption -> Text
$sel:encryptionType:StartStreamEncryption' :: StartStreamEncryption -> EncryptionType
$sel:streamName:StartStreamEncryption' :: StartStreamEncryption -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"StreamName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
streamName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"EncryptionType" Text -> EncryptionType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= EncryptionType
encryptionType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"KeyId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
keyId)
          ]
      )

instance Core.ToPath StartStreamEncryption where
  toPath :: StartStreamEncryption -> ByteString
toPath = ByteString -> StartStreamEncryption -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newStartStreamEncryptionResponse' smart constructor.
data StartStreamEncryptionResponse = StartStreamEncryptionResponse'
  {
  }
  deriving (StartStreamEncryptionResponse
-> StartStreamEncryptionResponse -> Bool
(StartStreamEncryptionResponse
 -> StartStreamEncryptionResponse -> Bool)
-> (StartStreamEncryptionResponse
    -> StartStreamEncryptionResponse -> Bool)
-> Eq StartStreamEncryptionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartStreamEncryptionResponse
-> StartStreamEncryptionResponse -> Bool
$c/= :: StartStreamEncryptionResponse
-> StartStreamEncryptionResponse -> Bool
== :: StartStreamEncryptionResponse
-> StartStreamEncryptionResponse -> Bool
$c== :: StartStreamEncryptionResponse
-> StartStreamEncryptionResponse -> Bool
Prelude.Eq, ReadPrec [StartStreamEncryptionResponse]
ReadPrec StartStreamEncryptionResponse
Int -> ReadS StartStreamEncryptionResponse
ReadS [StartStreamEncryptionResponse]
(Int -> ReadS StartStreamEncryptionResponse)
-> ReadS [StartStreamEncryptionResponse]
-> ReadPrec StartStreamEncryptionResponse
-> ReadPrec [StartStreamEncryptionResponse]
-> Read StartStreamEncryptionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartStreamEncryptionResponse]
$creadListPrec :: ReadPrec [StartStreamEncryptionResponse]
readPrec :: ReadPrec StartStreamEncryptionResponse
$creadPrec :: ReadPrec StartStreamEncryptionResponse
readList :: ReadS [StartStreamEncryptionResponse]
$creadList :: ReadS [StartStreamEncryptionResponse]
readsPrec :: Int -> ReadS StartStreamEncryptionResponse
$creadsPrec :: Int -> ReadS StartStreamEncryptionResponse
Prelude.Read, Int -> StartStreamEncryptionResponse -> ShowS
[StartStreamEncryptionResponse] -> ShowS
StartStreamEncryptionResponse -> String
(Int -> StartStreamEncryptionResponse -> ShowS)
-> (StartStreamEncryptionResponse -> String)
-> ([StartStreamEncryptionResponse] -> ShowS)
-> Show StartStreamEncryptionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartStreamEncryptionResponse] -> ShowS
$cshowList :: [StartStreamEncryptionResponse] -> ShowS
show :: StartStreamEncryptionResponse -> String
$cshow :: StartStreamEncryptionResponse -> String
showsPrec :: Int -> StartStreamEncryptionResponse -> ShowS
$cshowsPrec :: Int -> StartStreamEncryptionResponse -> ShowS
Prelude.Show, (forall x.
 StartStreamEncryptionResponse
 -> Rep StartStreamEncryptionResponse x)
-> (forall x.
    Rep StartStreamEncryptionResponse x
    -> StartStreamEncryptionResponse)
-> Generic StartStreamEncryptionResponse
forall x.
Rep StartStreamEncryptionResponse x
-> StartStreamEncryptionResponse
forall x.
StartStreamEncryptionResponse
-> Rep StartStreamEncryptionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StartStreamEncryptionResponse x
-> StartStreamEncryptionResponse
$cfrom :: forall x.
StartStreamEncryptionResponse
-> Rep StartStreamEncryptionResponse x
Prelude.Generic)

-- |
-- Create a value of 'StartStreamEncryptionResponse' 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.
newStartStreamEncryptionResponse ::
  StartStreamEncryptionResponse
newStartStreamEncryptionResponse :: StartStreamEncryptionResponse
newStartStreamEncryptionResponse =
  StartStreamEncryptionResponse
StartStreamEncryptionResponse'

instance Prelude.NFData StartStreamEncryptionResponse