{-# 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.GetKeyRotationStatus
-- 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)
--
-- Gets a Boolean value that indicates whether
-- <https://docs.aws.amazon.com/kms/latest/developerguide/rotate-keys.html automatic rotation of the key material>
-- is enabled for the specified KMS key.
--
-- You cannot enable automatic rotation of
-- <https://docs.aws.amazon.com/kms/latest/developerguide/symm-asymm-concepts.html#asymmetric-cmks asymmetric KMS keys>,
-- KMS keys with
-- <https://docs.aws.amazon.com/kms/latest/developerguide/importing-keys.html imported key material>,
-- or KMS keys in a
-- <https://docs.aws.amazon.com/kms/latest/developerguide/custom-key-store-overview.html custom key store>.
-- To enable or disable automatic rotation of a set of related
-- <https://docs.aws.amazon.com/kms/latest/developerguide/multi-region-keys-overview.html#mrk-replica-key multi-Region keys>,
-- set the property on the primary key. The key rotation status for these
-- KMS keys is always @false@.
--
-- 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/.
--
-- -   Disabled: The key rotation status does not change when you disable a
--     KMS key. However, while the KMS key is disabled, KMS does not rotate
--     the key material.
--
-- -   Pending deletion: While a KMS key is pending deletion, its key
--     rotation status is @false@ and KMS does not rotate the key material.
--     If you cancel the deletion, the original key rotation status is
--     restored.
--
-- __Cross-account use__: Yes. To perform this operation on a KMS key in a
-- different Amazon Web Services account, specify the key ARN in the value
-- of the @KeyId@ parameter.
--
-- __Required permissions__:
-- <https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html kms:GetKeyRotationStatus>
-- (key policy)
--
-- __Related operations:__
--
-- -   DisableKeyRotation
--
-- -   EnableKeyRotation
module Amazonka.KMS.GetKeyRotationStatus
  ( -- * Creating a Request
    GetKeyRotationStatus (..),
    newGetKeyRotationStatus,

    -- * Request Lenses
    getKeyRotationStatus_keyId,

    -- * Destructuring the Response
    GetKeyRotationStatusResponse (..),
    newGetKeyRotationStatusResponse,

    -- * Response Lenses
    getKeyRotationStatusResponse_keyRotationEnabled,
    getKeyRotationStatusResponse_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:/ 'newGetKeyRotationStatus' smart constructor.
data GetKeyRotationStatus = GetKeyRotationStatus'
  { -- | Gets the rotation status for the specified KMS key.
    --
    -- Specify the key ID or key ARN of the KMS key. To specify a KMS key in a
    -- different Amazon Web Services account, you must use the key ARN.
    --
    -- 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.
    GetKeyRotationStatus -> Text
keyId :: Prelude.Text
  }
  deriving (GetKeyRotationStatus -> GetKeyRotationStatus -> Bool
(GetKeyRotationStatus -> GetKeyRotationStatus -> Bool)
-> (GetKeyRotationStatus -> GetKeyRotationStatus -> Bool)
-> Eq GetKeyRotationStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetKeyRotationStatus -> GetKeyRotationStatus -> Bool
$c/= :: GetKeyRotationStatus -> GetKeyRotationStatus -> Bool
== :: GetKeyRotationStatus -> GetKeyRotationStatus -> Bool
$c== :: GetKeyRotationStatus -> GetKeyRotationStatus -> Bool
Prelude.Eq, ReadPrec [GetKeyRotationStatus]
ReadPrec GetKeyRotationStatus
Int -> ReadS GetKeyRotationStatus
ReadS [GetKeyRotationStatus]
(Int -> ReadS GetKeyRotationStatus)
-> ReadS [GetKeyRotationStatus]
-> ReadPrec GetKeyRotationStatus
-> ReadPrec [GetKeyRotationStatus]
-> Read GetKeyRotationStatus
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetKeyRotationStatus]
$creadListPrec :: ReadPrec [GetKeyRotationStatus]
readPrec :: ReadPrec GetKeyRotationStatus
$creadPrec :: ReadPrec GetKeyRotationStatus
readList :: ReadS [GetKeyRotationStatus]
$creadList :: ReadS [GetKeyRotationStatus]
readsPrec :: Int -> ReadS GetKeyRotationStatus
$creadsPrec :: Int -> ReadS GetKeyRotationStatus
Prelude.Read, Int -> GetKeyRotationStatus -> ShowS
[GetKeyRotationStatus] -> ShowS
GetKeyRotationStatus -> String
(Int -> GetKeyRotationStatus -> ShowS)
-> (GetKeyRotationStatus -> String)
-> ([GetKeyRotationStatus] -> ShowS)
-> Show GetKeyRotationStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetKeyRotationStatus] -> ShowS
$cshowList :: [GetKeyRotationStatus] -> ShowS
show :: GetKeyRotationStatus -> String
$cshow :: GetKeyRotationStatus -> String
showsPrec :: Int -> GetKeyRotationStatus -> ShowS
$cshowsPrec :: Int -> GetKeyRotationStatus -> ShowS
Prelude.Show, (forall x. GetKeyRotationStatus -> Rep GetKeyRotationStatus x)
-> (forall x. Rep GetKeyRotationStatus x -> GetKeyRotationStatus)
-> Generic GetKeyRotationStatus
forall x. Rep GetKeyRotationStatus x -> GetKeyRotationStatus
forall x. GetKeyRotationStatus -> Rep GetKeyRotationStatus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetKeyRotationStatus x -> GetKeyRotationStatus
$cfrom :: forall x. GetKeyRotationStatus -> Rep GetKeyRotationStatus x
Prelude.Generic)

-- |
-- Create a value of 'GetKeyRotationStatus' 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', 'getKeyRotationStatus_keyId' - Gets the rotation status for the specified KMS key.
--
-- Specify the key ID or key ARN of the KMS key. To specify a KMS key in a
-- different Amazon Web Services account, you must use the key ARN.
--
-- 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.
newGetKeyRotationStatus ::
  -- | 'keyId'
  Prelude.Text ->
  GetKeyRotationStatus
newGetKeyRotationStatus :: Text -> GetKeyRotationStatus
newGetKeyRotationStatus Text
pKeyId_ =
  GetKeyRotationStatus' :: Text -> GetKeyRotationStatus
GetKeyRotationStatus' {$sel:keyId:GetKeyRotationStatus' :: Text
keyId = Text
pKeyId_}

-- | Gets the rotation status for the specified KMS key.
--
-- Specify the key ID or key ARN of the KMS key. To specify a KMS key in a
-- different Amazon Web Services account, you must use the key ARN.
--
-- 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.
getKeyRotationStatus_keyId :: Lens.Lens' GetKeyRotationStatus Prelude.Text
getKeyRotationStatus_keyId :: (Text -> f Text) -> GetKeyRotationStatus -> f GetKeyRotationStatus
getKeyRotationStatus_keyId = (GetKeyRotationStatus -> Text)
-> (GetKeyRotationStatus -> Text -> GetKeyRotationStatus)
-> Lens GetKeyRotationStatus GetKeyRotationStatus Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetKeyRotationStatus' {Text
keyId :: Text
$sel:keyId:GetKeyRotationStatus' :: GetKeyRotationStatus -> Text
keyId} -> Text
keyId) (\s :: GetKeyRotationStatus
s@GetKeyRotationStatus' {} Text
a -> GetKeyRotationStatus
s {$sel:keyId:GetKeyRotationStatus' :: Text
keyId = Text
a} :: GetKeyRotationStatus)

instance Core.AWSRequest GetKeyRotationStatus where
  type
    AWSResponse GetKeyRotationStatus =
      GetKeyRotationStatusResponse
  request :: GetKeyRotationStatus -> Request GetKeyRotationStatus
request = Service -> GetKeyRotationStatus -> Request GetKeyRotationStatus
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetKeyRotationStatus
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetKeyRotationStatus)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetKeyRotationStatus))
-> Logger
-> Service
-> Proxy GetKeyRotationStatus
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetKeyRotationStatus)))
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 Bool -> Int -> GetKeyRotationStatusResponse
GetKeyRotationStatusResponse'
            (Maybe Bool -> Int -> GetKeyRotationStatusResponse)
-> Either String (Maybe Bool)
-> Either String (Int -> GetKeyRotationStatusResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"KeyRotationEnabled")
            Either String (Int -> GetKeyRotationStatusResponse)
-> Either String Int -> Either String GetKeyRotationStatusResponse
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 GetKeyRotationStatus

instance Prelude.NFData GetKeyRotationStatus

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

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

-- | /See:/ 'newGetKeyRotationStatusResponse' smart constructor.
data GetKeyRotationStatusResponse = GetKeyRotationStatusResponse'
  { -- | A Boolean value that specifies whether key rotation is enabled.
    GetKeyRotationStatusResponse -> Maybe Bool
keyRotationEnabled :: Prelude.Maybe Prelude.Bool,
    -- | The response's http status code.
    GetKeyRotationStatusResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetKeyRotationStatusResponse
-> GetKeyRotationStatusResponse -> Bool
(GetKeyRotationStatusResponse
 -> GetKeyRotationStatusResponse -> Bool)
-> (GetKeyRotationStatusResponse
    -> GetKeyRotationStatusResponse -> Bool)
-> Eq GetKeyRotationStatusResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetKeyRotationStatusResponse
-> GetKeyRotationStatusResponse -> Bool
$c/= :: GetKeyRotationStatusResponse
-> GetKeyRotationStatusResponse -> Bool
== :: GetKeyRotationStatusResponse
-> GetKeyRotationStatusResponse -> Bool
$c== :: GetKeyRotationStatusResponse
-> GetKeyRotationStatusResponse -> Bool
Prelude.Eq, ReadPrec [GetKeyRotationStatusResponse]
ReadPrec GetKeyRotationStatusResponse
Int -> ReadS GetKeyRotationStatusResponse
ReadS [GetKeyRotationStatusResponse]
(Int -> ReadS GetKeyRotationStatusResponse)
-> ReadS [GetKeyRotationStatusResponse]
-> ReadPrec GetKeyRotationStatusResponse
-> ReadPrec [GetKeyRotationStatusResponse]
-> Read GetKeyRotationStatusResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetKeyRotationStatusResponse]
$creadListPrec :: ReadPrec [GetKeyRotationStatusResponse]
readPrec :: ReadPrec GetKeyRotationStatusResponse
$creadPrec :: ReadPrec GetKeyRotationStatusResponse
readList :: ReadS [GetKeyRotationStatusResponse]
$creadList :: ReadS [GetKeyRotationStatusResponse]
readsPrec :: Int -> ReadS GetKeyRotationStatusResponse
$creadsPrec :: Int -> ReadS GetKeyRotationStatusResponse
Prelude.Read, Int -> GetKeyRotationStatusResponse -> ShowS
[GetKeyRotationStatusResponse] -> ShowS
GetKeyRotationStatusResponse -> String
(Int -> GetKeyRotationStatusResponse -> ShowS)
-> (GetKeyRotationStatusResponse -> String)
-> ([GetKeyRotationStatusResponse] -> ShowS)
-> Show GetKeyRotationStatusResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetKeyRotationStatusResponse] -> ShowS
$cshowList :: [GetKeyRotationStatusResponse] -> ShowS
show :: GetKeyRotationStatusResponse -> String
$cshow :: GetKeyRotationStatusResponse -> String
showsPrec :: Int -> GetKeyRotationStatusResponse -> ShowS
$cshowsPrec :: Int -> GetKeyRotationStatusResponse -> ShowS
Prelude.Show, (forall x.
 GetKeyRotationStatusResponse -> Rep GetKeyRotationStatusResponse x)
-> (forall x.
    Rep GetKeyRotationStatusResponse x -> GetKeyRotationStatusResponse)
-> Generic GetKeyRotationStatusResponse
forall x.
Rep GetKeyRotationStatusResponse x -> GetKeyRotationStatusResponse
forall x.
GetKeyRotationStatusResponse -> Rep GetKeyRotationStatusResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetKeyRotationStatusResponse x -> GetKeyRotationStatusResponse
$cfrom :: forall x.
GetKeyRotationStatusResponse -> Rep GetKeyRotationStatusResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetKeyRotationStatusResponse' 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:
--
-- 'keyRotationEnabled', 'getKeyRotationStatusResponse_keyRotationEnabled' - A Boolean value that specifies whether key rotation is enabled.
--
-- 'httpStatus', 'getKeyRotationStatusResponse_httpStatus' - The response's http status code.
newGetKeyRotationStatusResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetKeyRotationStatusResponse
newGetKeyRotationStatusResponse :: Int -> GetKeyRotationStatusResponse
newGetKeyRotationStatusResponse Int
pHttpStatus_ =
  GetKeyRotationStatusResponse' :: Maybe Bool -> Int -> GetKeyRotationStatusResponse
GetKeyRotationStatusResponse'
    { $sel:keyRotationEnabled:GetKeyRotationStatusResponse' :: Maybe Bool
keyRotationEnabled =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetKeyRotationStatusResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A Boolean value that specifies whether key rotation is enabled.
getKeyRotationStatusResponse_keyRotationEnabled :: Lens.Lens' GetKeyRotationStatusResponse (Prelude.Maybe Prelude.Bool)
getKeyRotationStatusResponse_keyRotationEnabled :: (Maybe Bool -> f (Maybe Bool))
-> GetKeyRotationStatusResponse -> f GetKeyRotationStatusResponse
getKeyRotationStatusResponse_keyRotationEnabled = (GetKeyRotationStatusResponse -> Maybe Bool)
-> (GetKeyRotationStatusResponse
    -> Maybe Bool -> GetKeyRotationStatusResponse)
-> Lens
     GetKeyRotationStatusResponse
     GetKeyRotationStatusResponse
     (Maybe Bool)
     (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetKeyRotationStatusResponse' {Maybe Bool
keyRotationEnabled :: Maybe Bool
$sel:keyRotationEnabled:GetKeyRotationStatusResponse' :: GetKeyRotationStatusResponse -> Maybe Bool
keyRotationEnabled} -> Maybe Bool
keyRotationEnabled) (\s :: GetKeyRotationStatusResponse
s@GetKeyRotationStatusResponse' {} Maybe Bool
a -> GetKeyRotationStatusResponse
s {$sel:keyRotationEnabled:GetKeyRotationStatusResponse' :: Maybe Bool
keyRotationEnabled = Maybe Bool
a} :: GetKeyRotationStatusResponse)

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

instance Prelude.NFData GetKeyRotationStatusResponse