{-# 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-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.TrustedKeyGroups where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(TrustedKeyGroups -> TrustedKeyGroups -> Bool)
-> (TrustedKeyGroups -> TrustedKeyGroups -> Bool)
-> Eq TrustedKeyGroups
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]
(Int -> ReadS TrustedKeyGroups)
-> ReadS [TrustedKeyGroups]
-> ReadPrec TrustedKeyGroups
-> ReadPrec [TrustedKeyGroups]
-> Read 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
(Int -> TrustedKeyGroups -> ShowS)
-> (TrustedKeyGroups -> String)
-> ([TrustedKeyGroups] -> ShowS)
-> Show TrustedKeyGroups
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. TrustedKeyGroups -> Rep TrustedKeyGroups x)
-> (forall x. Rep TrustedKeyGroups x -> TrustedKeyGroups)
-> Generic TrustedKeyGroups
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' :: Maybe [Text] -> Bool -> Int -> TrustedKeyGroups
TrustedKeyGroups'
    { $sel:items:TrustedKeyGroups' :: Maybe [Text]
items = Maybe [Text]
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 :: (Maybe [Text] -> f (Maybe [Text]))
-> TrustedKeyGroups -> f TrustedKeyGroups
trustedKeyGroups_items = (TrustedKeyGroups -> Maybe [Text])
-> (TrustedKeyGroups -> Maybe [Text] -> TrustedKeyGroups)
-> Lens
     TrustedKeyGroups TrustedKeyGroups (Maybe [Text]) (Maybe [Text])
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) ((Maybe [Text] -> f (Maybe [Text]))
 -> TrustedKeyGroups -> f TrustedKeyGroups)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> TrustedKeyGroups
-> f TrustedKeyGroups
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 AnIso [Text] [Text] [Text] [Text]
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 :: (Bool -> f Bool) -> TrustedKeyGroups -> f TrustedKeyGroups
trustedKeyGroups_enabled = (TrustedKeyGroups -> Bool)
-> (TrustedKeyGroups -> Bool -> TrustedKeyGroups)
-> Lens TrustedKeyGroups TrustedKeyGroups Bool Bool
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 :: (Int -> f Int) -> TrustedKeyGroups -> f TrustedKeyGroups
trustedKeyGroups_quantity = (TrustedKeyGroups -> Int)
-> (TrustedKeyGroups -> Int -> TrustedKeyGroups)
-> Lens TrustedKeyGroups TrustedKeyGroups Int Int
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 Core.FromXML TrustedKeyGroups where
  parseXML :: [Node] -> Either String TrustedKeyGroups
parseXML [Node]
x =
    Maybe [Text] -> Bool -> Int -> TrustedKeyGroups
TrustedKeyGroups'
      (Maybe [Text] -> Bool -> Int -> TrustedKeyGroups)
-> Either String (Maybe [Text])
-> Either String (Bool -> Int -> TrustedKeyGroups)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Items" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [Text]))
-> Either String (Maybe [Text])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [Text])
-> [Node] -> Either String (Maybe [Text])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [Text]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"KeyGroup")
                  )
      Either String (Bool -> Int -> TrustedKeyGroups)
-> Either String Bool -> Either String (Int -> TrustedKeyGroups)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Bool
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Enabled")
      Either String (Int -> TrustedKeyGroups)
-> Either String Int -> Either String TrustedKeyGroups
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Int
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Quantity")

instance Prelude.Hashable TrustedKeyGroups

instance Prelude.NFData TrustedKeyGroups

instance Core.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]
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Items"
          Name -> XML -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe XML -> XML
forall a. ToXML a => a -> XML
Core.toXML
            (Name -> [Text] -> XML
forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Core.toXMLList Name
"KeyGroup" ([Text] -> XML) -> Maybe [Text] -> Maybe XML
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
items),
        Name
"Enabled" Name -> Bool -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Bool
enabled,
        Name
"Quantity" Name -> Int -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Int
quantity
      ]