{-# 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.TrustedKeyGroups
-- 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.TrustedKeyGroups 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 list of key groups whose public keys CloudFront can use to verify the
-- signatures of signed URLs and signed cookies.
--
-- /See:/ 'newTrustedKeyGroups' smart constructor.
data TrustedKeyGroups = TrustedKeyGroups'
  { -- | A list of key groups identifiers.
    TrustedKeyGroups -> Maybe [Text]
items :: Prelude.Maybe [Prelude.Text],
    -- | This field is @true@ if any of the key groups in the list have public
    -- keys that CloudFront can use to verify the signatures of signed URLs and
    -- signed cookies. If not, this field is @false@.
    TrustedKeyGroups -> Bool
enabled :: Prelude.Bool,
    -- | The number of key groups in the list.
    TrustedKeyGroups -> Int
quantity :: Prelude.Int
  }
  deriving (TrustedKeyGroups -> TrustedKeyGroups -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TrustedKeyGroups -> TrustedKeyGroups -> Bool
$c/= :: TrustedKeyGroups -> TrustedKeyGroups -> Bool
== :: TrustedKeyGroups -> TrustedKeyGroups -> Bool
$c== :: TrustedKeyGroups -> TrustedKeyGroups -> Bool
Prelude.Eq, ReadPrec [TrustedKeyGroups]
ReadPrec TrustedKeyGroups
Int -> ReadS TrustedKeyGroups
ReadS [TrustedKeyGroups]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TrustedKeyGroups]
$creadListPrec :: ReadPrec [TrustedKeyGroups]
readPrec :: ReadPrec TrustedKeyGroups
$creadPrec :: ReadPrec TrustedKeyGroups
readList :: ReadS [TrustedKeyGroups]
$creadList :: ReadS [TrustedKeyGroups]
readsPrec :: Int -> ReadS TrustedKeyGroups
$creadsPrec :: Int -> ReadS TrustedKeyGroups
Prelude.Read, Int -> TrustedKeyGroups -> ShowS
[TrustedKeyGroups] -> ShowS
TrustedKeyGroups -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TrustedKeyGroups] -> ShowS
$cshowList :: [TrustedKeyGroups] -> ShowS
show :: TrustedKeyGroups -> String
$cshow :: TrustedKeyGroups -> String
showsPrec :: Int -> TrustedKeyGroups -> ShowS
$cshowsPrec :: Int -> TrustedKeyGroups -> ShowS
Prelude.Show, forall x. Rep TrustedKeyGroups x -> TrustedKeyGroups
forall x. TrustedKeyGroups -> Rep TrustedKeyGroups x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TrustedKeyGroups x -> TrustedKeyGroups
$cfrom :: forall x. TrustedKeyGroups -> Rep TrustedKeyGroups x
Prelude.Generic)

-- |
-- Create a value of 'TrustedKeyGroups' 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:
--
-- 'items', 'trustedKeyGroups_items' - A list of key groups identifiers.
--
-- 'enabled', 'trustedKeyGroups_enabled' - This field is @true@ if any of the key groups in the list have public
-- keys that CloudFront can use to verify the signatures of signed URLs and
-- signed cookies. If not, this field is @false@.
--
-- 'quantity', 'trustedKeyGroups_quantity' - The number of key groups in the list.
newTrustedKeyGroups ::
  -- | 'enabled'
  Prelude.Bool ->
  -- | 'quantity'
  Prelude.Int ->
  TrustedKeyGroups
newTrustedKeyGroups :: Bool -> Int -> TrustedKeyGroups
newTrustedKeyGroups Bool
pEnabled_ Int
pQuantity_ =
  TrustedKeyGroups'
    { $sel:items:TrustedKeyGroups' :: Maybe [Text]
items = forall a. Maybe a
Prelude.Nothing,
      $sel:enabled:TrustedKeyGroups' :: Bool
enabled = Bool
pEnabled_,
      $sel:quantity:TrustedKeyGroups' :: Int
quantity = Int
pQuantity_
    }

-- | A list of key groups identifiers.
trustedKeyGroups_items :: Lens.Lens' TrustedKeyGroups (Prelude.Maybe [Prelude.Text])
trustedKeyGroups_items :: Lens' TrustedKeyGroups (Maybe [Text])
trustedKeyGroups_items = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TrustedKeyGroups' {Maybe [Text]
items :: Maybe [Text]
$sel:items:TrustedKeyGroups' :: TrustedKeyGroups -> Maybe [Text]
items} -> Maybe [Text]
items) (\s :: TrustedKeyGroups
s@TrustedKeyGroups' {} Maybe [Text]
a -> TrustedKeyGroups
s {$sel:items:TrustedKeyGroups' :: Maybe [Text]
items = Maybe [Text]
a} :: TrustedKeyGroups) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | This field is @true@ if any of the key groups in the list have public
-- keys that CloudFront can use to verify the signatures of signed URLs and
-- signed cookies. If not, this field is @false@.
trustedKeyGroups_enabled :: Lens.Lens' TrustedKeyGroups Prelude.Bool
trustedKeyGroups_enabled :: Lens' TrustedKeyGroups Bool
trustedKeyGroups_enabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TrustedKeyGroups' {Bool
enabled :: Bool
$sel:enabled:TrustedKeyGroups' :: TrustedKeyGroups -> Bool
enabled} -> Bool
enabled) (\s :: TrustedKeyGroups
s@TrustedKeyGroups' {} Bool
a -> TrustedKeyGroups
s {$sel:enabled:TrustedKeyGroups' :: Bool
enabled = Bool
a} :: TrustedKeyGroups)

-- | The number of key groups in the list.
trustedKeyGroups_quantity :: Lens.Lens' TrustedKeyGroups Prelude.Int
trustedKeyGroups_quantity :: Lens' TrustedKeyGroups Int
trustedKeyGroups_quantity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TrustedKeyGroups' {Int
quantity :: Int
$sel:quantity:TrustedKeyGroups' :: TrustedKeyGroups -> Int
quantity} -> Int
quantity) (\s :: TrustedKeyGroups
s@TrustedKeyGroups' {} Int
a -> TrustedKeyGroups
s {$sel:quantity:TrustedKeyGroups' :: Int
quantity = Int
a} :: TrustedKeyGroups)

instance Data.FromXML TrustedKeyGroups where
  parseXML :: [Node] -> Either String TrustedKeyGroups
parseXML [Node]
x =
    Maybe [Text] -> Bool -> Int -> TrustedKeyGroups
TrustedKeyGroups'
      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
"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 (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"KeyGroup")
                  )
      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
"Enabled")
      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
"Quantity")

instance Prelude.Hashable TrustedKeyGroups where
  hashWithSalt :: Int -> TrustedKeyGroups -> Int
hashWithSalt Int
_salt TrustedKeyGroups' {Bool
Int
Maybe [Text]
quantity :: Int
enabled :: Bool
items :: Maybe [Text]
$sel:quantity:TrustedKeyGroups' :: TrustedKeyGroups -> Int
$sel:enabled:TrustedKeyGroups' :: TrustedKeyGroups -> Bool
$sel:items:TrustedKeyGroups' :: TrustedKeyGroups -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
items
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Bool
enabled
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
quantity

instance Prelude.NFData TrustedKeyGroups where
  rnf :: TrustedKeyGroups -> ()
rnf TrustedKeyGroups' {Bool
Int
Maybe [Text]
quantity :: Int
enabled :: Bool
items :: Maybe [Text]
$sel:quantity:TrustedKeyGroups' :: TrustedKeyGroups -> Int
$sel:enabled:TrustedKeyGroups' :: TrustedKeyGroups -> Bool
$sel:items:TrustedKeyGroups' :: TrustedKeyGroups -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
items
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Bool
enabled
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
quantity

instance Data.ToXML TrustedKeyGroups where
  toXML :: TrustedKeyGroups -> XML
toXML TrustedKeyGroups' {Bool
Int
Maybe [Text]
quantity :: Int
enabled :: Bool
items :: Maybe [Text]
$sel:quantity:TrustedKeyGroups' :: TrustedKeyGroups -> Int
$sel:enabled:TrustedKeyGroups' :: TrustedKeyGroups -> Bool
$sel:items:TrustedKeyGroups' :: TrustedKeyGroups -> Maybe [Text]
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Items"
          forall a. ToXML a => Name -> a -> XML
Data.@= forall a. ToXML a => a -> XML
Data.toXML
            (forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Data.toXMLList Name
"KeyGroup" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
items),
        Name
"Enabled" forall a. ToXML a => Name -> a -> XML
Data.@= Bool
enabled,
        Name
"Quantity" forall a. ToXML a => Name -> a -> XML
Data.@= Int
quantity
      ]