{-# 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.UpdatePublicKey
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Update public key information. Note that the only value you can change
-- is the comment.
module Amazonka.CloudFront.UpdatePublicKey
  ( -- * Creating a Request
    UpdatePublicKey (..),
    newUpdatePublicKey,

    -- * Request Lenses
    updatePublicKey_ifMatch,
    updatePublicKey_publicKeyConfig,
    updatePublicKey_id,

    -- * Destructuring the Response
    UpdatePublicKeyResponse (..),
    newUpdatePublicKeyResponse,

    -- * Response Lenses
    updatePublicKeyResponse_eTag,
    updatePublicKeyResponse_publicKey,
    updatePublicKeyResponse_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:/ 'newUpdatePublicKey' smart constructor.
data UpdatePublicKey = UpdatePublicKey'
  { -- | The value of the @ETag@ header that you received when retrieving the
    -- public key to update. For example: @E2QWRUHAPOMQZL@.
    UpdatePublicKey -> Maybe Text
ifMatch :: Prelude.Maybe Prelude.Text,
    -- | A public key configuration.
    UpdatePublicKey -> PublicKeyConfig
publicKeyConfig :: PublicKeyConfig,
    -- | The identifier of the public key that you are updating.
    UpdatePublicKey -> Text
id :: Prelude.Text
  }
  deriving (UpdatePublicKey -> UpdatePublicKey -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdatePublicKey -> UpdatePublicKey -> Bool
$c/= :: UpdatePublicKey -> UpdatePublicKey -> Bool
== :: UpdatePublicKey -> UpdatePublicKey -> Bool
$c== :: UpdatePublicKey -> UpdatePublicKey -> Bool
Prelude.Eq, ReadPrec [UpdatePublicKey]
ReadPrec UpdatePublicKey
Int -> ReadS UpdatePublicKey
ReadS [UpdatePublicKey]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdatePublicKey]
$creadListPrec :: ReadPrec [UpdatePublicKey]
readPrec :: ReadPrec UpdatePublicKey
$creadPrec :: ReadPrec UpdatePublicKey
readList :: ReadS [UpdatePublicKey]
$creadList :: ReadS [UpdatePublicKey]
readsPrec :: Int -> ReadS UpdatePublicKey
$creadsPrec :: Int -> ReadS UpdatePublicKey
Prelude.Read, Int -> UpdatePublicKey -> ShowS
[UpdatePublicKey] -> ShowS
UpdatePublicKey -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdatePublicKey] -> ShowS
$cshowList :: [UpdatePublicKey] -> ShowS
show :: UpdatePublicKey -> String
$cshow :: UpdatePublicKey -> String
showsPrec :: Int -> UpdatePublicKey -> ShowS
$cshowsPrec :: Int -> UpdatePublicKey -> ShowS
Prelude.Show, forall x. Rep UpdatePublicKey x -> UpdatePublicKey
forall x. UpdatePublicKey -> Rep UpdatePublicKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdatePublicKey x -> UpdatePublicKey
$cfrom :: forall x. UpdatePublicKey -> Rep UpdatePublicKey x
Prelude.Generic)

-- |
-- Create a value of 'UpdatePublicKey' 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:
--
-- 'ifMatch', 'updatePublicKey_ifMatch' - The value of the @ETag@ header that you received when retrieving the
-- public key to update. For example: @E2QWRUHAPOMQZL@.
--
-- 'publicKeyConfig', 'updatePublicKey_publicKeyConfig' - A public key configuration.
--
-- 'id', 'updatePublicKey_id' - The identifier of the public key that you are updating.
newUpdatePublicKey ::
  -- | 'publicKeyConfig'
  PublicKeyConfig ->
  -- | 'id'
  Prelude.Text ->
  UpdatePublicKey
newUpdatePublicKey :: PublicKeyConfig -> Text -> UpdatePublicKey
newUpdatePublicKey PublicKeyConfig
pPublicKeyConfig_ Text
pId_ =
  UpdatePublicKey'
    { $sel:ifMatch:UpdatePublicKey' :: Maybe Text
ifMatch = forall a. Maybe a
Prelude.Nothing,
      $sel:publicKeyConfig:UpdatePublicKey' :: PublicKeyConfig
publicKeyConfig = PublicKeyConfig
pPublicKeyConfig_,
      $sel:id:UpdatePublicKey' :: Text
id = Text
pId_
    }

-- | The value of the @ETag@ header that you received when retrieving the
-- public key to update. For example: @E2QWRUHAPOMQZL@.
updatePublicKey_ifMatch :: Lens.Lens' UpdatePublicKey (Prelude.Maybe Prelude.Text)
updatePublicKey_ifMatch :: Lens' UpdatePublicKey (Maybe Text)
updatePublicKey_ifMatch = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdatePublicKey' {Maybe Text
ifMatch :: Maybe Text
$sel:ifMatch:UpdatePublicKey' :: UpdatePublicKey -> Maybe Text
ifMatch} -> Maybe Text
ifMatch) (\s :: UpdatePublicKey
s@UpdatePublicKey' {} Maybe Text
a -> UpdatePublicKey
s {$sel:ifMatch:UpdatePublicKey' :: Maybe Text
ifMatch = Maybe Text
a} :: UpdatePublicKey)

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

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

instance Core.AWSRequest UpdatePublicKey where
  type
    AWSResponse UpdatePublicKey =
      UpdatePublicKeyResponse
  request :: (Service -> Service) -> UpdatePublicKey -> Request UpdatePublicKey
request Service -> Service
overrides =
    forall a. (ToRequest a, ToElement a) => Service -> a -> Request a
Request.putXML (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy UpdatePublicKey
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdatePublicKey)))
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 -> UpdatePublicKeyResponse
UpdatePublicKeyResponse'
            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 UpdatePublicKey where
  hashWithSalt :: Int -> UpdatePublicKey -> Int
hashWithSalt Int
_salt UpdatePublicKey' {Maybe Text
Text
PublicKeyConfig
id :: Text
publicKeyConfig :: PublicKeyConfig
ifMatch :: Maybe Text
$sel:id:UpdatePublicKey' :: UpdatePublicKey -> Text
$sel:publicKeyConfig:UpdatePublicKey' :: UpdatePublicKey -> PublicKeyConfig
$sel:ifMatch:UpdatePublicKey' :: UpdatePublicKey -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
ifMatch
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` PublicKeyConfig
publicKeyConfig
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id

instance Prelude.NFData UpdatePublicKey where
  rnf :: UpdatePublicKey -> ()
rnf UpdatePublicKey' {Maybe Text
Text
PublicKeyConfig
id :: Text
publicKeyConfig :: PublicKeyConfig
ifMatch :: Maybe Text
$sel:id:UpdatePublicKey' :: UpdatePublicKey -> Text
$sel:publicKeyConfig:UpdatePublicKey' :: UpdatePublicKey -> PublicKeyConfig
$sel:ifMatch:UpdatePublicKey' :: UpdatePublicKey -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
ifMatch
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf PublicKeyConfig
publicKeyConfig
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
id

instance Data.ToElement UpdatePublicKey where
  toElement :: UpdatePublicKey -> Element
toElement UpdatePublicKey' {Maybe Text
Text
PublicKeyConfig
id :: Text
publicKeyConfig :: PublicKeyConfig
ifMatch :: Maybe Text
$sel:id:UpdatePublicKey' :: UpdatePublicKey -> Text
$sel:publicKeyConfig:UpdatePublicKey' :: UpdatePublicKey -> PublicKeyConfig
$sel:ifMatch:UpdatePublicKey' :: UpdatePublicKey -> Maybe Text
..} =
    forall a. ToXML a => Name -> a -> Element
Data.mkElement
      Name
"{http://cloudfront.amazonaws.com/doc/2020-05-31/}PublicKeyConfig"
      PublicKeyConfig
publicKeyConfig

instance Data.ToHeaders UpdatePublicKey where
  toHeaders :: UpdatePublicKey -> ResponseHeaders
toHeaders UpdatePublicKey' {Maybe Text
Text
PublicKeyConfig
id :: Text
publicKeyConfig :: PublicKeyConfig
ifMatch :: Maybe Text
$sel:id:UpdatePublicKey' :: UpdatePublicKey -> Text
$sel:publicKeyConfig:UpdatePublicKey' :: UpdatePublicKey -> PublicKeyConfig
$sel:ifMatch:UpdatePublicKey' :: UpdatePublicKey -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat [HeaderName
"If-Match" forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# Maybe Text
ifMatch]

instance Data.ToPath UpdatePublicKey where
  toPath :: UpdatePublicKey -> ByteString
toPath UpdatePublicKey' {Maybe Text
Text
PublicKeyConfig
id :: Text
publicKeyConfig :: PublicKeyConfig
ifMatch :: Maybe Text
$sel:id:UpdatePublicKey' :: UpdatePublicKey -> Text
$sel:publicKeyConfig:UpdatePublicKey' :: UpdatePublicKey -> PublicKeyConfig
$sel:ifMatch:UpdatePublicKey' :: UpdatePublicKey -> Maybe 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, ByteString
"/config"]

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

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

-- |
-- Create a value of 'UpdatePublicKeyResponse' 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', 'updatePublicKeyResponse_eTag' - The identifier of the current version of the public key.
--
-- 'publicKey', 'updatePublicKeyResponse_publicKey' - The public key.
--
-- 'httpStatus', 'updatePublicKeyResponse_httpStatus' - The response's http status code.
newUpdatePublicKeyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdatePublicKeyResponse
newUpdatePublicKeyResponse :: Int -> UpdatePublicKeyResponse
newUpdatePublicKeyResponse Int
pHttpStatus_ =
  UpdatePublicKeyResponse'
    { $sel:eTag:UpdatePublicKeyResponse' :: Maybe Text
eTag = forall a. Maybe a
Prelude.Nothing,
      $sel:publicKey:UpdatePublicKeyResponse' :: Maybe PublicKey
publicKey = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:UpdatePublicKeyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

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

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

instance Prelude.NFData UpdatePublicKeyResponse where
  rnf :: UpdatePublicKeyResponse -> ()
rnf UpdatePublicKeyResponse' {Int
Maybe Text
Maybe PublicKey
httpStatus :: Int
publicKey :: Maybe PublicKey
eTag :: Maybe Text
$sel:httpStatus:UpdatePublicKeyResponse' :: UpdatePublicKeyResponse -> Int
$sel:publicKey:UpdatePublicKeyResponse' :: UpdatePublicKeyResponse -> Maybe PublicKey
$sel:eTag:UpdatePublicKeyResponse' :: UpdatePublicKeyResponse -> 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