{-# 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-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)
--
-- 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 state: Effect on your KMS key>
-- 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: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 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:/ '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
(DisableKey -> DisableKey -> Bool)
-> (DisableKey -> DisableKey -> Bool) -> Eq DisableKey
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]
(Int -> ReadS DisableKey)
-> ReadS [DisableKey]
-> ReadPrec DisableKey
-> ReadPrec [DisableKey]
-> Read 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
(Int -> DisableKey -> ShowS)
-> (DisableKey -> String)
-> ([DisableKey] -> ShowS)
-> Show DisableKey
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. DisableKey -> Rep DisableKey x)
-> (forall x. Rep DisableKey x -> DisableKey) -> Generic DisableKey
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' :: Text -> DisableKey
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 :: (Text -> f Text) -> DisableKey -> f DisableKey
disableKey_keyId = (DisableKey -> Text)
-> (DisableKey -> Text -> DisableKey)
-> Lens DisableKey DisableKey Text Text
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 :: DisableKey -> Request DisableKey
request = Service -> DisableKey -> Request DisableKey
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DisableKey
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DisableKey)))
response = AWSResponse DisableKey
-> Logger
-> Service
-> Proxy DisableKey
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DisableKey)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse DisableKey
DisableKeyResponse
DisableKeyResponse'

instance Prelude.Hashable DisableKey

instance Prelude.NFData DisableKey

instance Core.ToHeaders DisableKey where
  toHeaders :: DisableKey -> [Header]
toHeaders =
    [Header] -> DisableKey -> [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
"TrentService.DisableKey" :: 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 DisableKey where
  toJSON :: DisableKey -> Value
toJSON DisableKey' {Text
keyId :: Text
$sel:keyId:DisableKey' :: DisableKey -> 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 DisableKey where
  toPath :: DisableKey -> ByteString
toPath = ByteString -> DisableKey -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newDisableKeyResponse' smart constructor.
data DisableKeyResponse = DisableKeyResponse'
  {
  }
  deriving (DisableKeyResponse -> DisableKeyResponse -> Bool
(DisableKeyResponse -> DisableKeyResponse -> Bool)
-> (DisableKeyResponse -> DisableKeyResponse -> Bool)
-> Eq DisableKeyResponse
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]
(Int -> ReadS DisableKeyResponse)
-> ReadS [DisableKeyResponse]
-> ReadPrec DisableKeyResponse
-> ReadPrec [DisableKeyResponse]
-> Read 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
(Int -> DisableKeyResponse -> ShowS)
-> (DisableKeyResponse -> String)
-> ([DisableKeyResponse] -> ShowS)
-> Show DisableKeyResponse
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. DisableKeyResponse -> Rep DisableKeyResponse x)
-> (forall x. Rep DisableKeyResponse x -> DisableKeyResponse)
-> Generic DisableKeyResponse
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