{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.PublicKeyConfig
-- 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)
module Amazonka.CloudFront.Types.PublicKeyConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Configuration information about a public key that you can use with
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html signed URLs and signed cookies>,
-- or with
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/field-level-encryption.html field-level encryption>.
--
-- /See:/ 'newPublicKeyConfig' smart constructor.
data PublicKeyConfig = PublicKeyConfig'
  { -- | A comment to describe the public key. The comment cannot be longer than
    -- 128 characters.
    PublicKeyConfig -> Maybe Text
comment :: Prelude.Maybe Prelude.Text,
    -- | A string included in the request to help make sure that the request
    -- can’t be replayed.
    PublicKeyConfig -> Text
callerReference :: Prelude.Text,
    -- | A name to help identify the public key.
    PublicKeyConfig -> Text
name :: Prelude.Text,
    -- | The public key that you can use with
    -- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html signed URLs and signed cookies>,
    -- or with
    -- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/field-level-encryption.html field-level encryption>.
    PublicKeyConfig -> Text
encodedKey :: Prelude.Text
  }
  deriving (PublicKeyConfig -> PublicKeyConfig -> Bool
(PublicKeyConfig -> PublicKeyConfig -> Bool)
-> (PublicKeyConfig -> PublicKeyConfig -> Bool)
-> Eq PublicKeyConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PublicKeyConfig -> PublicKeyConfig -> Bool
$c/= :: PublicKeyConfig -> PublicKeyConfig -> Bool
== :: PublicKeyConfig -> PublicKeyConfig -> Bool
$c== :: PublicKeyConfig -> PublicKeyConfig -> Bool
Prelude.Eq, ReadPrec [PublicKeyConfig]
ReadPrec PublicKeyConfig
Int -> ReadS PublicKeyConfig
ReadS [PublicKeyConfig]
(Int -> ReadS PublicKeyConfig)
-> ReadS [PublicKeyConfig]
-> ReadPrec PublicKeyConfig
-> ReadPrec [PublicKeyConfig]
-> Read PublicKeyConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PublicKeyConfig]
$creadListPrec :: ReadPrec [PublicKeyConfig]
readPrec :: ReadPrec PublicKeyConfig
$creadPrec :: ReadPrec PublicKeyConfig
readList :: ReadS [PublicKeyConfig]
$creadList :: ReadS [PublicKeyConfig]
readsPrec :: Int -> ReadS PublicKeyConfig
$creadsPrec :: Int -> ReadS PublicKeyConfig
Prelude.Read, Int -> PublicKeyConfig -> ShowS
[PublicKeyConfig] -> ShowS
PublicKeyConfig -> String
(Int -> PublicKeyConfig -> ShowS)
-> (PublicKeyConfig -> String)
-> ([PublicKeyConfig] -> ShowS)
-> Show PublicKeyConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PublicKeyConfig] -> ShowS
$cshowList :: [PublicKeyConfig] -> ShowS
show :: PublicKeyConfig -> String
$cshow :: PublicKeyConfig -> String
showsPrec :: Int -> PublicKeyConfig -> ShowS
$cshowsPrec :: Int -> PublicKeyConfig -> ShowS
Prelude.Show, (forall x. PublicKeyConfig -> Rep PublicKeyConfig x)
-> (forall x. Rep PublicKeyConfig x -> PublicKeyConfig)
-> Generic PublicKeyConfig
forall x. Rep PublicKeyConfig x -> PublicKeyConfig
forall x. PublicKeyConfig -> Rep PublicKeyConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PublicKeyConfig x -> PublicKeyConfig
$cfrom :: forall x. PublicKeyConfig -> Rep PublicKeyConfig x
Prelude.Generic)

-- |
-- Create a value of 'PublicKeyConfig' 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:
--
-- 'comment', 'publicKeyConfig_comment' - A comment to describe the public key. The comment cannot be longer than
-- 128 characters.
--
-- 'callerReference', 'publicKeyConfig_callerReference' - A string included in the request to help make sure that the request
-- can’t be replayed.
--
-- 'name', 'publicKeyConfig_name' - A name to help identify the public key.
--
-- 'encodedKey', 'publicKeyConfig_encodedKey' - The public key that you can use with
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html signed URLs and signed cookies>,
-- or with
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/field-level-encryption.html field-level encryption>.
newPublicKeyConfig ::
  -- | 'callerReference'
  Prelude.Text ->
  -- | 'name'
  Prelude.Text ->
  -- | 'encodedKey'
  Prelude.Text ->
  PublicKeyConfig
newPublicKeyConfig :: Text -> Text -> Text -> PublicKeyConfig
newPublicKeyConfig
  Text
pCallerReference_
  Text
pName_
  Text
pEncodedKey_ =
    PublicKeyConfig' :: Maybe Text -> Text -> Text -> Text -> PublicKeyConfig
PublicKeyConfig'
      { $sel:comment:PublicKeyConfig' :: Maybe Text
comment = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:callerReference:PublicKeyConfig' :: Text
callerReference = Text
pCallerReference_,
        $sel:name:PublicKeyConfig' :: Text
name = Text
pName_,
        $sel:encodedKey:PublicKeyConfig' :: Text
encodedKey = Text
pEncodedKey_
      }

-- | A comment to describe the public key. The comment cannot be longer than
-- 128 characters.
publicKeyConfig_comment :: Lens.Lens' PublicKeyConfig (Prelude.Maybe Prelude.Text)
publicKeyConfig_comment :: (Maybe Text -> f (Maybe Text))
-> PublicKeyConfig -> f PublicKeyConfig
publicKeyConfig_comment = (PublicKeyConfig -> Maybe Text)
-> (PublicKeyConfig -> Maybe Text -> PublicKeyConfig)
-> Lens PublicKeyConfig PublicKeyConfig (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PublicKeyConfig' {Maybe Text
comment :: Maybe Text
$sel:comment:PublicKeyConfig' :: PublicKeyConfig -> Maybe Text
comment} -> Maybe Text
comment) (\s :: PublicKeyConfig
s@PublicKeyConfig' {} Maybe Text
a -> PublicKeyConfig
s {$sel:comment:PublicKeyConfig' :: Maybe Text
comment = Maybe Text
a} :: PublicKeyConfig)

-- | A string included in the request to help make sure that the request
-- can’t be replayed.
publicKeyConfig_callerReference :: Lens.Lens' PublicKeyConfig Prelude.Text
publicKeyConfig_callerReference :: (Text -> f Text) -> PublicKeyConfig -> f PublicKeyConfig
publicKeyConfig_callerReference = (PublicKeyConfig -> Text)
-> (PublicKeyConfig -> Text -> PublicKeyConfig)
-> Lens PublicKeyConfig PublicKeyConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PublicKeyConfig' {Text
callerReference :: Text
$sel:callerReference:PublicKeyConfig' :: PublicKeyConfig -> Text
callerReference} -> Text
callerReference) (\s :: PublicKeyConfig
s@PublicKeyConfig' {} Text
a -> PublicKeyConfig
s {$sel:callerReference:PublicKeyConfig' :: Text
callerReference = Text
a} :: PublicKeyConfig)

-- | A name to help identify the public key.
publicKeyConfig_name :: Lens.Lens' PublicKeyConfig Prelude.Text
publicKeyConfig_name :: (Text -> f Text) -> PublicKeyConfig -> f PublicKeyConfig
publicKeyConfig_name = (PublicKeyConfig -> Text)
-> (PublicKeyConfig -> Text -> PublicKeyConfig)
-> Lens PublicKeyConfig PublicKeyConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PublicKeyConfig' {Text
name :: Text
$sel:name:PublicKeyConfig' :: PublicKeyConfig -> Text
name} -> Text
name) (\s :: PublicKeyConfig
s@PublicKeyConfig' {} Text
a -> PublicKeyConfig
s {$sel:name:PublicKeyConfig' :: Text
name = Text
a} :: PublicKeyConfig)

-- | The public key that you can use with
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html signed URLs and signed cookies>,
-- or with
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/field-level-encryption.html field-level encryption>.
publicKeyConfig_encodedKey :: Lens.Lens' PublicKeyConfig Prelude.Text
publicKeyConfig_encodedKey :: (Text -> f Text) -> PublicKeyConfig -> f PublicKeyConfig
publicKeyConfig_encodedKey = (PublicKeyConfig -> Text)
-> (PublicKeyConfig -> Text -> PublicKeyConfig)
-> Lens PublicKeyConfig PublicKeyConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PublicKeyConfig' {Text
encodedKey :: Text
$sel:encodedKey:PublicKeyConfig' :: PublicKeyConfig -> Text
encodedKey} -> Text
encodedKey) (\s :: PublicKeyConfig
s@PublicKeyConfig' {} Text
a -> PublicKeyConfig
s {$sel:encodedKey:PublicKeyConfig' :: Text
encodedKey = Text
a} :: PublicKeyConfig)

instance Core.FromXML PublicKeyConfig where
  parseXML :: [Node] -> Either String PublicKeyConfig
parseXML [Node]
x =
    Maybe Text -> Text -> Text -> Text -> PublicKeyConfig
PublicKeyConfig'
      (Maybe Text -> Text -> Text -> Text -> PublicKeyConfig)
-> Either String (Maybe Text)
-> Either String (Text -> Text -> Text -> PublicKeyConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Comment")
      Either String (Text -> Text -> Text -> PublicKeyConfig)
-> Either String Text
-> Either String (Text -> Text -> PublicKeyConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"CallerReference")
      Either String (Text -> Text -> PublicKeyConfig)
-> Either String Text -> Either String (Text -> PublicKeyConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Name")
      Either String (Text -> PublicKeyConfig)
-> Either String Text -> Either String PublicKeyConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"EncodedKey")

instance Prelude.Hashable PublicKeyConfig

instance Prelude.NFData PublicKeyConfig

instance Core.ToXML PublicKeyConfig where
  toXML :: PublicKeyConfig -> XML
toXML PublicKeyConfig' {Maybe Text
Text
encodedKey :: Text
name :: Text
callerReference :: Text
comment :: Maybe Text
$sel:encodedKey:PublicKeyConfig' :: PublicKeyConfig -> Text
$sel:name:PublicKeyConfig' :: PublicKeyConfig -> Text
$sel:callerReference:PublicKeyConfig' :: PublicKeyConfig -> Text
$sel:comment:PublicKeyConfig' :: PublicKeyConfig -> Maybe Text
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Comment" Name -> Maybe Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Text
comment,
        Name
"CallerReference" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
callerReference,
        Name
"Name" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
name,
        Name
"EncodedKey" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
encodedKey
      ]