{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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 states of KMS keys>
-- 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 qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.KMS.Types
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
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]
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
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. 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' {$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 :: Lens' CancelKeyDeletion Text
cancelKeyDeletion_keyId = 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 :: (Service -> Service)
-> CancelKeyDeletion -> Request CancelKeyDeletion
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 CancelKeyDeletion
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CancelKeyDeletion)))
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 Text -> Int -> CancelKeyDeletionResponse
CancelKeyDeletionResponse'
            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
"KeyId")
            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 CancelKeyDeletion where
  hashWithSalt :: Int -> CancelKeyDeletion -> Int
hashWithSalt Int
_salt CancelKeyDeletion' {Text
keyId :: Text
$sel:keyId:CancelKeyDeletion' :: CancelKeyDeletion -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
keyId

instance Prelude.NFData CancelKeyDeletion where
  rnf :: CancelKeyDeletion -> ()
rnf CancelKeyDeletion' {Text
keyId :: Text
$sel:keyId:CancelKeyDeletion' :: CancelKeyDeletion -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
keyId

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

instance Data.ToJSON CancelKeyDeletion where
  toJSON :: CancelKeyDeletion -> Value
toJSON CancelKeyDeletion' {Text
keyId :: Text
$sel:keyId:CancelKeyDeletion' :: CancelKeyDeletion -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"KeyId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
keyId)]
      )

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

instance Data.ToQuery CancelKeyDeletion where
  toQuery :: CancelKeyDeletion -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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.
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'
    { $sel:keyId:CancelKeyDeletionResponse' :: Maybe Text
keyId = 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 :: Lens' CancelKeyDeletionResponse (Maybe Text)
cancelKeyDeletionResponse_keyId = 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 :: Lens' CancelKeyDeletionResponse Int
cancelKeyDeletionResponse_httpStatus = 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 where
  rnf :: CancelKeyDeletionResponse -> ()
rnf CancelKeyDeletionResponse' {Int
Maybe Text
httpStatus :: Int
keyId :: Maybe Text
$sel:httpStatus:CancelKeyDeletionResponse' :: CancelKeyDeletionResponse -> Int
$sel:keyId:CancelKeyDeletionResponse' :: CancelKeyDeletionResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
keyId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus