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

-- | 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 Amazon Web Services Region for Origin Shield.
    --
    -- Specify the Amazon Web Services 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 Amazon
    -- Web Services Region for Origin Shield. For the list of Amazon Web
    -- Services 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 Amazon Web Services 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
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]
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
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. 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 Amazon Web Services Region for Origin Shield.
--
-- Specify the Amazon Web Services 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 Amazon
-- Web Services Region for Origin Shield. For the list of Amazon Web
-- Services 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 Amazon Web Services 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'
    { $sel:originShieldRegion:OriginShield' :: Maybe Text
originShieldRegion = forall a. Maybe a
Prelude.Nothing,
      $sel:enabled:OriginShield' :: Bool
enabled = Bool
pEnabled_
    }

-- | The Amazon Web Services Region for Origin Shield.
--
-- Specify the Amazon Web Services 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 Amazon
-- Web Services Region for Origin Shield. For the list of Amazon Web
-- Services 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 Amazon Web Services Region for Origin Shield>
-- in the /Amazon CloudFront Developer Guide/.
originShield_originShieldRegion :: Lens.Lens' OriginShield (Prelude.Maybe Prelude.Text)
originShield_originShieldRegion :: Lens' OriginShield (Maybe Text)
originShield_originShieldRegion = 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 :: Lens' OriginShield Bool
originShield_enabled = 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 Data.FromXML OriginShield where
  parseXML :: [Node] -> Either String OriginShield
parseXML [Node]
x =
    Maybe Text -> Bool -> OriginShield
OriginShield'
      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
"OriginShieldRegion")
      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")

instance Prelude.Hashable OriginShield where
  hashWithSalt :: Int -> OriginShield -> Int
hashWithSalt Int
_salt OriginShield' {Bool
Maybe Text
enabled :: Bool
originShieldRegion :: Maybe Text
$sel:enabled:OriginShield' :: OriginShield -> Bool
$sel:originShieldRegion:OriginShield' :: OriginShield -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
originShieldRegion
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Bool
enabled

instance Prelude.NFData OriginShield where
  rnf :: OriginShield -> ()
rnf OriginShield' {Bool
Maybe Text
enabled :: Bool
originShieldRegion :: Maybe Text
$sel:enabled:OriginShield' :: OriginShield -> Bool
$sel:originShieldRegion:OriginShield' :: OriginShield -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
originShieldRegion
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Bool
enabled

instance Data.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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"OriginShieldRegion" forall a. ToXML a => Name -> a -> XML
Data.@= Maybe Text
originShieldRegion,
        Name
"Enabled" forall a. ToXML a => Name -> a -> XML
Data.@= Bool
enabled
      ]