{-# 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.DirectoryService.DescribeCertificate
-- 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)
--
-- Displays information about the certificate registered for secure LDAP or
-- client certificate authentication.
module Amazonka.DirectoryService.DescribeCertificate
  ( -- * Creating a Request
    DescribeCertificate (..),
    newDescribeCertificate,

    -- * Request Lenses
    describeCertificate_directoryId,
    describeCertificate_certificateId,

    -- * Destructuring the Response
    DescribeCertificateResponse (..),
    newDescribeCertificateResponse,

    -- * Response Lenses
    describeCertificateResponse_certificate,
    describeCertificateResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.DirectoryService.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:/ 'newDescribeCertificate' smart constructor.
data DescribeCertificate = DescribeCertificate'
  { -- | The identifier of the directory.
    DescribeCertificate -> Text
directoryId :: Prelude.Text,
    -- | The identifier of the certificate.
    DescribeCertificate -> Text
certificateId :: Prelude.Text
  }
  deriving (DescribeCertificate -> DescribeCertificate -> Bool
(DescribeCertificate -> DescribeCertificate -> Bool)
-> (DescribeCertificate -> DescribeCertificate -> Bool)
-> Eq DescribeCertificate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeCertificate -> DescribeCertificate -> Bool
$c/= :: DescribeCertificate -> DescribeCertificate -> Bool
== :: DescribeCertificate -> DescribeCertificate -> Bool
$c== :: DescribeCertificate -> DescribeCertificate -> Bool
Prelude.Eq, ReadPrec [DescribeCertificate]
ReadPrec DescribeCertificate
Int -> ReadS DescribeCertificate
ReadS [DescribeCertificate]
(Int -> ReadS DescribeCertificate)
-> ReadS [DescribeCertificate]
-> ReadPrec DescribeCertificate
-> ReadPrec [DescribeCertificate]
-> Read DescribeCertificate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeCertificate]
$creadListPrec :: ReadPrec [DescribeCertificate]
readPrec :: ReadPrec DescribeCertificate
$creadPrec :: ReadPrec DescribeCertificate
readList :: ReadS [DescribeCertificate]
$creadList :: ReadS [DescribeCertificate]
readsPrec :: Int -> ReadS DescribeCertificate
$creadsPrec :: Int -> ReadS DescribeCertificate
Prelude.Read, Int -> DescribeCertificate -> ShowS
[DescribeCertificate] -> ShowS
DescribeCertificate -> String
(Int -> DescribeCertificate -> ShowS)
-> (DescribeCertificate -> String)
-> ([DescribeCertificate] -> ShowS)
-> Show DescribeCertificate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeCertificate] -> ShowS
$cshowList :: [DescribeCertificate] -> ShowS
show :: DescribeCertificate -> String
$cshow :: DescribeCertificate -> String
showsPrec :: Int -> DescribeCertificate -> ShowS
$cshowsPrec :: Int -> DescribeCertificate -> ShowS
Prelude.Show, (forall x. DescribeCertificate -> Rep DescribeCertificate x)
-> (forall x. Rep DescribeCertificate x -> DescribeCertificate)
-> Generic DescribeCertificate
forall x. Rep DescribeCertificate x -> DescribeCertificate
forall x. DescribeCertificate -> Rep DescribeCertificate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeCertificate x -> DescribeCertificate
$cfrom :: forall x. DescribeCertificate -> Rep DescribeCertificate x
Prelude.Generic)

-- |
-- Create a value of 'DescribeCertificate' 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:
--
-- 'directoryId', 'describeCertificate_directoryId' - The identifier of the directory.
--
-- 'certificateId', 'describeCertificate_certificateId' - The identifier of the certificate.
newDescribeCertificate ::
  -- | 'directoryId'
  Prelude.Text ->
  -- | 'certificateId'
  Prelude.Text ->
  DescribeCertificate
newDescribeCertificate :: Text -> Text -> DescribeCertificate
newDescribeCertificate Text
pDirectoryId_ Text
pCertificateId_ =
  DescribeCertificate' :: Text -> Text -> DescribeCertificate
DescribeCertificate'
    { $sel:directoryId:DescribeCertificate' :: Text
directoryId = Text
pDirectoryId_,
      $sel:certificateId:DescribeCertificate' :: Text
certificateId = Text
pCertificateId_
    }

-- | The identifier of the directory.
describeCertificate_directoryId :: Lens.Lens' DescribeCertificate Prelude.Text
describeCertificate_directoryId :: (Text -> f Text) -> DescribeCertificate -> f DescribeCertificate
describeCertificate_directoryId = (DescribeCertificate -> Text)
-> (DescribeCertificate -> Text -> DescribeCertificate)
-> Lens DescribeCertificate DescribeCertificate Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeCertificate' {Text
directoryId :: Text
$sel:directoryId:DescribeCertificate' :: DescribeCertificate -> Text
directoryId} -> Text
directoryId) (\s :: DescribeCertificate
s@DescribeCertificate' {} Text
a -> DescribeCertificate
s {$sel:directoryId:DescribeCertificate' :: Text
directoryId = Text
a} :: DescribeCertificate)

-- | The identifier of the certificate.
describeCertificate_certificateId :: Lens.Lens' DescribeCertificate Prelude.Text
describeCertificate_certificateId :: (Text -> f Text) -> DescribeCertificate -> f DescribeCertificate
describeCertificate_certificateId = (DescribeCertificate -> Text)
-> (DescribeCertificate -> Text -> DescribeCertificate)
-> Lens DescribeCertificate DescribeCertificate Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeCertificate' {Text
certificateId :: Text
$sel:certificateId:DescribeCertificate' :: DescribeCertificate -> Text
certificateId} -> Text
certificateId) (\s :: DescribeCertificate
s@DescribeCertificate' {} Text
a -> DescribeCertificate
s {$sel:certificateId:DescribeCertificate' :: Text
certificateId = Text
a} :: DescribeCertificate)

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

instance Prelude.NFData DescribeCertificate

instance Core.ToHeaders DescribeCertificate where
  toHeaders :: DescribeCertificate -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeCertificate -> 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
"DirectoryService_20150416.DescribeCertificate" ::
                          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 DescribeCertificate where
  toJSON :: DescribeCertificate -> Value
toJSON DescribeCertificate' {Text
certificateId :: Text
directoryId :: Text
$sel:certificateId:DescribeCertificate' :: DescribeCertificate -> Text
$sel:directoryId:DescribeCertificate' :: DescribeCertificate -> 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
"DirectoryId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
directoryId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"CertificateId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
certificateId)
          ]
      )

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

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

-- | /See:/ 'newDescribeCertificateResponse' smart constructor.
data DescribeCertificateResponse = DescribeCertificateResponse'
  { -- | Information about the certificate, including registered date time,
    -- certificate state, the reason for the state, expiration date time, and
    -- certificate common name.
    DescribeCertificateResponse -> Maybe Certificate
certificate :: Prelude.Maybe Certificate,
    -- | The response's http status code.
    DescribeCertificateResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeCertificateResponse -> DescribeCertificateResponse -> Bool
(DescribeCertificateResponse
 -> DescribeCertificateResponse -> Bool)
-> (DescribeCertificateResponse
    -> DescribeCertificateResponse -> Bool)
-> Eq DescribeCertificateResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeCertificateResponse -> DescribeCertificateResponse -> Bool
$c/= :: DescribeCertificateResponse -> DescribeCertificateResponse -> Bool
== :: DescribeCertificateResponse -> DescribeCertificateResponse -> Bool
$c== :: DescribeCertificateResponse -> DescribeCertificateResponse -> Bool
Prelude.Eq, ReadPrec [DescribeCertificateResponse]
ReadPrec DescribeCertificateResponse
Int -> ReadS DescribeCertificateResponse
ReadS [DescribeCertificateResponse]
(Int -> ReadS DescribeCertificateResponse)
-> ReadS [DescribeCertificateResponse]
-> ReadPrec DescribeCertificateResponse
-> ReadPrec [DescribeCertificateResponse]
-> Read DescribeCertificateResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeCertificateResponse]
$creadListPrec :: ReadPrec [DescribeCertificateResponse]
readPrec :: ReadPrec DescribeCertificateResponse
$creadPrec :: ReadPrec DescribeCertificateResponse
readList :: ReadS [DescribeCertificateResponse]
$creadList :: ReadS [DescribeCertificateResponse]
readsPrec :: Int -> ReadS DescribeCertificateResponse
$creadsPrec :: Int -> ReadS DescribeCertificateResponse
Prelude.Read, Int -> DescribeCertificateResponse -> ShowS
[DescribeCertificateResponse] -> ShowS
DescribeCertificateResponse -> String
(Int -> DescribeCertificateResponse -> ShowS)
-> (DescribeCertificateResponse -> String)
-> ([DescribeCertificateResponse] -> ShowS)
-> Show DescribeCertificateResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeCertificateResponse] -> ShowS
$cshowList :: [DescribeCertificateResponse] -> ShowS
show :: DescribeCertificateResponse -> String
$cshow :: DescribeCertificateResponse -> String
showsPrec :: Int -> DescribeCertificateResponse -> ShowS
$cshowsPrec :: Int -> DescribeCertificateResponse -> ShowS
Prelude.Show, (forall x.
 DescribeCertificateResponse -> Rep DescribeCertificateResponse x)
-> (forall x.
    Rep DescribeCertificateResponse x -> DescribeCertificateResponse)
-> Generic DescribeCertificateResponse
forall x.
Rep DescribeCertificateResponse x -> DescribeCertificateResponse
forall x.
DescribeCertificateResponse -> Rep DescribeCertificateResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeCertificateResponse x -> DescribeCertificateResponse
$cfrom :: forall x.
DescribeCertificateResponse -> Rep DescribeCertificateResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeCertificateResponse' 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', 'describeCertificateResponse_certificate' - Information about the certificate, including registered date time,
-- certificate state, the reason for the state, expiration date time, and
-- certificate common name.
--
-- 'httpStatus', 'describeCertificateResponse_httpStatus' - The response's http status code.
newDescribeCertificateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeCertificateResponse
newDescribeCertificateResponse :: Int -> DescribeCertificateResponse
newDescribeCertificateResponse Int
pHttpStatus_ =
  DescribeCertificateResponse' :: Maybe Certificate -> Int -> DescribeCertificateResponse
DescribeCertificateResponse'
    { $sel:certificate:DescribeCertificateResponse' :: Maybe Certificate
certificate =
        Maybe Certificate
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeCertificateResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the certificate, including registered date time,
-- certificate state, the reason for the state, expiration date time, and
-- certificate common name.
describeCertificateResponse_certificate :: Lens.Lens' DescribeCertificateResponse (Prelude.Maybe Certificate)
describeCertificateResponse_certificate :: (Maybe Certificate -> f (Maybe Certificate))
-> DescribeCertificateResponse -> f DescribeCertificateResponse
describeCertificateResponse_certificate = (DescribeCertificateResponse -> Maybe Certificate)
-> (DescribeCertificateResponse
    -> Maybe Certificate -> DescribeCertificateResponse)
-> Lens
     DescribeCertificateResponse
     DescribeCertificateResponse
     (Maybe Certificate)
     (Maybe Certificate)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeCertificateResponse' {Maybe Certificate
certificate :: Maybe Certificate
$sel:certificate:DescribeCertificateResponse' :: DescribeCertificateResponse -> Maybe Certificate
certificate} -> Maybe Certificate
certificate) (\s :: DescribeCertificateResponse
s@DescribeCertificateResponse' {} Maybe Certificate
a -> DescribeCertificateResponse
s {$sel:certificate:DescribeCertificateResponse' :: Maybe Certificate
certificate = Maybe Certificate
a} :: DescribeCertificateResponse)

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

instance Prelude.NFData DescribeCertificateResponse