{-# 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.GetPublicKey
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Gets a public key.
module Amazonka.CloudFront.GetPublicKey
  ( -- * Creating a Request
    GetPublicKey (..),
    newGetPublicKey,

    -- * Request Lenses
    getPublicKey_id,

    -- * Destructuring the Response
    GetPublicKeyResponse (..),
    newGetPublicKeyResponse,

    -- * Response Lenses
    getPublicKeyResponse_eTag,
    getPublicKeyResponse_publicKey,
    getPublicKeyResponse_httpStatus,
  )
where

import Amazonka.CloudFront.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

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

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

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

instance Core.AWSRequest GetPublicKey where
  type AWSResponse GetPublicKey = GetPublicKeyResponse
  request :: (Service -> Service) -> GetPublicKey -> Request GetPublicKey
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetPublicKey
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetPublicKey)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXML
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe Text -> Maybe PublicKey -> Int -> GetPublicKeyResponse
GetPublicKeyResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (ResponseHeaders
h forall a.
FromText a =>
ResponseHeaders -> HeaderName -> Either String (Maybe a)
Data..#? HeaderName
"ETag")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall a. FromXML a => [Node] -> Either String a
Data.parseXML [Node]
x)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetPublicKey where
  hashWithSalt :: Int -> GetPublicKey -> Int
hashWithSalt Int
_salt GetPublicKey' {Text
id :: Text
$sel:id:GetPublicKey' :: GetPublicKey -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id

instance Prelude.NFData GetPublicKey where
  rnf :: GetPublicKey -> ()
rnf GetPublicKey' {Text
id :: Text
$sel:id:GetPublicKey' :: GetPublicKey -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
id

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

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

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

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

-- |
-- Create a value of 'GetPublicKeyResponse' 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', 'getPublicKeyResponse_eTag' - The identifier for this version of the public key.
--
-- 'publicKey', 'getPublicKeyResponse_publicKey' - The public key.
--
-- 'httpStatus', 'getPublicKeyResponse_httpStatus' - The response's http status code.
newGetPublicKeyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetPublicKeyResponse
newGetPublicKeyResponse :: Int -> GetPublicKeyResponse
newGetPublicKeyResponse Int
pHttpStatus_ =
  GetPublicKeyResponse'
    { $sel:eTag:GetPublicKeyResponse' :: Maybe Text
eTag = forall a. Maybe a
Prelude.Nothing,
      $sel:publicKey:GetPublicKeyResponse' :: Maybe PublicKey
publicKey = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetPublicKeyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

-- | The public key.
getPublicKeyResponse_publicKey :: Lens.Lens' GetPublicKeyResponse (Prelude.Maybe PublicKey)
getPublicKeyResponse_publicKey :: Lens' GetPublicKeyResponse (Maybe PublicKey)
getPublicKeyResponse_publicKey = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetPublicKeyResponse' {Maybe PublicKey
publicKey :: Maybe PublicKey
$sel:publicKey:GetPublicKeyResponse' :: GetPublicKeyResponse -> Maybe PublicKey
publicKey} -> Maybe PublicKey
publicKey) (\s :: GetPublicKeyResponse
s@GetPublicKeyResponse' {} Maybe PublicKey
a -> GetPublicKeyResponse
s {$sel:publicKey:GetPublicKeyResponse' :: Maybe PublicKey
publicKey = Maybe PublicKey
a} :: GetPublicKeyResponse)

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

instance Prelude.NFData GetPublicKeyResponse where
  rnf :: GetPublicKeyResponse -> ()
rnf GetPublicKeyResponse' {Int
Maybe Text
Maybe PublicKey
httpStatus :: Int
publicKey :: Maybe PublicKey
eTag :: Maybe Text
$sel:httpStatus:GetPublicKeyResponse' :: GetPublicKeyResponse -> Int
$sel:publicKey:GetPublicKeyResponse' :: GetPublicKeyResponse -> Maybe PublicKey
$sel:eTag:GetPublicKeyResponse' :: GetPublicKeyResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
eTag
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe PublicKey
publicKey
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus