{-# 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-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)
--
-- 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/acm-pca/latest/APIReference/API_CreateCertificateAuthority.html CreateCertificateAuthority>
-- action. Sign the CSR with your ACM Private CA-hosted or on-premises root
-- or subordinate CA. Then import the signed certificate back into ACM
-- Private CA by calling the
-- <https://docs.aws.amazon.com/acm-pca/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.Lens as Lens
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/acm-pca/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
(GetCertificateAuthorityCsr -> GetCertificateAuthorityCsr -> Bool)
-> (GetCertificateAuthorityCsr
    -> GetCertificateAuthorityCsr -> Bool)
-> Eq GetCertificateAuthorityCsr
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]
(Int -> ReadS GetCertificateAuthorityCsr)
-> ReadS [GetCertificateAuthorityCsr]
-> ReadPrec GetCertificateAuthorityCsr
-> ReadPrec [GetCertificateAuthorityCsr]
-> Read 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
(Int -> GetCertificateAuthorityCsr -> ShowS)
-> (GetCertificateAuthorityCsr -> String)
-> ([GetCertificateAuthorityCsr] -> ShowS)
-> Show GetCertificateAuthorityCsr
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.
 GetCertificateAuthorityCsr -> Rep GetCertificateAuthorityCsr x)
-> (forall x.
    Rep GetCertificateAuthorityCsr x -> GetCertificateAuthorityCsr)
-> Generic GetCertificateAuthorityCsr
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/acm-pca/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' :: Text -> GetCertificateAuthorityCsr
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/acm-pca/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 :: (Text -> f Text)
-> GetCertificateAuthorityCsr -> f GetCertificateAuthorityCsr
getCertificateAuthorityCsr_certificateAuthorityArn = (GetCertificateAuthorityCsr -> Text)
-> (GetCertificateAuthorityCsr
    -> Text -> GetCertificateAuthorityCsr)
-> Lens
     GetCertificateAuthorityCsr GetCertificateAuthorityCsr Text Text
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 :: GetCertificateAuthorityCsr -> Request GetCertificateAuthorityCsr
request = Service
-> GetCertificateAuthorityCsr -> Request GetCertificateAuthorityCsr
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetCertificateAuthorityCsr
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetCertificateAuthorityCsr)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetCertificateAuthorityCsr))
-> Logger
-> Service
-> Proxy GetCertificateAuthorityCsr
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetCertificateAuthorityCsr)))
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 Text -> Int -> GetCertificateAuthorityCsrResponse
GetCertificateAuthorityCsrResponse'
            (Maybe Text -> Int -> GetCertificateAuthorityCsrResponse)
-> Either String (Maybe Text)
-> Either String (Int -> GetCertificateAuthorityCsrResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Csr")
            Either String (Int -> GetCertificateAuthorityCsrResponse)
-> Either String Int
-> Either String GetCertificateAuthorityCsrResponse
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 GetCertificateAuthorityCsr

instance Prelude.NFData GetCertificateAuthorityCsr

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

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

instance Core.ToQuery GetCertificateAuthorityCsr where
  toQuery :: GetCertificateAuthorityCsr -> QueryString
toQuery = QueryString -> GetCertificateAuthorityCsr -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(GetCertificateAuthorityCsrResponse
 -> GetCertificateAuthorityCsrResponse -> Bool)
-> (GetCertificateAuthorityCsrResponse
    -> GetCertificateAuthorityCsrResponse -> Bool)
-> Eq GetCertificateAuthorityCsrResponse
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]
(Int -> ReadS GetCertificateAuthorityCsrResponse)
-> ReadS [GetCertificateAuthorityCsrResponse]
-> ReadPrec GetCertificateAuthorityCsrResponse
-> ReadPrec [GetCertificateAuthorityCsrResponse]
-> Read 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
(Int -> GetCertificateAuthorityCsrResponse -> ShowS)
-> (GetCertificateAuthorityCsrResponse -> String)
-> ([GetCertificateAuthorityCsrResponse] -> ShowS)
-> Show GetCertificateAuthorityCsrResponse
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.
 GetCertificateAuthorityCsrResponse
 -> Rep GetCertificateAuthorityCsrResponse x)
-> (forall x.
    Rep GetCertificateAuthorityCsrResponse x
    -> GetCertificateAuthorityCsrResponse)
-> Generic GetCertificateAuthorityCsrResponse
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' :: Maybe Text -> Int -> GetCertificateAuthorityCsrResponse
GetCertificateAuthorityCsrResponse'
    { $sel:csr:GetCertificateAuthorityCsrResponse' :: Maybe Text
csr =
        Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> GetCertificateAuthorityCsrResponse
-> f GetCertificateAuthorityCsrResponse
getCertificateAuthorityCsrResponse_csr = (GetCertificateAuthorityCsrResponse -> Maybe Text)
-> (GetCertificateAuthorityCsrResponse
    -> Maybe Text -> GetCertificateAuthorityCsrResponse)
-> Lens
     GetCertificateAuthorityCsrResponse
     GetCertificateAuthorityCsrResponse
     (Maybe Text)
     (Maybe Text)
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 :: (Int -> f Int)
-> GetCertificateAuthorityCsrResponse
-> f GetCertificateAuthorityCsrResponse
getCertificateAuthorityCsrResponse_httpStatus = (GetCertificateAuthorityCsrResponse -> Int)
-> (GetCertificateAuthorityCsrResponse
    -> Int -> GetCertificateAuthorityCsrResponse)
-> Lens
     GetCertificateAuthorityCsrResponse
     GetCertificateAuthorityCsrResponse
     Int
     Int
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