{-# 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.DeleteCustomKeyStore
-- 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)
--
-- Deletes a
-- <https://docs.aws.amazon.com/kms/latest/developerguide/custom-key-store-overview.html custom key store>.
-- This operation does not delete the CloudHSM cluster that is associated
-- with the custom key store, or affect any users or keys in the cluster.
--
-- The custom key store that you delete cannot contain any KMS
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#kms_keys KMS keys>.
-- Before deleting the key store, verify that you will never need to use
-- any of the KMS keys in the key store for any
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#cryptographic-operations cryptographic operations>.
-- Then, use ScheduleKeyDeletion to delete the KMS keys from the key store.
-- When the scheduled waiting period expires, the @ScheduleKeyDeletion@
-- operation deletes the KMS keys. Then it makes a best effort to delete
-- the key material from the associated cluster. However, you might need to
-- manually
-- <https://docs.aws.amazon.com/kms/latest/developerguide/fix-keystore.html#fix-keystore-orphaned-key delete the orphaned key material>
-- from the cluster and its backups.
--
-- After all KMS keys are deleted from KMS, use DisconnectCustomKeyStore to
-- disconnect the key store from KMS. Then, you can delete the custom key
-- store.
--
-- Instead of deleting the custom key store, consider using
-- DisconnectCustomKeyStore to disconnect it from KMS. While the key store
-- is disconnected, you cannot create or use the KMS keys in the key store.
-- But, you do not need to delete KMS keys and you can reconnect a
-- disconnected custom key store at any time.
--
-- If the operation succeeds, it returns a JSON object with no properties.
--
-- This operation is part of the
-- <https://docs.aws.amazon.com/kms/latest/developerguide/custom-key-store-overview.html Custom Key Store feature>
-- feature in KMS, which combines the convenience and extensive integration
-- of KMS with the isolation and control of a single-tenant key store.
--
-- __Cross-account use__: No. You cannot perform this operation on a custom
-- key store in a different Amazon Web Services account.
--
-- __Required permissions__:
-- <https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html kms:DeleteCustomKeyStore>
-- (IAM policy)
--
-- __Related operations:__
--
-- -   ConnectCustomKeyStore
--
-- -   CreateCustomKeyStore
--
-- -   DescribeCustomKeyStores
--
-- -   DisconnectCustomKeyStore
--
-- -   UpdateCustomKeyStore
module Amazonka.KMS.DeleteCustomKeyStore
  ( -- * Creating a Request
    DeleteCustomKeyStore (..),
    newDeleteCustomKeyStore,

    -- * Request Lenses
    deleteCustomKeyStore_customKeyStoreId,

    -- * Destructuring the Response
    DeleteCustomKeyStoreResponse (..),
    newDeleteCustomKeyStoreResponse,

    -- * Response Lenses
    deleteCustomKeyStoreResponse_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:/ 'newDeleteCustomKeyStore' smart constructor.
data DeleteCustomKeyStore = DeleteCustomKeyStore'
  { -- | Enter the ID of the custom key store you want to delete. To find the ID
    -- of a custom key store, use the DescribeCustomKeyStores operation.
    DeleteCustomKeyStore -> Text
customKeyStoreId :: Prelude.Text
  }
  deriving (DeleteCustomKeyStore -> DeleteCustomKeyStore -> Bool
(DeleteCustomKeyStore -> DeleteCustomKeyStore -> Bool)
-> (DeleteCustomKeyStore -> DeleteCustomKeyStore -> Bool)
-> Eq DeleteCustomKeyStore
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteCustomKeyStore -> DeleteCustomKeyStore -> Bool
$c/= :: DeleteCustomKeyStore -> DeleteCustomKeyStore -> Bool
== :: DeleteCustomKeyStore -> DeleteCustomKeyStore -> Bool
$c== :: DeleteCustomKeyStore -> DeleteCustomKeyStore -> Bool
Prelude.Eq, ReadPrec [DeleteCustomKeyStore]
ReadPrec DeleteCustomKeyStore
Int -> ReadS DeleteCustomKeyStore
ReadS [DeleteCustomKeyStore]
(Int -> ReadS DeleteCustomKeyStore)
-> ReadS [DeleteCustomKeyStore]
-> ReadPrec DeleteCustomKeyStore
-> ReadPrec [DeleteCustomKeyStore]
-> Read DeleteCustomKeyStore
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteCustomKeyStore]
$creadListPrec :: ReadPrec [DeleteCustomKeyStore]
readPrec :: ReadPrec DeleteCustomKeyStore
$creadPrec :: ReadPrec DeleteCustomKeyStore
readList :: ReadS [DeleteCustomKeyStore]
$creadList :: ReadS [DeleteCustomKeyStore]
readsPrec :: Int -> ReadS DeleteCustomKeyStore
$creadsPrec :: Int -> ReadS DeleteCustomKeyStore
Prelude.Read, Int -> DeleteCustomKeyStore -> ShowS
[DeleteCustomKeyStore] -> ShowS
DeleteCustomKeyStore -> String
(Int -> DeleteCustomKeyStore -> ShowS)
-> (DeleteCustomKeyStore -> String)
-> ([DeleteCustomKeyStore] -> ShowS)
-> Show DeleteCustomKeyStore
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteCustomKeyStore] -> ShowS
$cshowList :: [DeleteCustomKeyStore] -> ShowS
show :: DeleteCustomKeyStore -> String
$cshow :: DeleteCustomKeyStore -> String
showsPrec :: Int -> DeleteCustomKeyStore -> ShowS
$cshowsPrec :: Int -> DeleteCustomKeyStore -> ShowS
Prelude.Show, (forall x. DeleteCustomKeyStore -> Rep DeleteCustomKeyStore x)
-> (forall x. Rep DeleteCustomKeyStore x -> DeleteCustomKeyStore)
-> Generic DeleteCustomKeyStore
forall x. Rep DeleteCustomKeyStore x -> DeleteCustomKeyStore
forall x. DeleteCustomKeyStore -> Rep DeleteCustomKeyStore x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteCustomKeyStore x -> DeleteCustomKeyStore
$cfrom :: forall x. DeleteCustomKeyStore -> Rep DeleteCustomKeyStore x
Prelude.Generic)

-- |
-- Create a value of 'DeleteCustomKeyStore' 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:
--
-- 'customKeyStoreId', 'deleteCustomKeyStore_customKeyStoreId' - Enter the ID of the custom key store you want to delete. To find the ID
-- of a custom key store, use the DescribeCustomKeyStores operation.
newDeleteCustomKeyStore ::
  -- | 'customKeyStoreId'
  Prelude.Text ->
  DeleteCustomKeyStore
newDeleteCustomKeyStore :: Text -> DeleteCustomKeyStore
newDeleteCustomKeyStore Text
pCustomKeyStoreId_ =
  DeleteCustomKeyStore' :: Text -> DeleteCustomKeyStore
DeleteCustomKeyStore'
    { $sel:customKeyStoreId:DeleteCustomKeyStore' :: Text
customKeyStoreId =
        Text
pCustomKeyStoreId_
    }

-- | Enter the ID of the custom key store you want to delete. To find the ID
-- of a custom key store, use the DescribeCustomKeyStores operation.
deleteCustomKeyStore_customKeyStoreId :: Lens.Lens' DeleteCustomKeyStore Prelude.Text
deleteCustomKeyStore_customKeyStoreId :: (Text -> f Text) -> DeleteCustomKeyStore -> f DeleteCustomKeyStore
deleteCustomKeyStore_customKeyStoreId = (DeleteCustomKeyStore -> Text)
-> (DeleteCustomKeyStore -> Text -> DeleteCustomKeyStore)
-> Lens DeleteCustomKeyStore DeleteCustomKeyStore Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteCustomKeyStore' {Text
customKeyStoreId :: Text
$sel:customKeyStoreId:DeleteCustomKeyStore' :: DeleteCustomKeyStore -> Text
customKeyStoreId} -> Text
customKeyStoreId) (\s :: DeleteCustomKeyStore
s@DeleteCustomKeyStore' {} Text
a -> DeleteCustomKeyStore
s {$sel:customKeyStoreId:DeleteCustomKeyStore' :: Text
customKeyStoreId = Text
a} :: DeleteCustomKeyStore)

instance Core.AWSRequest DeleteCustomKeyStore where
  type
    AWSResponse DeleteCustomKeyStore =
      DeleteCustomKeyStoreResponse
  request :: DeleteCustomKeyStore -> Request DeleteCustomKeyStore
request = Service -> DeleteCustomKeyStore -> Request DeleteCustomKeyStore
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DeleteCustomKeyStore
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeleteCustomKeyStore)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse DeleteCustomKeyStore))
-> Logger
-> Service
-> Proxy DeleteCustomKeyStore
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeleteCustomKeyStore)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> DeleteCustomKeyStoreResponse
DeleteCustomKeyStoreResponse'
            (Int -> DeleteCustomKeyStoreResponse)
-> Either String Int -> Either String DeleteCustomKeyStoreResponse
forall (f :: * -> *) a b. Functor 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 DeleteCustomKeyStore

instance Prelude.NFData DeleteCustomKeyStore

instance Core.ToHeaders DeleteCustomKeyStore where
  toHeaders :: DeleteCustomKeyStore -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DeleteCustomKeyStore -> 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.DeleteCustomKeyStore" ::
                          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 DeleteCustomKeyStore where
  toJSON :: DeleteCustomKeyStore -> Value
toJSON DeleteCustomKeyStore' {Text
customKeyStoreId :: Text
$sel:customKeyStoreId:DeleteCustomKeyStore' :: DeleteCustomKeyStore -> 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
"CustomKeyStoreId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
customKeyStoreId)
          ]
      )

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

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

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

-- |
-- Create a value of 'DeleteCustomKeyStoreResponse' 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:
--
-- 'httpStatus', 'deleteCustomKeyStoreResponse_httpStatus' - The response's http status code.
newDeleteCustomKeyStoreResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeleteCustomKeyStoreResponse
newDeleteCustomKeyStoreResponse :: Int -> DeleteCustomKeyStoreResponse
newDeleteCustomKeyStoreResponse Int
pHttpStatus_ =
  DeleteCustomKeyStoreResponse' :: Int -> DeleteCustomKeyStoreResponse
DeleteCustomKeyStoreResponse'
    { $sel:httpStatus:DeleteCustomKeyStoreResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData DeleteCustomKeyStoreResponse