{-# 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.KMS.CancelKeyDeletion
-- 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)
--
-- Cancels the deletion of a KMS key. When this operation succeeds, the key
-- state of the KMS key is @Disabled@. To enable the KMS key, use
-- EnableKey.
--
-- For more information about scheduling and canceling deletion of a KMS
-- key, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/deleting-keys.html Deleting KMS keys>
-- in the /Key Management Service Developer Guide/.
--
-- The KMS key that you use for this operation must be in a compatible key
-- state. For details, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html Key state: Effect on your KMS key>
-- in the /Key Management Service Developer Guide/.
--
-- __Cross-account use__: No. You cannot perform this operation on a KMS
-- key in a different Amazon Web Services account.
--
-- __Required permissions__:
-- <https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html kms:CancelKeyDeletion>
-- (key policy)
--
-- __Related operations__: ScheduleKeyDeletion
module Amazonka.KMS.CancelKeyDeletion
  ( -- * Creating a Request
    CancelKeyDeletion (..),
    newCancelKeyDeletion,

    -- * Request Lenses
    cancelKeyDeletion_keyId,

    -- * Destructuring the Response
    CancelKeyDeletionResponse (..),
    newCancelKeyDeletionResponse,

    -- * Response Lenses
    cancelKeyDeletionResponse_keyId,
    cancelKeyDeletionResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.KMS.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:/ 'newCancelKeyDeletion' smart constructor.
data CancelKeyDeletion = CancelKeyDeletion'
  { -- | Identifies the KMS key whose deletion is being canceled.
    --
    -- Specify the key ID or key ARN of the KMS key.
    --
    -- For example:
    --
    -- -   Key ID: @1234abcd-12ab-34cd-56ef-1234567890ab@
    --
    -- -   Key ARN:
    --     @arn:aws:kms:us-east-2:111122223333:key\/1234abcd-12ab-34cd-56ef-1234567890ab@
    --
    -- To get the key ID and key ARN for a KMS key, use ListKeys or
    -- DescribeKey.
    CancelKeyDeletion -> Text
keyId :: Prelude.Text
  }
  deriving (CancelKeyDeletion -> CancelKeyDeletion -> Bool
(CancelKeyDeletion -> CancelKeyDeletion -> Bool)
-> (CancelKeyDeletion -> CancelKeyDeletion -> Bool)
-> Eq CancelKeyDeletion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelKeyDeletion -> CancelKeyDeletion -> Bool
$c/= :: CancelKeyDeletion -> CancelKeyDeletion -> Bool
== :: CancelKeyDeletion -> CancelKeyDeletion -> Bool
$c== :: CancelKeyDeletion -> CancelKeyDeletion -> Bool
Prelude.Eq, ReadPrec [CancelKeyDeletion]
ReadPrec CancelKeyDeletion
Int -> ReadS CancelKeyDeletion
ReadS [CancelKeyDeletion]
(Int -> ReadS CancelKeyDeletion)
-> ReadS [CancelKeyDeletion]
-> ReadPrec CancelKeyDeletion
-> ReadPrec [CancelKeyDeletion]
-> Read CancelKeyDeletion
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelKeyDeletion]
$creadListPrec :: ReadPrec [CancelKeyDeletion]
readPrec :: ReadPrec CancelKeyDeletion
$creadPrec :: ReadPrec CancelKeyDeletion
readList :: ReadS [CancelKeyDeletion]
$creadList :: ReadS [CancelKeyDeletion]
readsPrec :: Int -> ReadS CancelKeyDeletion
$creadsPrec :: Int -> ReadS CancelKeyDeletion
Prelude.Read, Int -> CancelKeyDeletion -> ShowS
[CancelKeyDeletion] -> ShowS
CancelKeyDeletion -> String
(Int -> CancelKeyDeletion -> ShowS)
-> (CancelKeyDeletion -> String)
-> ([CancelKeyDeletion] -> ShowS)
-> Show CancelKeyDeletion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelKeyDeletion] -> ShowS
$cshowList :: [CancelKeyDeletion] -> ShowS
show :: CancelKeyDeletion -> String
$cshow :: CancelKeyDeletion -> String
showsPrec :: Int -> CancelKeyDeletion -> ShowS
$cshowsPrec :: Int -> CancelKeyDeletion -> ShowS
Prelude.Show, (forall x. CancelKeyDeletion -> Rep CancelKeyDeletion x)
-> (forall x. Rep CancelKeyDeletion x -> CancelKeyDeletion)
-> Generic CancelKeyDeletion
forall x. Rep CancelKeyDeletion x -> CancelKeyDeletion
forall x. CancelKeyDeletion -> Rep CancelKeyDeletion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CancelKeyDeletion x -> CancelKeyDeletion
$cfrom :: forall x. CancelKeyDeletion -> Rep CancelKeyDeletion x
Prelude.Generic)

-- |
-- Create a value of 'CancelKeyDeletion' 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:
--
-- 'keyId', 'cancelKeyDeletion_keyId' - Identifies the KMS key whose deletion is being canceled.
--
-- Specify the key ID or key ARN of the KMS key.
--
-- For example:
--
-- -   Key ID: @1234abcd-12ab-34cd-56ef-1234567890ab@
--
-- -   Key ARN:
--     @arn:aws:kms:us-east-2:111122223333:key\/1234abcd-12ab-34cd-56ef-1234567890ab@
--
-- To get the key ID and key ARN for a KMS key, use ListKeys or
-- DescribeKey.
newCancelKeyDeletion ::
  -- | 'keyId'
  Prelude.Text ->
  CancelKeyDeletion
newCancelKeyDeletion :: Text -> CancelKeyDeletion
newCancelKeyDeletion Text
pKeyId_ =
  CancelKeyDeletion' :: Text -> CancelKeyDeletion
CancelKeyDeletion' {$sel:keyId:CancelKeyDeletion' :: Text
keyId = Text
pKeyId_}

-- | Identifies the KMS key whose deletion is being canceled.
--
-- Specify the key ID or key ARN of the KMS key.
--
-- For example:
--
-- -   Key ID: @1234abcd-12ab-34cd-56ef-1234567890ab@
--
-- -   Key ARN:
--     @arn:aws:kms:us-east-2:111122223333:key\/1234abcd-12ab-34cd-56ef-1234567890ab@
--
-- To get the key ID and key ARN for a KMS key, use ListKeys or
-- DescribeKey.
cancelKeyDeletion_keyId :: Lens.Lens' CancelKeyDeletion Prelude.Text
cancelKeyDeletion_keyId :: (Text -> f Text) -> CancelKeyDeletion -> f CancelKeyDeletion
cancelKeyDeletion_keyId = (CancelKeyDeletion -> Text)
-> (CancelKeyDeletion -> Text -> CancelKeyDeletion)
-> Lens CancelKeyDeletion CancelKeyDeletion Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelKeyDeletion' {Text
keyId :: Text
$sel:keyId:CancelKeyDeletion' :: CancelKeyDeletion -> Text
keyId} -> Text
keyId) (\s :: CancelKeyDeletion
s@CancelKeyDeletion' {} Text
a -> CancelKeyDeletion
s {$sel:keyId:CancelKeyDeletion' :: Text
keyId = Text
a} :: CancelKeyDeletion)

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

instance Prelude.Hashable CancelKeyDeletion

instance Prelude.NFData CancelKeyDeletion

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

instance Core.ToJSON CancelKeyDeletion where
  toJSON :: CancelKeyDeletion -> Value
toJSON CancelKeyDeletion' {Text
keyId :: Text
$sel:keyId:CancelKeyDeletion' :: CancelKeyDeletion -> 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
"KeyId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
keyId)]
      )

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

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

-- | /See:/ 'newCancelKeyDeletionResponse' smart constructor.
data CancelKeyDeletionResponse = CancelKeyDeletionResponse'
  { -- | The Amazon Resource Name
    -- (<https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id-key-ARN key ARN>)
    -- of the KMS key whose deletion is canceled.
    CancelKeyDeletionResponse -> Maybe Text
keyId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CancelKeyDeletionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CancelKeyDeletionResponse -> CancelKeyDeletionResponse -> Bool
(CancelKeyDeletionResponse -> CancelKeyDeletionResponse -> Bool)
-> (CancelKeyDeletionResponse -> CancelKeyDeletionResponse -> Bool)
-> Eq CancelKeyDeletionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CancelKeyDeletionResponse -> CancelKeyDeletionResponse -> Bool
$c/= :: CancelKeyDeletionResponse -> CancelKeyDeletionResponse -> Bool
== :: CancelKeyDeletionResponse -> CancelKeyDeletionResponse -> Bool
$c== :: CancelKeyDeletionResponse -> CancelKeyDeletionResponse -> Bool
Prelude.Eq, ReadPrec [CancelKeyDeletionResponse]
ReadPrec CancelKeyDeletionResponse
Int -> ReadS CancelKeyDeletionResponse
ReadS [CancelKeyDeletionResponse]
(Int -> ReadS CancelKeyDeletionResponse)
-> ReadS [CancelKeyDeletionResponse]
-> ReadPrec CancelKeyDeletionResponse
-> ReadPrec [CancelKeyDeletionResponse]
-> Read CancelKeyDeletionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CancelKeyDeletionResponse]
$creadListPrec :: ReadPrec [CancelKeyDeletionResponse]
readPrec :: ReadPrec CancelKeyDeletionResponse
$creadPrec :: ReadPrec CancelKeyDeletionResponse
readList :: ReadS [CancelKeyDeletionResponse]
$creadList :: ReadS [CancelKeyDeletionResponse]
readsPrec :: Int -> ReadS CancelKeyDeletionResponse
$creadsPrec :: Int -> ReadS CancelKeyDeletionResponse
Prelude.Read, Int -> CancelKeyDeletionResponse -> ShowS
[CancelKeyDeletionResponse] -> ShowS
CancelKeyDeletionResponse -> String
(Int -> CancelKeyDeletionResponse -> ShowS)
-> (CancelKeyDeletionResponse -> String)
-> ([CancelKeyDeletionResponse] -> ShowS)
-> Show CancelKeyDeletionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CancelKeyDeletionResponse] -> ShowS
$cshowList :: [CancelKeyDeletionResponse] -> ShowS
show :: CancelKeyDeletionResponse -> String
$cshow :: CancelKeyDeletionResponse -> String
showsPrec :: Int -> CancelKeyDeletionResponse -> ShowS
$cshowsPrec :: Int -> CancelKeyDeletionResponse -> ShowS
Prelude.Show, (forall x.
 CancelKeyDeletionResponse -> Rep CancelKeyDeletionResponse x)
-> (forall x.
    Rep CancelKeyDeletionResponse x -> CancelKeyDeletionResponse)
-> Generic CancelKeyDeletionResponse
forall x.
Rep CancelKeyDeletionResponse x -> CancelKeyDeletionResponse
forall x.
CancelKeyDeletionResponse -> Rep CancelKeyDeletionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CancelKeyDeletionResponse x -> CancelKeyDeletionResponse
$cfrom :: forall x.
CancelKeyDeletionResponse -> Rep CancelKeyDeletionResponse x
Prelude.Generic)

-- |
-- Create a value of 'CancelKeyDeletionResponse' 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:
--
-- 'keyId', 'cancelKeyDeletionResponse_keyId' - The Amazon Resource Name
-- (<https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id-key-ARN key ARN>)
-- of the KMS key whose deletion is canceled.
--
-- 'httpStatus', 'cancelKeyDeletionResponse_httpStatus' - The response's http status code.
newCancelKeyDeletionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CancelKeyDeletionResponse
newCancelKeyDeletionResponse :: Int -> CancelKeyDeletionResponse
newCancelKeyDeletionResponse Int
pHttpStatus_ =
  CancelKeyDeletionResponse' :: Maybe Text -> Int -> CancelKeyDeletionResponse
CancelKeyDeletionResponse'
    { $sel:keyId:CancelKeyDeletionResponse' :: Maybe Text
keyId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CancelKeyDeletionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Amazon Resource Name
-- (<https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id-key-ARN key ARN>)
-- of the KMS key whose deletion is canceled.
cancelKeyDeletionResponse_keyId :: Lens.Lens' CancelKeyDeletionResponse (Prelude.Maybe Prelude.Text)
cancelKeyDeletionResponse_keyId :: (Maybe Text -> f (Maybe Text))
-> CancelKeyDeletionResponse -> f CancelKeyDeletionResponse
cancelKeyDeletionResponse_keyId = (CancelKeyDeletionResponse -> Maybe Text)
-> (CancelKeyDeletionResponse
    -> Maybe Text -> CancelKeyDeletionResponse)
-> Lens
     CancelKeyDeletionResponse
     CancelKeyDeletionResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CancelKeyDeletionResponse' {Maybe Text
keyId :: Maybe Text
$sel:keyId:CancelKeyDeletionResponse' :: CancelKeyDeletionResponse -> Maybe Text
keyId} -> Maybe Text
keyId) (\s :: CancelKeyDeletionResponse
s@CancelKeyDeletionResponse' {} Maybe Text
a -> CancelKeyDeletionResponse
s {$sel:keyId:CancelKeyDeletionResponse' :: Maybe Text
keyId = Maybe Text
a} :: CancelKeyDeletionResponse)

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

instance Prelude.NFData CancelKeyDeletionResponse