{-# 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.DisableKey
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Sets the state of a KMS key to disabled. This change temporarily
-- prevents use of the KMS key for
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#cryptographic-operations cryptographic operations>.
--
-- For more information about how key state affects the use of a KMS key,
-- see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html Key states of 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:DisableKey>
-- (key policy)
--
-- __Related operations__: EnableKey
module Amazonka.KMS.DisableKey
  ( -- * Creating a Request
    DisableKey (..),
    newDisableKey,

    -- * Request Lenses
    disableKey_keyId,

    -- * Destructuring the Response
    DisableKeyResponse (..),
    newDisableKeyResponse,
  )
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:/ 'newDisableKey' smart constructor.
data DisableKey = DisableKey'
  { -- | Identifies the KMS key to disable.
    --
    -- 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.
    DisableKey -> Text
keyId :: Prelude.Text
  }
  deriving (DisableKey -> DisableKey -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DisableKey -> DisableKey -> Bool
$c/= :: DisableKey -> DisableKey -> Bool
== :: DisableKey -> DisableKey -> Bool
$c== :: DisableKey -> DisableKey -> Bool
Prelude.Eq, ReadPrec [DisableKey]
ReadPrec DisableKey
Int -> ReadS DisableKey
ReadS [DisableKey]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DisableKey]
$creadListPrec :: ReadPrec [DisableKey]
readPrec :: ReadPrec DisableKey
$creadPrec :: ReadPrec DisableKey
readList :: ReadS [DisableKey]
$creadList :: ReadS [DisableKey]
readsPrec :: Int -> ReadS DisableKey
$creadsPrec :: Int -> ReadS DisableKey
Prelude.Read, Int -> DisableKey -> ShowS
[DisableKey] -> ShowS
DisableKey -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DisableKey] -> ShowS
$cshowList :: [DisableKey] -> ShowS
show :: DisableKey -> String
$cshow :: DisableKey -> String
showsPrec :: Int -> DisableKey -> ShowS
$cshowsPrec :: Int -> DisableKey -> ShowS
Prelude.Show, forall x. Rep DisableKey x -> DisableKey
forall x. DisableKey -> Rep DisableKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DisableKey x -> DisableKey
$cfrom :: forall x. DisableKey -> Rep DisableKey x
Prelude.Generic)

-- |
-- Create a value of 'DisableKey' 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', 'disableKey_keyId' - Identifies the KMS key to disable.
--
-- 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.
newDisableKey ::
  -- | 'keyId'
  Prelude.Text ->
  DisableKey
newDisableKey :: Text -> DisableKey
newDisableKey Text
pKeyId_ = DisableKey' {$sel:keyId:DisableKey' :: Text
keyId = Text
pKeyId_}

-- | Identifies the KMS key to disable.
--
-- 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.
disableKey_keyId :: Lens.Lens' DisableKey Prelude.Text
disableKey_keyId :: Lens' DisableKey Text
disableKey_keyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DisableKey' {Text
keyId :: Text
$sel:keyId:DisableKey' :: DisableKey -> Text
keyId} -> Text
keyId) (\s :: DisableKey
s@DisableKey' {} Text
a -> DisableKey
s {$sel:keyId:DisableKey' :: Text
keyId = Text
a} :: DisableKey)

instance Core.AWSRequest DisableKey where
  type AWSResponse DisableKey = DisableKeyResponse
  request :: (Service -> Service) -> DisableKey -> Request DisableKey
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 DisableKey
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DisableKey)))
response = forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull DisableKeyResponse
DisableKeyResponse'

instance Prelude.Hashable DisableKey where
  hashWithSalt :: Int -> DisableKey -> Int
hashWithSalt Int
_salt DisableKey' {Text
keyId :: Text
$sel:keyId:DisableKey' :: DisableKey -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
keyId

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

instance Data.ToHeaders DisableKey where
  toHeaders :: DisableKey -> [Header]
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 -> [Header]
Data.=# (ByteString
"TrentService.DisableKey" :: Prelude.ByteString),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> [Header]
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON DisableKey where
  toJSON :: DisableKey -> Value
toJSON DisableKey' {Text
keyId :: Text
$sel:keyId:DisableKey' :: DisableKey -> 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 DisableKey where
  toPath :: DisableKey -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

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

instance Prelude.NFData DisableKeyResponse where
  rnf :: DisableKeyResponse -> ()
rnf DisableKeyResponse
_ = ()