{-# 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.CertificateManager.GetCertificate
-- 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 an Amazon-issued certificate and its certificate chain. The
-- chain consists of the certificate of the issuing CA and the intermediate
-- certificates of any other subordinate CAs. All of the certificates are
-- base64 encoded. You can use
-- <https://wiki.openssl.org/index.php/Command_Line_Utilities OpenSSL> to
-- decode the certificates and inspect individual fields.
module Amazonka.CertificateManager.GetCertificate
  ( -- * Creating a Request
    GetCertificate (..),
    newGetCertificate,

    -- * Request Lenses
    getCertificate_certificateArn,

    -- * Destructuring the Response
    GetCertificateResponse (..),
    newGetCertificateResponse,

    -- * Response Lenses
    getCertificateResponse_certificate,
    getCertificateResponse_certificateChain,
    getCertificateResponse_httpStatus,
  )
where

import Amazonka.CertificateManager.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:/ 'newGetCertificate' smart constructor.
data GetCertificate = GetCertificate'
  { -- | String that contains a certificate ARN in the following format:
    --
    -- @arn:aws:acm:region:123456789012:certificate\/12345678-1234-1234-1234-123456789012@
    --
    -- For more information about ARNs, see
    -- <https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html Amazon Resource Names (ARNs)>.
    GetCertificate -> Text
certificateArn :: Prelude.Text
  }
  deriving (GetCertificate -> GetCertificate -> Bool
(GetCertificate -> GetCertificate -> Bool)
-> (GetCertificate -> GetCertificate -> Bool) -> Eq GetCertificate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCertificate -> GetCertificate -> Bool
$c/= :: GetCertificate -> GetCertificate -> Bool
== :: GetCertificate -> GetCertificate -> Bool
$c== :: GetCertificate -> GetCertificate -> Bool
Prelude.Eq, ReadPrec [GetCertificate]
ReadPrec GetCertificate
Int -> ReadS GetCertificate
ReadS [GetCertificate]
(Int -> ReadS GetCertificate)
-> ReadS [GetCertificate]
-> ReadPrec GetCertificate
-> ReadPrec [GetCertificate]
-> Read GetCertificate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCertificate]
$creadListPrec :: ReadPrec [GetCertificate]
readPrec :: ReadPrec GetCertificate
$creadPrec :: ReadPrec GetCertificate
readList :: ReadS [GetCertificate]
$creadList :: ReadS [GetCertificate]
readsPrec :: Int -> ReadS GetCertificate
$creadsPrec :: Int -> ReadS GetCertificate
Prelude.Read, Int -> GetCertificate -> ShowS
[GetCertificate] -> ShowS
GetCertificate -> String
(Int -> GetCertificate -> ShowS)
-> (GetCertificate -> String)
-> ([GetCertificate] -> ShowS)
-> Show GetCertificate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCertificate] -> ShowS
$cshowList :: [GetCertificate] -> ShowS
show :: GetCertificate -> String
$cshow :: GetCertificate -> String
showsPrec :: Int -> GetCertificate -> ShowS
$cshowsPrec :: Int -> GetCertificate -> ShowS
Prelude.Show, (forall x. GetCertificate -> Rep GetCertificate x)
-> (forall x. Rep GetCertificate x -> GetCertificate)
-> Generic GetCertificate
forall x. Rep GetCertificate x -> GetCertificate
forall x. GetCertificate -> Rep GetCertificate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetCertificate x -> GetCertificate
$cfrom :: forall x. GetCertificate -> Rep GetCertificate x
Prelude.Generic)

-- |
-- Create a value of 'GetCertificate' 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:
--
-- 'certificateArn', 'getCertificate_certificateArn' - String that contains a certificate ARN in the following format:
--
-- @arn:aws:acm:region:123456789012:certificate\/12345678-1234-1234-1234-123456789012@
--
-- For more information about ARNs, see
-- <https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html Amazon Resource Names (ARNs)>.
newGetCertificate ::
  -- | 'certificateArn'
  Prelude.Text ->
  GetCertificate
newGetCertificate :: Text -> GetCertificate
newGetCertificate Text
pCertificateArn_ =
  GetCertificate' :: Text -> GetCertificate
GetCertificate' {$sel:certificateArn:GetCertificate' :: Text
certificateArn = Text
pCertificateArn_}

-- | String that contains a certificate ARN in the following format:
--
-- @arn:aws:acm:region:123456789012:certificate\/12345678-1234-1234-1234-123456789012@
--
-- For more information about ARNs, see
-- <https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html Amazon Resource Names (ARNs)>.
getCertificate_certificateArn :: Lens.Lens' GetCertificate Prelude.Text
getCertificate_certificateArn :: (Text -> f Text) -> GetCertificate -> f GetCertificate
getCertificate_certificateArn = (GetCertificate -> Text)
-> (GetCertificate -> Text -> GetCertificate)
-> Lens GetCertificate GetCertificate Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCertificate' {Text
certificateArn :: Text
$sel:certificateArn:GetCertificate' :: GetCertificate -> Text
certificateArn} -> Text
certificateArn) (\s :: GetCertificate
s@GetCertificate' {} Text
a -> GetCertificate
s {$sel:certificateArn:GetCertificate' :: Text
certificateArn = Text
a} :: GetCertificate)

instance Core.AWSRequest GetCertificate where
  type
    AWSResponse GetCertificate =
      GetCertificateResponse
  request :: GetCertificate -> Request GetCertificate
request = Service -> GetCertificate -> Request GetCertificate
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetCertificate
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetCertificate)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetCertificate))
-> Logger
-> Service
-> Proxy GetCertificate
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetCertificate)))
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 -> Maybe Text -> Int -> GetCertificateResponse
GetCertificateResponse'
            (Maybe Text -> Maybe Text -> Int -> GetCertificateResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> GetCertificateResponse)
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
"Certificate")
            Either String (Maybe Text -> Int -> GetCertificateResponse)
-> Either String (Maybe Text)
-> Either String (Int -> GetCertificateResponse)
forall (f :: * -> *) a b. Applicative f => 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
"CertificateChain")
            Either String (Int -> GetCertificateResponse)
-> Either String Int -> Either String GetCertificateResponse
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 GetCertificate

instance Prelude.NFData GetCertificate

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

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

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

-- | /See:/ 'newGetCertificateResponse' smart constructor.
data GetCertificateResponse = GetCertificateResponse'
  { -- | The ACM-issued certificate corresponding to the ARN specified as input.
    GetCertificateResponse -> Maybe Text
certificate :: Prelude.Maybe Prelude.Text,
    -- | Certificates forming the requested certificate\'s chain of trust. The
    -- chain consists of the certificate of the issuing CA and the intermediate
    -- certificates of any other subordinate CAs.
    GetCertificateResponse -> Maybe Text
certificateChain :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetCertificateResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetCertificateResponse -> GetCertificateResponse -> Bool
(GetCertificateResponse -> GetCertificateResponse -> Bool)
-> (GetCertificateResponse -> GetCertificateResponse -> Bool)
-> Eq GetCertificateResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCertificateResponse -> GetCertificateResponse -> Bool
$c/= :: GetCertificateResponse -> GetCertificateResponse -> Bool
== :: GetCertificateResponse -> GetCertificateResponse -> Bool
$c== :: GetCertificateResponse -> GetCertificateResponse -> Bool
Prelude.Eq, ReadPrec [GetCertificateResponse]
ReadPrec GetCertificateResponse
Int -> ReadS GetCertificateResponse
ReadS [GetCertificateResponse]
(Int -> ReadS GetCertificateResponse)
-> ReadS [GetCertificateResponse]
-> ReadPrec GetCertificateResponse
-> ReadPrec [GetCertificateResponse]
-> Read GetCertificateResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCertificateResponse]
$creadListPrec :: ReadPrec [GetCertificateResponse]
readPrec :: ReadPrec GetCertificateResponse
$creadPrec :: ReadPrec GetCertificateResponse
readList :: ReadS [GetCertificateResponse]
$creadList :: ReadS [GetCertificateResponse]
readsPrec :: Int -> ReadS GetCertificateResponse
$creadsPrec :: Int -> ReadS GetCertificateResponse
Prelude.Read, Int -> GetCertificateResponse -> ShowS
[GetCertificateResponse] -> ShowS
GetCertificateResponse -> String
(Int -> GetCertificateResponse -> ShowS)
-> (GetCertificateResponse -> String)
-> ([GetCertificateResponse] -> ShowS)
-> Show GetCertificateResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCertificateResponse] -> ShowS
$cshowList :: [GetCertificateResponse] -> ShowS
show :: GetCertificateResponse -> String
$cshow :: GetCertificateResponse -> String
showsPrec :: Int -> GetCertificateResponse -> ShowS
$cshowsPrec :: Int -> GetCertificateResponse -> ShowS
Prelude.Show, (forall x. GetCertificateResponse -> Rep GetCertificateResponse x)
-> (forall x.
    Rep GetCertificateResponse x -> GetCertificateResponse)
-> Generic GetCertificateResponse
forall x. Rep GetCertificateResponse x -> GetCertificateResponse
forall x. GetCertificateResponse -> Rep GetCertificateResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetCertificateResponse x -> GetCertificateResponse
$cfrom :: forall x. GetCertificateResponse -> Rep GetCertificateResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetCertificateResponse' 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:
--
-- 'certificate', 'getCertificateResponse_certificate' - The ACM-issued certificate corresponding to the ARN specified as input.
--
-- 'certificateChain', 'getCertificateResponse_certificateChain' - Certificates forming the requested certificate\'s chain of trust. The
-- chain consists of the certificate of the issuing CA and the intermediate
-- certificates of any other subordinate CAs.
--
-- 'httpStatus', 'getCertificateResponse_httpStatus' - The response's http status code.
newGetCertificateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetCertificateResponse
newGetCertificateResponse :: Int -> GetCertificateResponse
newGetCertificateResponse Int
pHttpStatus_ =
  GetCertificateResponse' :: Maybe Text -> Maybe Text -> Int -> GetCertificateResponse
GetCertificateResponse'
    { $sel:certificate:GetCertificateResponse' :: Maybe Text
certificate =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:certificateChain:GetCertificateResponse' :: Maybe Text
certificateChain = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetCertificateResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ACM-issued certificate corresponding to the ARN specified as input.
getCertificateResponse_certificate :: Lens.Lens' GetCertificateResponse (Prelude.Maybe Prelude.Text)
getCertificateResponse_certificate :: (Maybe Text -> f (Maybe Text))
-> GetCertificateResponse -> f GetCertificateResponse
getCertificateResponse_certificate = (GetCertificateResponse -> Maybe Text)
-> (GetCertificateResponse -> Maybe Text -> GetCertificateResponse)
-> Lens
     GetCertificateResponse
     GetCertificateResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCertificateResponse' {Maybe Text
certificate :: Maybe Text
$sel:certificate:GetCertificateResponse' :: GetCertificateResponse -> Maybe Text
certificate} -> Maybe Text
certificate) (\s :: GetCertificateResponse
s@GetCertificateResponse' {} Maybe Text
a -> GetCertificateResponse
s {$sel:certificate:GetCertificateResponse' :: Maybe Text
certificate = Maybe Text
a} :: GetCertificateResponse)

-- | Certificates forming the requested certificate\'s chain of trust. The
-- chain consists of the certificate of the issuing CA and the intermediate
-- certificates of any other subordinate CAs.
getCertificateResponse_certificateChain :: Lens.Lens' GetCertificateResponse (Prelude.Maybe Prelude.Text)
getCertificateResponse_certificateChain :: (Maybe Text -> f (Maybe Text))
-> GetCertificateResponse -> f GetCertificateResponse
getCertificateResponse_certificateChain = (GetCertificateResponse -> Maybe Text)
-> (GetCertificateResponse -> Maybe Text -> GetCertificateResponse)
-> Lens
     GetCertificateResponse
     GetCertificateResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCertificateResponse' {Maybe Text
certificateChain :: Maybe Text
$sel:certificateChain:GetCertificateResponse' :: GetCertificateResponse -> Maybe Text
certificateChain} -> Maybe Text
certificateChain) (\s :: GetCertificateResponse
s@GetCertificateResponse' {} Maybe Text
a -> GetCertificateResponse
s {$sel:certificateChain:GetCertificateResponse' :: Maybe Text
certificateChain = Maybe Text
a} :: GetCertificateResponse)

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

instance Prelude.NFData GetCertificateResponse