{-# 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.APIGateway.GenerateClientCertificate
-- 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)
--
-- Generates a ClientCertificate resource.
module Amazonka.APIGateway.GenerateClientCertificate
  ( -- * Creating a Request
    GenerateClientCertificate (..),
    newGenerateClientCertificate,

    -- * Request Lenses
    generateClientCertificate_description,
    generateClientCertificate_tags,

    -- * Destructuring the Response
    ClientCertificate (..),
    newClientCertificate,

    -- * Response Lenses
    clientCertificate_pemEncodedCertificate,
    clientCertificate_clientCertificateId,
    clientCertificate_createdDate,
    clientCertificate_expirationDate,
    clientCertificate_description,
    clientCertificate_tags,
  )
where

import Amazonka.APIGateway.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

-- | A request to generate a ClientCertificate resource.
--
-- /See:/ 'newGenerateClientCertificate' smart constructor.
data GenerateClientCertificate = GenerateClientCertificate'
  { -- | The description of the ClientCertificate.
    GenerateClientCertificate -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The key-value map of strings. The valid character set is
    -- [a-zA-Z+-=._:\/]. The tag key can be up to 128 characters and must not
    -- start with @aws:@. The tag value can be up to 256 characters.
    GenerateClientCertificate -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text)
  }
  deriving (GenerateClientCertificate -> GenerateClientCertificate -> Bool
(GenerateClientCertificate -> GenerateClientCertificate -> Bool)
-> (GenerateClientCertificate -> GenerateClientCertificate -> Bool)
-> Eq GenerateClientCertificate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GenerateClientCertificate -> GenerateClientCertificate -> Bool
$c/= :: GenerateClientCertificate -> GenerateClientCertificate -> Bool
== :: GenerateClientCertificate -> GenerateClientCertificate -> Bool
$c== :: GenerateClientCertificate -> GenerateClientCertificate -> Bool
Prelude.Eq, ReadPrec [GenerateClientCertificate]
ReadPrec GenerateClientCertificate
Int -> ReadS GenerateClientCertificate
ReadS [GenerateClientCertificate]
(Int -> ReadS GenerateClientCertificate)
-> ReadS [GenerateClientCertificate]
-> ReadPrec GenerateClientCertificate
-> ReadPrec [GenerateClientCertificate]
-> Read GenerateClientCertificate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GenerateClientCertificate]
$creadListPrec :: ReadPrec [GenerateClientCertificate]
readPrec :: ReadPrec GenerateClientCertificate
$creadPrec :: ReadPrec GenerateClientCertificate
readList :: ReadS [GenerateClientCertificate]
$creadList :: ReadS [GenerateClientCertificate]
readsPrec :: Int -> ReadS GenerateClientCertificate
$creadsPrec :: Int -> ReadS GenerateClientCertificate
Prelude.Read, Int -> GenerateClientCertificate -> ShowS
[GenerateClientCertificate] -> ShowS
GenerateClientCertificate -> String
(Int -> GenerateClientCertificate -> ShowS)
-> (GenerateClientCertificate -> String)
-> ([GenerateClientCertificate] -> ShowS)
-> Show GenerateClientCertificate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GenerateClientCertificate] -> ShowS
$cshowList :: [GenerateClientCertificate] -> ShowS
show :: GenerateClientCertificate -> String
$cshow :: GenerateClientCertificate -> String
showsPrec :: Int -> GenerateClientCertificate -> ShowS
$cshowsPrec :: Int -> GenerateClientCertificate -> ShowS
Prelude.Show, (forall x.
 GenerateClientCertificate -> Rep GenerateClientCertificate x)
-> (forall x.
    Rep GenerateClientCertificate x -> GenerateClientCertificate)
-> Generic GenerateClientCertificate
forall x.
Rep GenerateClientCertificate x -> GenerateClientCertificate
forall x.
GenerateClientCertificate -> Rep GenerateClientCertificate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GenerateClientCertificate x -> GenerateClientCertificate
$cfrom :: forall x.
GenerateClientCertificate -> Rep GenerateClientCertificate x
Prelude.Generic)

-- |
-- Create a value of 'GenerateClientCertificate' 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:
--
-- 'description', 'generateClientCertificate_description' - The description of the ClientCertificate.
--
-- 'tags', 'generateClientCertificate_tags' - The key-value map of strings. The valid character set is
-- [a-zA-Z+-=._:\/]. The tag key can be up to 128 characters and must not
-- start with @aws:@. The tag value can be up to 256 characters.
newGenerateClientCertificate ::
  GenerateClientCertificate
newGenerateClientCertificate :: GenerateClientCertificate
newGenerateClientCertificate =
  GenerateClientCertificate' :: Maybe Text
-> Maybe (HashMap Text Text) -> GenerateClientCertificate
GenerateClientCertificate'
    { $sel:description:GenerateClientCertificate' :: Maybe Text
description =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:tags:GenerateClientCertificate' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing
    }

-- | The description of the ClientCertificate.
generateClientCertificate_description :: Lens.Lens' GenerateClientCertificate (Prelude.Maybe Prelude.Text)
generateClientCertificate_description :: (Maybe Text -> f (Maybe Text))
-> GenerateClientCertificate -> f GenerateClientCertificate
generateClientCertificate_description = (GenerateClientCertificate -> Maybe Text)
-> (GenerateClientCertificate
    -> Maybe Text -> GenerateClientCertificate)
-> Lens
     GenerateClientCertificate
     GenerateClientCertificate
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GenerateClientCertificate' {Maybe Text
description :: Maybe Text
$sel:description:GenerateClientCertificate' :: GenerateClientCertificate -> Maybe Text
description} -> Maybe Text
description) (\s :: GenerateClientCertificate
s@GenerateClientCertificate' {} Maybe Text
a -> GenerateClientCertificate
s {$sel:description:GenerateClientCertificate' :: Maybe Text
description = Maybe Text
a} :: GenerateClientCertificate)

-- | The key-value map of strings. The valid character set is
-- [a-zA-Z+-=._:\/]. The tag key can be up to 128 characters and must not
-- start with @aws:@. The tag value can be up to 256 characters.
generateClientCertificate_tags :: Lens.Lens' GenerateClientCertificate (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
generateClientCertificate_tags :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GenerateClientCertificate -> f GenerateClientCertificate
generateClientCertificate_tags = (GenerateClientCertificate -> Maybe (HashMap Text Text))
-> (GenerateClientCertificate
    -> Maybe (HashMap Text Text) -> GenerateClientCertificate)
-> Lens
     GenerateClientCertificate
     GenerateClientCertificate
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GenerateClientCertificate' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:GenerateClientCertificate' :: GenerateClientCertificate -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: GenerateClientCertificate
s@GenerateClientCertificate' {} Maybe (HashMap Text Text)
a -> GenerateClientCertificate
s {$sel:tags:GenerateClientCertificate' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: GenerateClientCertificate) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> GenerateClientCertificate -> f GenerateClientCertificate)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GenerateClientCertificate
-> f GenerateClientCertificate
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest GenerateClientCertificate where
  type
    AWSResponse GenerateClientCertificate =
      ClientCertificate
  request :: GenerateClientCertificate -> Request GenerateClientCertificate
request = Service
-> GenerateClientCertificate -> Request GenerateClientCertificate
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GenerateClientCertificate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GenerateClientCertificate)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GenerateClientCertificate))
-> Logger
-> Service
-> Proxy GenerateClientCertificate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GenerateClientCertificate)))
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 -> Object -> Either String ClientCertificate
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable GenerateClientCertificate

instance Prelude.NFData GenerateClientCertificate

instance Core.ToHeaders GenerateClientCertificate where
  toHeaders :: GenerateClientCertificate -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GenerateClientCertificate -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Accept"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"application/json" :: Prelude.ByteString)
          ]
      )

instance Core.ToJSON GenerateClientCertificate where
  toJSON :: GenerateClientCertificate -> Value
toJSON GenerateClientCertificate' {Maybe Text
Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
description :: Maybe Text
$sel:tags:GenerateClientCertificate' :: GenerateClientCertificate -> Maybe (HashMap Text Text)
$sel:description:GenerateClientCertificate' :: GenerateClientCertificate -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"description" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
description,
            (Text
"tags" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
tags
          ]
      )

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

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