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

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

-- | CloudFront Origin Shield.
--
-- Using Origin Shield can help reduce the load on your origin. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/origin-shield.html Using Origin Shield>
-- in the /Amazon CloudFront Developer Guide/.
--
-- /See:/ 'newOriginShield' smart constructor.
data OriginShield = OriginShield'
  { -- | The Region for Origin Shield.
    --
    -- Specify the Region that has the lowest latency to your origin. To
    -- specify a region, use the region code, not the region name. For example,
    -- specify the US East (Ohio) region as @us-east-2@.
    --
    -- When you enable CloudFront Origin Shield, you must specify the Region
    -- for Origin Shield. For the list of Regions that you can specify, and for
    -- help choosing the best Region for your origin, see
    -- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/origin-shield.html#choose-origin-shield-region Choosing the Region for Origin Shield>
    -- in the /Amazon CloudFront Developer Guide/.
    OriginShield -> Maybe Text
originShieldRegion :: Prelude.Maybe Prelude.Text,
    -- | A flag that specifies whether Origin Shield is enabled.
    --
    -- When it’s enabled, CloudFront routes all requests through Origin Shield,
    -- which can help protect your origin. When it’s disabled, CloudFront might
    -- send requests directly to your origin from multiple edge locations or
    -- regional edge caches.
    OriginShield -> Bool
enabled :: Prelude.Bool
  }
  deriving (OriginShield -> OriginShield -> Bool
(OriginShield -> OriginShield -> Bool)
-> (OriginShield -> OriginShield -> Bool) -> Eq OriginShield
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OriginShield -> OriginShield -> Bool
$c/= :: OriginShield -> OriginShield -> Bool
== :: OriginShield -> OriginShield -> Bool
$c== :: OriginShield -> OriginShield -> Bool
Prelude.Eq, ReadPrec [OriginShield]
ReadPrec OriginShield
Int -> ReadS OriginShield
ReadS [OriginShield]
(Int -> ReadS OriginShield)
-> ReadS [OriginShield]
-> ReadPrec OriginShield
-> ReadPrec [OriginShield]
-> Read OriginShield
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OriginShield]
$creadListPrec :: ReadPrec [OriginShield]
readPrec :: ReadPrec OriginShield
$creadPrec :: ReadPrec OriginShield
readList :: ReadS [OriginShield]
$creadList :: ReadS [OriginShield]
readsPrec :: Int -> ReadS OriginShield
$creadsPrec :: Int -> ReadS OriginShield
Prelude.Read, Int -> OriginShield -> ShowS
[OriginShield] -> ShowS
OriginShield -> String
(Int -> OriginShield -> ShowS)
-> (OriginShield -> String)
-> ([OriginShield] -> ShowS)
-> Show OriginShield
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OriginShield] -> ShowS
$cshowList :: [OriginShield] -> ShowS
show :: OriginShield -> String
$cshow :: OriginShield -> String
showsPrec :: Int -> OriginShield -> ShowS
$cshowsPrec :: Int -> OriginShield -> ShowS
Prelude.Show, (forall x. OriginShield -> Rep OriginShield x)
-> (forall x. Rep OriginShield x -> OriginShield)
-> Generic OriginShield
forall x. Rep OriginShield x -> OriginShield
forall x. OriginShield -> Rep OriginShield x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OriginShield x -> OriginShield
$cfrom :: forall x. OriginShield -> Rep OriginShield x
Prelude.Generic)

-- |
-- Create a value of 'OriginShield' 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:
--
-- 'originShieldRegion', 'originShield_originShieldRegion' - The Region for Origin Shield.
--
-- Specify the Region that has the lowest latency to your origin. To
-- specify a region, use the region code, not the region name. For example,
-- specify the US East (Ohio) region as @us-east-2@.
--
-- When you enable CloudFront Origin Shield, you must specify the Region
-- for Origin Shield. For the list of Regions that you can specify, and for
-- help choosing the best Region for your origin, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/origin-shield.html#choose-origin-shield-region Choosing the Region for Origin Shield>
-- in the /Amazon CloudFront Developer Guide/.
--
-- 'enabled', 'originShield_enabled' - A flag that specifies whether Origin Shield is enabled.
--
-- When it’s enabled, CloudFront routes all requests through Origin Shield,
-- which can help protect your origin. When it’s disabled, CloudFront might
-- send requests directly to your origin from multiple edge locations or
-- regional edge caches.
newOriginShield ::
  -- | 'enabled'
  Prelude.Bool ->
  OriginShield
newOriginShield :: Bool -> OriginShield
newOriginShield Bool
pEnabled_ =
  OriginShield' :: Maybe Text -> Bool -> OriginShield
OriginShield'
    { $sel:originShieldRegion:OriginShield' :: Maybe Text
originShieldRegion = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:enabled:OriginShield' :: Bool
enabled = Bool
pEnabled_
    }

-- | The Region for Origin Shield.
--
-- Specify the Region that has the lowest latency to your origin. To
-- specify a region, use the region code, not the region name. For example,
-- specify the US East (Ohio) region as @us-east-2@.
--
-- When you enable CloudFront Origin Shield, you must specify the Region
-- for Origin Shield. For the list of Regions that you can specify, and for
-- help choosing the best Region for your origin, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/origin-shield.html#choose-origin-shield-region Choosing the Region for Origin Shield>
-- in the /Amazon CloudFront Developer Guide/.
originShield_originShieldRegion :: Lens.Lens' OriginShield (Prelude.Maybe Prelude.Text)
originShield_originShieldRegion :: (Maybe Text -> f (Maybe Text)) -> OriginShield -> f OriginShield
originShield_originShieldRegion = (OriginShield -> Maybe Text)
-> (OriginShield -> Maybe Text -> OriginShield)
-> Lens OriginShield OriginShield (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginShield' {Maybe Text
originShieldRegion :: Maybe Text
$sel:originShieldRegion:OriginShield' :: OriginShield -> Maybe Text
originShieldRegion} -> Maybe Text
originShieldRegion) (\s :: OriginShield
s@OriginShield' {} Maybe Text
a -> OriginShield
s {$sel:originShieldRegion:OriginShield' :: Maybe Text
originShieldRegion = Maybe Text
a} :: OriginShield)

-- | A flag that specifies whether Origin Shield is enabled.
--
-- When it’s enabled, CloudFront routes all requests through Origin Shield,
-- which can help protect your origin. When it’s disabled, CloudFront might
-- send requests directly to your origin from multiple edge locations or
-- regional edge caches.
originShield_enabled :: Lens.Lens' OriginShield Prelude.Bool
originShield_enabled :: (Bool -> f Bool) -> OriginShield -> f OriginShield
originShield_enabled = (OriginShield -> Bool)
-> (OriginShield -> Bool -> OriginShield)
-> Lens OriginShield OriginShield Bool Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginShield' {Bool
enabled :: Bool
$sel:enabled:OriginShield' :: OriginShield -> Bool
enabled} -> Bool
enabled) (\s :: OriginShield
s@OriginShield' {} Bool
a -> OriginShield
s {$sel:enabled:OriginShield' :: Bool
enabled = Bool
a} :: OriginShield)

instance Core.FromXML OriginShield where
  parseXML :: [Node] -> Either String OriginShield
parseXML [Node]
x =
    Maybe Text -> Bool -> OriginShield
OriginShield'
      (Maybe Text -> Bool -> OriginShield)
-> Either String (Maybe Text)
-> Either String (Bool -> OriginShield)
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
"OriginShieldRegion")
      Either String (Bool -> OriginShield)
-> Either String Bool -> Either String OriginShield
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")

instance Prelude.Hashable OriginShield

instance Prelude.NFData OriginShield

instance Core.ToXML OriginShield where
  toXML :: OriginShield -> XML
toXML OriginShield' {Bool
Maybe Text
enabled :: Bool
originShieldRegion :: Maybe Text
$sel:enabled:OriginShield' :: OriginShield -> Bool
$sel:originShieldRegion:OriginShield' :: OriginShield -> Maybe Text
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"OriginShieldRegion" Name -> Maybe Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Text
originShieldRegion,
        Name
"Enabled" Name -> Bool -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Bool
enabled
      ]