{-# 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.CertificateManagerPCA.GetCertificateAuthorityCsr
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Retrieves the certificate signing request (CSR) for your private
-- certificate authority (CA). The CSR is created when you call the
-- <https://docs.aws.amazon.com/privateca/latest/APIReference/API_CreateCertificateAuthority.html CreateCertificateAuthority>
-- action. Sign the CSR with your Amazon Web Services Private CA-hosted or
-- on-premises root or subordinate CA. Then import the signed certificate
-- back into Amazon Web Services Private CA by calling the
-- <https://docs.aws.amazon.com/privateca/latest/APIReference/API_ImportCertificateAuthorityCertificate.html ImportCertificateAuthorityCertificate>
-- action. The CSR is returned as a base64 PEM-encoded string.
module Amazonka.CertificateManagerPCA.GetCertificateAuthorityCsr
  ( -- * Creating a Request
    GetCertificateAuthorityCsr (..),
    newGetCertificateAuthorityCsr,

    -- * Request Lenses
    getCertificateAuthorityCsr_certificateAuthorityArn,

    -- * Destructuring the Response
    GetCertificateAuthorityCsrResponse (..),
    newGetCertificateAuthorityCsrResponse,

    -- * Response Lenses
    getCertificateAuthorityCsrResponse_csr,
    getCertificateAuthorityCsrResponse_httpStatus,
  )
where

import Amazonka.CertificateManagerPCA.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newGetCertificateAuthorityCsr' smart constructor.
data GetCertificateAuthorityCsr = GetCertificateAuthorityCsr'
  { -- | The Amazon Resource Name (ARN) that was returned when you called the
    -- <https://docs.aws.amazon.com/privateca/latest/APIReference/API_CreateCertificateAuthority.html CreateCertificateAuthority>
    -- action. This must be of the form:
    --
    -- @arn:aws:acm-pca:@/@region@/@:@/@account@/@:certificate-authority\/@/@12345678-1234-1234-1234-123456789012@/@ @
    GetCertificateAuthorityCsr -> Text
certificateAuthorityArn :: Prelude.Text
  }
  deriving (GetCertificateAuthorityCsr -> GetCertificateAuthorityCsr -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCertificateAuthorityCsr -> GetCertificateAuthorityCsr -> Bool
$c/= :: GetCertificateAuthorityCsr -> GetCertificateAuthorityCsr -> Bool
== :: GetCertificateAuthorityCsr -> GetCertificateAuthorityCsr -> Bool
$c== :: GetCertificateAuthorityCsr -> GetCertificateAuthorityCsr -> Bool
Prelude.Eq, ReadPrec [GetCertificateAuthorityCsr]
ReadPrec GetCertificateAuthorityCsr
Int -> ReadS GetCertificateAuthorityCsr
ReadS [GetCertificateAuthorityCsr]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCertificateAuthorityCsr]
$creadListPrec :: ReadPrec [GetCertificateAuthorityCsr]
readPrec :: ReadPrec GetCertificateAuthorityCsr
$creadPrec :: ReadPrec GetCertificateAuthorityCsr
readList :: ReadS [GetCertificateAuthorityCsr]
$creadList :: ReadS [GetCertificateAuthorityCsr]
readsPrec :: Int -> ReadS GetCertificateAuthorityCsr
$creadsPrec :: Int -> ReadS GetCertificateAuthorityCsr
Prelude.Read, Int -> GetCertificateAuthorityCsr -> ShowS
[GetCertificateAuthorityCsr] -> ShowS
GetCertificateAuthorityCsr -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCertificateAuthorityCsr] -> ShowS
$cshowList :: [GetCertificateAuthorityCsr] -> ShowS
show :: GetCertificateAuthorityCsr -> String
$cshow :: GetCertificateAuthorityCsr -> String
showsPrec :: Int -> GetCertificateAuthorityCsr -> ShowS
$cshowsPrec :: Int -> GetCertificateAuthorityCsr -> ShowS
Prelude.Show, forall x.
Rep GetCertificateAuthorityCsr x -> GetCertificateAuthorityCsr
forall x.
GetCertificateAuthorityCsr -> Rep GetCertificateAuthorityCsr x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetCertificateAuthorityCsr x -> GetCertificateAuthorityCsr
$cfrom :: forall x.
GetCertificateAuthorityCsr -> Rep GetCertificateAuthorityCsr x
Prelude.Generic)

-- |
-- Create a value of 'GetCertificateAuthorityCsr' 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:
--
-- 'certificateAuthorityArn', 'getCertificateAuthorityCsr_certificateAuthorityArn' - The Amazon Resource Name (ARN) that was returned when you called the
-- <https://docs.aws.amazon.com/privateca/latest/APIReference/API_CreateCertificateAuthority.html CreateCertificateAuthority>
-- action. This must be of the form:
--
-- @arn:aws:acm-pca:@/@region@/@:@/@account@/@:certificate-authority\/@/@12345678-1234-1234-1234-123456789012@/@ @
newGetCertificateAuthorityCsr ::
  -- | 'certificateAuthorityArn'
  Prelude.Text ->
  GetCertificateAuthorityCsr
newGetCertificateAuthorityCsr :: Text -> GetCertificateAuthorityCsr
newGetCertificateAuthorityCsr
  Text
pCertificateAuthorityArn_ =
    GetCertificateAuthorityCsr'
      { $sel:certificateAuthorityArn:GetCertificateAuthorityCsr' :: Text
certificateAuthorityArn =
          Text
pCertificateAuthorityArn_
      }

-- | The Amazon Resource Name (ARN) that was returned when you called the
-- <https://docs.aws.amazon.com/privateca/latest/APIReference/API_CreateCertificateAuthority.html CreateCertificateAuthority>
-- action. This must be of the form:
--
-- @arn:aws:acm-pca:@/@region@/@:@/@account@/@:certificate-authority\/@/@12345678-1234-1234-1234-123456789012@/@ @
getCertificateAuthorityCsr_certificateAuthorityArn :: Lens.Lens' GetCertificateAuthorityCsr Prelude.Text
getCertificateAuthorityCsr_certificateAuthorityArn :: Lens' GetCertificateAuthorityCsr Text
getCertificateAuthorityCsr_certificateAuthorityArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCertificateAuthorityCsr' {Text
certificateAuthorityArn :: Text
$sel:certificateAuthorityArn:GetCertificateAuthorityCsr' :: GetCertificateAuthorityCsr -> Text
certificateAuthorityArn} -> Text
certificateAuthorityArn) (\s :: GetCertificateAuthorityCsr
s@GetCertificateAuthorityCsr' {} Text
a -> GetCertificateAuthorityCsr
s {$sel:certificateAuthorityArn:GetCertificateAuthorityCsr' :: Text
certificateAuthorityArn = Text
a} :: GetCertificateAuthorityCsr)

instance Core.AWSRequest GetCertificateAuthorityCsr where
  type
    AWSResponse GetCertificateAuthorityCsr =
      GetCertificateAuthorityCsrResponse
  request :: (Service -> Service)
-> GetCertificateAuthorityCsr -> Request GetCertificateAuthorityCsr
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 GetCertificateAuthorityCsr
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetCertificateAuthorityCsr)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Int -> GetCertificateAuthorityCsrResponse
GetCertificateAuthorityCsrResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Csr")
            forall (f :: * -> *) a b. Applicative f => 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 GetCertificateAuthorityCsr where
  hashWithSalt :: Int -> GetCertificateAuthorityCsr -> Int
hashWithSalt Int
_salt GetCertificateAuthorityCsr' {Text
certificateAuthorityArn :: Text
$sel:certificateAuthorityArn:GetCertificateAuthorityCsr' :: GetCertificateAuthorityCsr -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
certificateAuthorityArn

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

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

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

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

-- | /See:/ 'newGetCertificateAuthorityCsrResponse' smart constructor.
data GetCertificateAuthorityCsrResponse = GetCertificateAuthorityCsrResponse'
  { -- | The base64 PEM-encoded certificate signing request (CSR) for your
    -- private CA certificate.
    GetCertificateAuthorityCsrResponse -> Maybe Text
csr :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetCertificateAuthorityCsrResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetCertificateAuthorityCsrResponse
-> GetCertificateAuthorityCsrResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCertificateAuthorityCsrResponse
-> GetCertificateAuthorityCsrResponse -> Bool
$c/= :: GetCertificateAuthorityCsrResponse
-> GetCertificateAuthorityCsrResponse -> Bool
== :: GetCertificateAuthorityCsrResponse
-> GetCertificateAuthorityCsrResponse -> Bool
$c== :: GetCertificateAuthorityCsrResponse
-> GetCertificateAuthorityCsrResponse -> Bool
Prelude.Eq, ReadPrec [GetCertificateAuthorityCsrResponse]
ReadPrec GetCertificateAuthorityCsrResponse
Int -> ReadS GetCertificateAuthorityCsrResponse
ReadS [GetCertificateAuthorityCsrResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCertificateAuthorityCsrResponse]
$creadListPrec :: ReadPrec [GetCertificateAuthorityCsrResponse]
readPrec :: ReadPrec GetCertificateAuthorityCsrResponse
$creadPrec :: ReadPrec GetCertificateAuthorityCsrResponse
readList :: ReadS [GetCertificateAuthorityCsrResponse]
$creadList :: ReadS [GetCertificateAuthorityCsrResponse]
readsPrec :: Int -> ReadS GetCertificateAuthorityCsrResponse
$creadsPrec :: Int -> ReadS GetCertificateAuthorityCsrResponse
Prelude.Read, Int -> GetCertificateAuthorityCsrResponse -> ShowS
[GetCertificateAuthorityCsrResponse] -> ShowS
GetCertificateAuthorityCsrResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCertificateAuthorityCsrResponse] -> ShowS
$cshowList :: [GetCertificateAuthorityCsrResponse] -> ShowS
show :: GetCertificateAuthorityCsrResponse -> String
$cshow :: GetCertificateAuthorityCsrResponse -> String
showsPrec :: Int -> GetCertificateAuthorityCsrResponse -> ShowS
$cshowsPrec :: Int -> GetCertificateAuthorityCsrResponse -> ShowS
Prelude.Show, forall x.
Rep GetCertificateAuthorityCsrResponse x
-> GetCertificateAuthorityCsrResponse
forall x.
GetCertificateAuthorityCsrResponse
-> Rep GetCertificateAuthorityCsrResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetCertificateAuthorityCsrResponse x
-> GetCertificateAuthorityCsrResponse
$cfrom :: forall x.
GetCertificateAuthorityCsrResponse
-> Rep GetCertificateAuthorityCsrResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetCertificateAuthorityCsrResponse' 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:
--
-- 'csr', 'getCertificateAuthorityCsrResponse_csr' - The base64 PEM-encoded certificate signing request (CSR) for your
-- private CA certificate.
--
-- 'httpStatus', 'getCertificateAuthorityCsrResponse_httpStatus' - The response's http status code.
newGetCertificateAuthorityCsrResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetCertificateAuthorityCsrResponse
newGetCertificateAuthorityCsrResponse :: Int -> GetCertificateAuthorityCsrResponse
newGetCertificateAuthorityCsrResponse Int
pHttpStatus_ =
  GetCertificateAuthorityCsrResponse'
    { $sel:csr:GetCertificateAuthorityCsrResponse' :: Maybe Text
csr =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetCertificateAuthorityCsrResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The base64 PEM-encoded certificate signing request (CSR) for your
-- private CA certificate.
getCertificateAuthorityCsrResponse_csr :: Lens.Lens' GetCertificateAuthorityCsrResponse (Prelude.Maybe Prelude.Text)
getCertificateAuthorityCsrResponse_csr :: Lens' GetCertificateAuthorityCsrResponse (Maybe Text)
getCertificateAuthorityCsrResponse_csr = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCertificateAuthorityCsrResponse' {Maybe Text
csr :: Maybe Text
$sel:csr:GetCertificateAuthorityCsrResponse' :: GetCertificateAuthorityCsrResponse -> Maybe Text
csr} -> Maybe Text
csr) (\s :: GetCertificateAuthorityCsrResponse
s@GetCertificateAuthorityCsrResponse' {} Maybe Text
a -> GetCertificateAuthorityCsrResponse
s {$sel:csr:GetCertificateAuthorityCsrResponse' :: Maybe Text
csr = Maybe Text
a} :: GetCertificateAuthorityCsrResponse)

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

instance
  Prelude.NFData
    GetCertificateAuthorityCsrResponse
  where
  rnf :: GetCertificateAuthorityCsrResponse -> ()
rnf GetCertificateAuthorityCsrResponse' {Int
Maybe Text
httpStatus :: Int
csr :: Maybe Text
$sel:httpStatus:GetCertificateAuthorityCsrResponse' :: GetCertificateAuthorityCsrResponse -> Int
$sel:csr:GetCertificateAuthorityCsrResponse' :: GetCertificateAuthorityCsrResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
csr
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus