{-# 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.KeyGroupConfig
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CloudFront.Types.KeyGroupConfig where

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

-- | A key group configuration.
--
-- A key group contains a list of public keys that you can use with
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html CloudFront signed URLs and signed cookies>.
--
-- /See:/ 'newKeyGroupConfig' smart constructor.
data KeyGroupConfig = KeyGroupConfig'
  { -- | A comment to describe the key group. The comment cannot be longer than
    -- 128 characters.
    KeyGroupConfig -> Maybe Text
comment :: Prelude.Maybe Prelude.Text,
    -- | A name to identify the key group.
    KeyGroupConfig -> Text
name :: Prelude.Text,
    -- | A list of the identifiers of the public keys in the key group.
    KeyGroupConfig -> [Text]
items :: [Prelude.Text]
  }
  deriving (KeyGroupConfig -> KeyGroupConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: KeyGroupConfig -> KeyGroupConfig -> Bool
$c/= :: KeyGroupConfig -> KeyGroupConfig -> Bool
== :: KeyGroupConfig -> KeyGroupConfig -> Bool
$c== :: KeyGroupConfig -> KeyGroupConfig -> Bool
Prelude.Eq, ReadPrec [KeyGroupConfig]
ReadPrec KeyGroupConfig
Int -> ReadS KeyGroupConfig
ReadS [KeyGroupConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [KeyGroupConfig]
$creadListPrec :: ReadPrec [KeyGroupConfig]
readPrec :: ReadPrec KeyGroupConfig
$creadPrec :: ReadPrec KeyGroupConfig
readList :: ReadS [KeyGroupConfig]
$creadList :: ReadS [KeyGroupConfig]
readsPrec :: Int -> ReadS KeyGroupConfig
$creadsPrec :: Int -> ReadS KeyGroupConfig
Prelude.Read, Int -> KeyGroupConfig -> ShowS
[KeyGroupConfig] -> ShowS
KeyGroupConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [KeyGroupConfig] -> ShowS
$cshowList :: [KeyGroupConfig] -> ShowS
show :: KeyGroupConfig -> String
$cshow :: KeyGroupConfig -> String
showsPrec :: Int -> KeyGroupConfig -> ShowS
$cshowsPrec :: Int -> KeyGroupConfig -> ShowS
Prelude.Show, forall x. Rep KeyGroupConfig x -> KeyGroupConfig
forall x. KeyGroupConfig -> Rep KeyGroupConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep KeyGroupConfig x -> KeyGroupConfig
$cfrom :: forall x. KeyGroupConfig -> Rep KeyGroupConfig x
Prelude.Generic)

-- |
-- Create a value of 'KeyGroupConfig' 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', 'keyGroupConfig_comment' - A comment to describe the key group. The comment cannot be longer than
-- 128 characters.
--
-- 'name', 'keyGroupConfig_name' - A name to identify the key group.
--
-- 'items', 'keyGroupConfig_items' - A list of the identifiers of the public keys in the key group.
newKeyGroupConfig ::
  -- | 'name'
  Prelude.Text ->
  KeyGroupConfig
newKeyGroupConfig :: Text -> KeyGroupConfig
newKeyGroupConfig Text
pName_ =
  KeyGroupConfig'
    { $sel:comment:KeyGroupConfig' :: Maybe Text
comment = forall a. Maybe a
Prelude.Nothing,
      $sel:name:KeyGroupConfig' :: Text
name = Text
pName_,
      $sel:items:KeyGroupConfig' :: [Text]
items = forall a. Monoid a => a
Prelude.mempty
    }

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

-- | A name to identify the key group.
keyGroupConfig_name :: Lens.Lens' KeyGroupConfig Prelude.Text
keyGroupConfig_name :: Lens' KeyGroupConfig Text
keyGroupConfig_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KeyGroupConfig' {Text
name :: Text
$sel:name:KeyGroupConfig' :: KeyGroupConfig -> Text
name} -> Text
name) (\s :: KeyGroupConfig
s@KeyGroupConfig' {} Text
a -> KeyGroupConfig
s {$sel:name:KeyGroupConfig' :: Text
name = Text
a} :: KeyGroupConfig)

-- | A list of the identifiers of the public keys in the key group.
keyGroupConfig_items :: Lens.Lens' KeyGroupConfig [Prelude.Text]
keyGroupConfig_items :: Lens' KeyGroupConfig [Text]
keyGroupConfig_items = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KeyGroupConfig' {[Text]
items :: [Text]
$sel:items:KeyGroupConfig' :: KeyGroupConfig -> [Text]
items} -> [Text]
items) (\s :: KeyGroupConfig
s@KeyGroupConfig' {} [Text]
a -> KeyGroupConfig
s {$sel:items:KeyGroupConfig' :: [Text]
items = [Text]
a} :: KeyGroupConfig) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromXML KeyGroupConfig where
  parseXML :: [Node] -> Either String KeyGroupConfig
parseXML [Node]
x =
    Maybe Text -> Text -> [Text] -> KeyGroupConfig
KeyGroupConfig'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Comment")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"Name")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x
                      forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Items"
                      forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                      forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"PublicKey"
                  )

instance Prelude.Hashable KeyGroupConfig where
  hashWithSalt :: Int -> KeyGroupConfig -> Int
hashWithSalt Int
_salt KeyGroupConfig' {[Text]
Maybe Text
Text
items :: [Text]
name :: Text
comment :: Maybe Text
$sel:items:KeyGroupConfig' :: KeyGroupConfig -> [Text]
$sel:name:KeyGroupConfig' :: KeyGroupConfig -> Text
$sel:comment:KeyGroupConfig' :: KeyGroupConfig -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
comment
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
items

instance Prelude.NFData KeyGroupConfig where
  rnf :: KeyGroupConfig -> ()
rnf KeyGroupConfig' {[Text]
Maybe Text
Text
items :: [Text]
name :: Text
comment :: Maybe Text
$sel:items:KeyGroupConfig' :: KeyGroupConfig -> [Text]
$sel:name:KeyGroupConfig' :: KeyGroupConfig -> Text
$sel:comment:KeyGroupConfig' :: KeyGroupConfig -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
comment
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Text]
items

instance Data.ToXML KeyGroupConfig where
  toXML :: KeyGroupConfig -> XML
toXML KeyGroupConfig' {[Text]
Maybe Text
Text
items :: [Text]
name :: Text
comment :: Maybe Text
$sel:items:KeyGroupConfig' :: KeyGroupConfig -> [Text]
$sel:name:KeyGroupConfig' :: KeyGroupConfig -> Text
$sel:comment:KeyGroupConfig' :: KeyGroupConfig -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Comment" forall a. ToXML a => Name -> a -> XML
Data.@= Maybe Text
comment,
        Name
"Name" forall a. ToXML a => Name -> a -> XML
Data.@= Text
name,
        Name
"Items" forall a. ToXML a => Name -> a -> XML
Data.@= forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Data.toXMLList Name
"PublicKey" [Text]
items
      ]