{-# 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.CloudFront.GetPublicKeyConfig
-- 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)
--
-- Gets a public key configuration.
module Amazonka.CloudFront.GetPublicKeyConfig
  ( -- * Creating a Request
    GetPublicKeyConfig (..),
    newGetPublicKeyConfig,

    -- * Request Lenses
    getPublicKeyConfig_id,

    -- * Destructuring the Response
    GetPublicKeyConfigResponse (..),
    newGetPublicKeyConfigResponse,

    -- * Response Lenses
    getPublicKeyConfigResponse_eTag,
    getPublicKeyConfigResponse_publicKeyConfig,
    getPublicKeyConfigResponse_httpStatus,
  )
where

import Amazonka.CloudFront.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:/ 'newGetPublicKeyConfig' smart constructor.
data GetPublicKeyConfig = GetPublicKeyConfig'
  { -- | The identifier of the public key whose configuration you are getting.
    GetPublicKeyConfig -> Text
id :: Prelude.Text
  }
  deriving (GetPublicKeyConfig -> GetPublicKeyConfig -> Bool
(GetPublicKeyConfig -> GetPublicKeyConfig -> Bool)
-> (GetPublicKeyConfig -> GetPublicKeyConfig -> Bool)
-> Eq GetPublicKeyConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetPublicKeyConfig -> GetPublicKeyConfig -> Bool
$c/= :: GetPublicKeyConfig -> GetPublicKeyConfig -> Bool
== :: GetPublicKeyConfig -> GetPublicKeyConfig -> Bool
$c== :: GetPublicKeyConfig -> GetPublicKeyConfig -> Bool
Prelude.Eq, ReadPrec [GetPublicKeyConfig]
ReadPrec GetPublicKeyConfig
Int -> ReadS GetPublicKeyConfig
ReadS [GetPublicKeyConfig]
(Int -> ReadS GetPublicKeyConfig)
-> ReadS [GetPublicKeyConfig]
-> ReadPrec GetPublicKeyConfig
-> ReadPrec [GetPublicKeyConfig]
-> Read GetPublicKeyConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetPublicKeyConfig]
$creadListPrec :: ReadPrec [GetPublicKeyConfig]
readPrec :: ReadPrec GetPublicKeyConfig
$creadPrec :: ReadPrec GetPublicKeyConfig
readList :: ReadS [GetPublicKeyConfig]
$creadList :: ReadS [GetPublicKeyConfig]
readsPrec :: Int -> ReadS GetPublicKeyConfig
$creadsPrec :: Int -> ReadS GetPublicKeyConfig
Prelude.Read, Int -> GetPublicKeyConfig -> ShowS
[GetPublicKeyConfig] -> ShowS
GetPublicKeyConfig -> String
(Int -> GetPublicKeyConfig -> ShowS)
-> (GetPublicKeyConfig -> String)
-> ([GetPublicKeyConfig] -> ShowS)
-> Show GetPublicKeyConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetPublicKeyConfig] -> ShowS
$cshowList :: [GetPublicKeyConfig] -> ShowS
show :: GetPublicKeyConfig -> String
$cshow :: GetPublicKeyConfig -> String
showsPrec :: Int -> GetPublicKeyConfig -> ShowS
$cshowsPrec :: Int -> GetPublicKeyConfig -> ShowS
Prelude.Show, (forall x. GetPublicKeyConfig -> Rep GetPublicKeyConfig x)
-> (forall x. Rep GetPublicKeyConfig x -> GetPublicKeyConfig)
-> Generic GetPublicKeyConfig
forall x. Rep GetPublicKeyConfig x -> GetPublicKeyConfig
forall x. GetPublicKeyConfig -> Rep GetPublicKeyConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetPublicKeyConfig x -> GetPublicKeyConfig
$cfrom :: forall x. GetPublicKeyConfig -> Rep GetPublicKeyConfig x
Prelude.Generic)

-- |
-- Create a value of 'GetPublicKeyConfig' 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:
--
-- 'id', 'getPublicKeyConfig_id' - The identifier of the public key whose configuration you are getting.
newGetPublicKeyConfig ::
  -- | 'id'
  Prelude.Text ->
  GetPublicKeyConfig
newGetPublicKeyConfig :: Text -> GetPublicKeyConfig
newGetPublicKeyConfig Text
pId_ =
  GetPublicKeyConfig' :: Text -> GetPublicKeyConfig
GetPublicKeyConfig' {$sel:id:GetPublicKeyConfig' :: Text
id = Text
pId_}

-- | The identifier of the public key whose configuration you are getting.
getPublicKeyConfig_id :: Lens.Lens' GetPublicKeyConfig Prelude.Text
getPublicKeyConfig_id :: (Text -> f Text) -> GetPublicKeyConfig -> f GetPublicKeyConfig
getPublicKeyConfig_id = (GetPublicKeyConfig -> Text)
-> (GetPublicKeyConfig -> Text -> GetPublicKeyConfig)
-> Lens GetPublicKeyConfig GetPublicKeyConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPublicKeyConfig' {Text
id :: Text
$sel:id:GetPublicKeyConfig' :: GetPublicKeyConfig -> Text
id} -> Text
id) (\s :: GetPublicKeyConfig
s@GetPublicKeyConfig' {} Text
a -> GetPublicKeyConfig
s {$sel:id:GetPublicKeyConfig' :: Text
id = Text
a} :: GetPublicKeyConfig)

instance Core.AWSRequest GetPublicKeyConfig where
  type
    AWSResponse GetPublicKeyConfig =
      GetPublicKeyConfigResponse
  request :: GetPublicKeyConfig -> Request GetPublicKeyConfig
request = Service -> GetPublicKeyConfig -> Request GetPublicKeyConfig
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetPublicKeyConfig
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetPublicKeyConfig)))
response =
    (Int
 -> ResponseHeaders
 -> [Node]
 -> Either String (AWSResponse GetPublicKeyConfig))
-> Logger
-> Service
-> Proxy GetPublicKeyConfig
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetPublicKeyConfig)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXML
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Text
-> Maybe PublicKeyConfig -> Int -> GetPublicKeyConfigResponse
GetPublicKeyConfigResponse'
            (Maybe Text
 -> Maybe PublicKeyConfig -> Int -> GetPublicKeyConfigResponse)
-> Either String (Maybe Text)
-> Either
     String (Maybe PublicKeyConfig -> Int -> GetPublicKeyConfigResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (ResponseHeaders
h ResponseHeaders -> HeaderName -> Either String (Maybe Text)
forall a.
FromText a =>
ResponseHeaders -> HeaderName -> Either String (Maybe a)
Core..#? HeaderName
"ETag")
            Either
  String (Maybe PublicKeyConfig -> Int -> GetPublicKeyConfigResponse)
-> Either String (Maybe PublicKeyConfig)
-> Either String (Int -> GetPublicKeyConfigResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node] -> Either String (Maybe PublicKeyConfig)
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)
            Either String (Int -> GetPublicKeyConfigResponse)
-> Either String Int -> Either String GetPublicKeyConfigResponse
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 GetPublicKeyConfig

instance Prelude.NFData GetPublicKeyConfig

instance Core.ToHeaders GetPublicKeyConfig where
  toHeaders :: GetPublicKeyConfig -> ResponseHeaders
toHeaders = ResponseHeaders -> GetPublicKeyConfig -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToPath GetPublicKeyConfig where
  toPath :: GetPublicKeyConfig -> ByteString
toPath GetPublicKeyConfig' {Text
id :: Text
$sel:id:GetPublicKeyConfig' :: GetPublicKeyConfig -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/2020-05-31/public-key/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
id, ByteString
"/config"]

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

-- | /See:/ 'newGetPublicKeyConfigResponse' smart constructor.
data GetPublicKeyConfigResponse = GetPublicKeyConfigResponse'
  { -- | The identifier for this version of the public key configuration.
    GetPublicKeyConfigResponse -> Maybe Text
eTag :: Prelude.Maybe Prelude.Text,
    -- | A public key configuration.
    GetPublicKeyConfigResponse -> Maybe PublicKeyConfig
publicKeyConfig :: Prelude.Maybe PublicKeyConfig,
    -- | The response's http status code.
    GetPublicKeyConfigResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetPublicKeyConfigResponse -> GetPublicKeyConfigResponse -> Bool
(GetPublicKeyConfigResponse -> GetPublicKeyConfigResponse -> Bool)
-> (GetPublicKeyConfigResponse
    -> GetPublicKeyConfigResponse -> Bool)
-> Eq GetPublicKeyConfigResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetPublicKeyConfigResponse -> GetPublicKeyConfigResponse -> Bool
$c/= :: GetPublicKeyConfigResponse -> GetPublicKeyConfigResponse -> Bool
== :: GetPublicKeyConfigResponse -> GetPublicKeyConfigResponse -> Bool
$c== :: GetPublicKeyConfigResponse -> GetPublicKeyConfigResponse -> Bool
Prelude.Eq, ReadPrec [GetPublicKeyConfigResponse]
ReadPrec GetPublicKeyConfigResponse
Int -> ReadS GetPublicKeyConfigResponse
ReadS [GetPublicKeyConfigResponse]
(Int -> ReadS GetPublicKeyConfigResponse)
-> ReadS [GetPublicKeyConfigResponse]
-> ReadPrec GetPublicKeyConfigResponse
-> ReadPrec [GetPublicKeyConfigResponse]
-> Read GetPublicKeyConfigResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetPublicKeyConfigResponse]
$creadListPrec :: ReadPrec [GetPublicKeyConfigResponse]
readPrec :: ReadPrec GetPublicKeyConfigResponse
$creadPrec :: ReadPrec GetPublicKeyConfigResponse
readList :: ReadS [GetPublicKeyConfigResponse]
$creadList :: ReadS [GetPublicKeyConfigResponse]
readsPrec :: Int -> ReadS GetPublicKeyConfigResponse
$creadsPrec :: Int -> ReadS GetPublicKeyConfigResponse
Prelude.Read, Int -> GetPublicKeyConfigResponse -> ShowS
[GetPublicKeyConfigResponse] -> ShowS
GetPublicKeyConfigResponse -> String
(Int -> GetPublicKeyConfigResponse -> ShowS)
-> (GetPublicKeyConfigResponse -> String)
-> ([GetPublicKeyConfigResponse] -> ShowS)
-> Show GetPublicKeyConfigResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetPublicKeyConfigResponse] -> ShowS
$cshowList :: [GetPublicKeyConfigResponse] -> ShowS
show :: GetPublicKeyConfigResponse -> String
$cshow :: GetPublicKeyConfigResponse -> String
showsPrec :: Int -> GetPublicKeyConfigResponse -> ShowS
$cshowsPrec :: Int -> GetPublicKeyConfigResponse -> ShowS
Prelude.Show, (forall x.
 GetPublicKeyConfigResponse -> Rep GetPublicKeyConfigResponse x)
-> (forall x.
    Rep GetPublicKeyConfigResponse x -> GetPublicKeyConfigResponse)
-> Generic GetPublicKeyConfigResponse
forall x.
Rep GetPublicKeyConfigResponse x -> GetPublicKeyConfigResponse
forall x.
GetPublicKeyConfigResponse -> Rep GetPublicKeyConfigResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetPublicKeyConfigResponse x -> GetPublicKeyConfigResponse
$cfrom :: forall x.
GetPublicKeyConfigResponse -> Rep GetPublicKeyConfigResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetPublicKeyConfigResponse' 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:
--
-- 'eTag', 'getPublicKeyConfigResponse_eTag' - The identifier for this version of the public key configuration.
--
-- 'publicKeyConfig', 'getPublicKeyConfigResponse_publicKeyConfig' - A public key configuration.
--
-- 'httpStatus', 'getPublicKeyConfigResponse_httpStatus' - The response's http status code.
newGetPublicKeyConfigResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetPublicKeyConfigResponse
newGetPublicKeyConfigResponse :: Int -> GetPublicKeyConfigResponse
newGetPublicKeyConfigResponse Int
pHttpStatus_ =
  GetPublicKeyConfigResponse' :: Maybe Text
-> Maybe PublicKeyConfig -> Int -> GetPublicKeyConfigResponse
GetPublicKeyConfigResponse'
    { $sel:eTag:GetPublicKeyConfigResponse' :: Maybe Text
eTag = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:publicKeyConfig:GetPublicKeyConfigResponse' :: Maybe PublicKeyConfig
publicKeyConfig = Maybe PublicKeyConfig
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetPublicKeyConfigResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The identifier for this version of the public key configuration.
getPublicKeyConfigResponse_eTag :: Lens.Lens' GetPublicKeyConfigResponse (Prelude.Maybe Prelude.Text)
getPublicKeyConfigResponse_eTag :: (Maybe Text -> f (Maybe Text))
-> GetPublicKeyConfigResponse -> f GetPublicKeyConfigResponse
getPublicKeyConfigResponse_eTag = (GetPublicKeyConfigResponse -> Maybe Text)
-> (GetPublicKeyConfigResponse
    -> Maybe Text -> GetPublicKeyConfigResponse)
-> Lens
     GetPublicKeyConfigResponse
     GetPublicKeyConfigResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPublicKeyConfigResponse' {Maybe Text
eTag :: Maybe Text
$sel:eTag:GetPublicKeyConfigResponse' :: GetPublicKeyConfigResponse -> Maybe Text
eTag} -> Maybe Text
eTag) (\s :: GetPublicKeyConfigResponse
s@GetPublicKeyConfigResponse' {} Maybe Text
a -> GetPublicKeyConfigResponse
s {$sel:eTag:GetPublicKeyConfigResponse' :: Maybe Text
eTag = Maybe Text
a} :: GetPublicKeyConfigResponse)

-- | A public key configuration.
getPublicKeyConfigResponse_publicKeyConfig :: Lens.Lens' GetPublicKeyConfigResponse (Prelude.Maybe PublicKeyConfig)
getPublicKeyConfigResponse_publicKeyConfig :: (Maybe PublicKeyConfig -> f (Maybe PublicKeyConfig))
-> GetPublicKeyConfigResponse -> f GetPublicKeyConfigResponse
getPublicKeyConfigResponse_publicKeyConfig = (GetPublicKeyConfigResponse -> Maybe PublicKeyConfig)
-> (GetPublicKeyConfigResponse
    -> Maybe PublicKeyConfig -> GetPublicKeyConfigResponse)
-> Lens
     GetPublicKeyConfigResponse
     GetPublicKeyConfigResponse
     (Maybe PublicKeyConfig)
     (Maybe PublicKeyConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPublicKeyConfigResponse' {Maybe PublicKeyConfig
publicKeyConfig :: Maybe PublicKeyConfig
$sel:publicKeyConfig:GetPublicKeyConfigResponse' :: GetPublicKeyConfigResponse -> Maybe PublicKeyConfig
publicKeyConfig} -> Maybe PublicKeyConfig
publicKeyConfig) (\s :: GetPublicKeyConfigResponse
s@GetPublicKeyConfigResponse' {} Maybe PublicKeyConfig
a -> GetPublicKeyConfigResponse
s {$sel:publicKeyConfig:GetPublicKeyConfigResponse' :: Maybe PublicKeyConfig
publicKeyConfig = Maybe PublicKeyConfig
a} :: GetPublicKeyConfigResponse)

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

instance Prelude.NFData GetPublicKeyConfigResponse