{-# 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.ConnectCustomKeyStore
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Connects or reconnects a
-- <https://docs.aws.amazon.com/kms/latest/developerguide/custom-key-store-overview.html custom key store>
-- to its backing key store. For an CloudHSM key store,
-- @ConnectCustomKeyStore@ connects the key store to its associated
-- CloudHSM cluster. For an external key store, @ConnectCustomKeyStore@
-- connects the key store to the external key store proxy that communicates
-- with your external key manager.
--
-- The custom key store must be connected before you can create KMS keys in
-- the key store or use the KMS keys it contains. You can disconnect and
-- reconnect a custom key store at any time.
--
-- The connection process for a custom key store can take an extended
-- amount of time to complete. This operation starts the connection
-- process, but it does not wait for it to complete. When it succeeds, this
-- operation quickly returns an HTTP 200 response and a JSON object with no
-- properties. However, this response does not indicate that the custom key
-- store is connected. To get the connection state of the custom key store,
-- use the DescribeCustomKeyStores operation.
--
-- This operation is part of the
-- <https://docs.aws.amazon.com/kms/latest/developerguide/custom-key-store-overview.html custom key stores>
-- feature in KMS, which combines the convenience and extensive integration
-- of KMS with the isolation and control of a key store that you own and
-- manage.
--
-- The @ConnectCustomKeyStore@ operation might fail for various reasons. To
-- find the reason, use the DescribeCustomKeyStores operation and see the
-- @ConnectionErrorCode@ in the response. For help interpreting the
-- @ConnectionErrorCode@, see CustomKeyStoresListEntry.
--
-- To fix the failure, use the DisconnectCustomKeyStore operation to
-- disconnect the custom key store, correct the error, use the
-- UpdateCustomKeyStore operation if necessary, and then use
-- @ConnectCustomKeyStore@ again.
--
-- __CloudHSM key store__
--
-- During the connection process for an CloudHSM key store, KMS finds the
-- CloudHSM cluster that is associated with the custom key store, creates
-- the connection infrastructure, connects to the cluster, logs into the
-- CloudHSM client as the @kmsuser@ CU, and rotates its password.
--
-- To connect an CloudHSM key store, its associated CloudHSM cluster must
-- have at least one active HSM. To get the number of active HSMs in a
-- cluster, use the
-- <https://docs.aws.amazon.com/cloudhsm/latest/APIReference/API_DescribeClusters.html DescribeClusters>
-- operation. To add HSMs to the cluster, use the
-- <https://docs.aws.amazon.com/cloudhsm/latest/APIReference/API_CreateHsm.html CreateHsm>
-- operation. Also, the
-- <https://docs.aws.amazon.com/kms/latest/developerguide/key-store-concepts.html#concept-kmsuser kmsuser crypto user>
-- (CU) must not be logged into the cluster. This prevents KMS from using
-- this account to log in.
--
-- If you are having trouble connecting or disconnecting a CloudHSM key
-- store, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/fix-keystore.html Troubleshooting an CloudHSM key store>
-- in the /Key Management Service Developer Guide/.
--
-- __External key store__
--
-- When you connect an external key store that uses public endpoint
-- connectivity, KMS tests its ability to communicate with your external
-- key manager by sending a request via the external key store proxy.
--
-- When you connect to an external key store that uses VPC endpoint service
-- connectivity, KMS establishes the networking elements that it needs to
-- communicate with your external key manager via the external key store
-- proxy. This includes creating an interface endpoint to the VPC endpoint
-- service and a private hosted zone for traffic between KMS and the VPC
-- endpoint service.
--
-- To connect an external key store, KMS must be able to connect to the
-- external key store proxy, the external key store proxy must be able to
-- communicate with your external key manager, and the external key manager
-- must be available for cryptographic operations.
--
-- If you are having trouble connecting or disconnecting an external key
-- store, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/xks-troubleshooting.html Troubleshooting an external key store>
-- in the /Key Management Service Developer Guide/.
--
-- __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:ConnectCustomKeyStore>
-- (IAM policy)
--
-- __Related operations__
--
-- -   CreateCustomKeyStore
--
-- -   DeleteCustomKeyStore
--
-- -   DescribeCustomKeyStores
--
-- -   DisconnectCustomKeyStore
--
-- -   UpdateCustomKeyStore
module Amazonka.KMS.ConnectCustomKeyStore
  ( -- * Creating a Request
    ConnectCustomKeyStore (..),
    newConnectCustomKeyStore,

    -- * Request Lenses
    connectCustomKeyStore_customKeyStoreId,

    -- * Destructuring the Response
    ConnectCustomKeyStoreResponse (..),
    newConnectCustomKeyStoreResponse,

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

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

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

instance Core.AWSRequest ConnectCustomKeyStore where
  type
    AWSResponse ConnectCustomKeyStore =
      ConnectCustomKeyStoreResponse
  request :: (Service -> Service)
-> ConnectCustomKeyStore -> Request ConnectCustomKeyStore
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 ConnectCustomKeyStore
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ConnectCustomKeyStore)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> ConnectCustomKeyStoreResponse
ConnectCustomKeyStoreResponse'
            forall (f :: * -> *) a b. Functor 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 ConnectCustomKeyStore where
  hashWithSalt :: Int -> ConnectCustomKeyStore -> Int
hashWithSalt Int
_salt ConnectCustomKeyStore' {Text
customKeyStoreId :: Text
$sel:customKeyStoreId:ConnectCustomKeyStore' :: ConnectCustomKeyStore -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
customKeyStoreId

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

instance Data.ToHeaders ConnectCustomKeyStore where
  toHeaders :: ConnectCustomKeyStore -> 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.ConnectCustomKeyStore" ::
                          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 ConnectCustomKeyStore where
  toJSON :: ConnectCustomKeyStore -> Value
toJSON ConnectCustomKeyStore' {Text
customKeyStoreId :: Text
$sel:customKeyStoreId:ConnectCustomKeyStore' :: ConnectCustomKeyStore -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"CustomKeyStoreId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
customKeyStoreId)
          ]
      )

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

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

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

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

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

instance Prelude.NFData ConnectCustomKeyStoreResponse where
  rnf :: ConnectCustomKeyStoreResponse -> ()
rnf ConnectCustomKeyStoreResponse' {Int
httpStatus :: Int
$sel:httpStatus:ConnectCustomKeyStoreResponse' :: ConnectCustomKeyStoreResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus