{-# 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.WAFV2.Types.ForwardedIPConfig
-- 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.WAFV2.Types.ForwardedIPConfig 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
import Amazonka.WAFV2.Types.FallbackBehavior

-- | The configuration for inspecting IP addresses in an HTTP header that you
-- specify, instead of using the IP address that\'s reported by the web
-- request origin. Commonly, this is the X-Forwarded-For (XFF) header, but
-- you can specify any header name.
--
-- If the specified header isn\'t present in the request, WAF doesn\'t
-- apply the rule to the web request at all.
--
-- This configuration is used for GeoMatchStatement and RateBasedStatement.
-- For IPSetReferenceStatement, use IPSetForwardedIPConfig instead.
--
-- WAF only evaluates the first IP address found in the specified HTTP
-- header.
--
-- /See:/ 'newForwardedIPConfig' smart constructor.
data ForwardedIPConfig = ForwardedIPConfig'
  { -- | The name of the HTTP header to use for the IP address. For example, to
    -- use the X-Forwarded-For (XFF) header, set this to @X-Forwarded-For@.
    --
    -- If the specified header isn\'t present in the request, WAF doesn\'t
    -- apply the rule to the web request at all.
    ForwardedIPConfig -> Text
headerName :: Prelude.Text,
    -- | The match status to assign to the web request if the request doesn\'t
    -- have a valid IP address in the specified position.
    --
    -- If the specified header isn\'t present in the request, WAF doesn\'t
    -- apply the rule to the web request at all.
    --
    -- You can specify the following fallback behaviors:
    --
    -- -   @MATCH@ - Treat the web request as matching the rule statement. WAF
    --     applies the rule action to the request.
    --
    -- -   @NO_MATCH@ - Treat the web request as not matching the rule
    --     statement.
    ForwardedIPConfig -> FallbackBehavior
fallbackBehavior :: FallbackBehavior
  }
  deriving (ForwardedIPConfig -> ForwardedIPConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ForwardedIPConfig -> ForwardedIPConfig -> Bool
$c/= :: ForwardedIPConfig -> ForwardedIPConfig -> Bool
== :: ForwardedIPConfig -> ForwardedIPConfig -> Bool
$c== :: ForwardedIPConfig -> ForwardedIPConfig -> Bool
Prelude.Eq, ReadPrec [ForwardedIPConfig]
ReadPrec ForwardedIPConfig
Int -> ReadS ForwardedIPConfig
ReadS [ForwardedIPConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ForwardedIPConfig]
$creadListPrec :: ReadPrec [ForwardedIPConfig]
readPrec :: ReadPrec ForwardedIPConfig
$creadPrec :: ReadPrec ForwardedIPConfig
readList :: ReadS [ForwardedIPConfig]
$creadList :: ReadS [ForwardedIPConfig]
readsPrec :: Int -> ReadS ForwardedIPConfig
$creadsPrec :: Int -> ReadS ForwardedIPConfig
Prelude.Read, Int -> ForwardedIPConfig -> ShowS
[ForwardedIPConfig] -> ShowS
ForwardedIPConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ForwardedIPConfig] -> ShowS
$cshowList :: [ForwardedIPConfig] -> ShowS
show :: ForwardedIPConfig -> String
$cshow :: ForwardedIPConfig -> String
showsPrec :: Int -> ForwardedIPConfig -> ShowS
$cshowsPrec :: Int -> ForwardedIPConfig -> ShowS
Prelude.Show, forall x. Rep ForwardedIPConfig x -> ForwardedIPConfig
forall x. ForwardedIPConfig -> Rep ForwardedIPConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ForwardedIPConfig x -> ForwardedIPConfig
$cfrom :: forall x. ForwardedIPConfig -> Rep ForwardedIPConfig x
Prelude.Generic)

-- |
-- Create a value of 'ForwardedIPConfig' 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:
--
-- 'headerName', 'forwardedIPConfig_headerName' - The name of the HTTP header to use for the IP address. For example, to
-- use the X-Forwarded-For (XFF) header, set this to @X-Forwarded-For@.
--
-- If the specified header isn\'t present in the request, WAF doesn\'t
-- apply the rule to the web request at all.
--
-- 'fallbackBehavior', 'forwardedIPConfig_fallbackBehavior' - The match status to assign to the web request if the request doesn\'t
-- have a valid IP address in the specified position.
--
-- If the specified header isn\'t present in the request, WAF doesn\'t
-- apply the rule to the web request at all.
--
-- You can specify the following fallback behaviors:
--
-- -   @MATCH@ - Treat the web request as matching the rule statement. WAF
--     applies the rule action to the request.
--
-- -   @NO_MATCH@ - Treat the web request as not matching the rule
--     statement.
newForwardedIPConfig ::
  -- | 'headerName'
  Prelude.Text ->
  -- | 'fallbackBehavior'
  FallbackBehavior ->
  ForwardedIPConfig
newForwardedIPConfig :: Text -> FallbackBehavior -> ForwardedIPConfig
newForwardedIPConfig Text
pHeaderName_ FallbackBehavior
pFallbackBehavior_ =
  ForwardedIPConfig'
    { $sel:headerName:ForwardedIPConfig' :: Text
headerName = Text
pHeaderName_,
      $sel:fallbackBehavior:ForwardedIPConfig' :: FallbackBehavior
fallbackBehavior = FallbackBehavior
pFallbackBehavior_
    }

-- | The name of the HTTP header to use for the IP address. For example, to
-- use the X-Forwarded-For (XFF) header, set this to @X-Forwarded-For@.
--
-- If the specified header isn\'t present in the request, WAF doesn\'t
-- apply the rule to the web request at all.
forwardedIPConfig_headerName :: Lens.Lens' ForwardedIPConfig Prelude.Text
forwardedIPConfig_headerName :: Lens' ForwardedIPConfig Text
forwardedIPConfig_headerName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ForwardedIPConfig' {Text
headerName :: Text
$sel:headerName:ForwardedIPConfig' :: ForwardedIPConfig -> Text
headerName} -> Text
headerName) (\s :: ForwardedIPConfig
s@ForwardedIPConfig' {} Text
a -> ForwardedIPConfig
s {$sel:headerName:ForwardedIPConfig' :: Text
headerName = Text
a} :: ForwardedIPConfig)

-- | The match status to assign to the web request if the request doesn\'t
-- have a valid IP address in the specified position.
--
-- If the specified header isn\'t present in the request, WAF doesn\'t
-- apply the rule to the web request at all.
--
-- You can specify the following fallback behaviors:
--
-- -   @MATCH@ - Treat the web request as matching the rule statement. WAF
--     applies the rule action to the request.
--
-- -   @NO_MATCH@ - Treat the web request as not matching the rule
--     statement.
forwardedIPConfig_fallbackBehavior :: Lens.Lens' ForwardedIPConfig FallbackBehavior
forwardedIPConfig_fallbackBehavior :: Lens' ForwardedIPConfig FallbackBehavior
forwardedIPConfig_fallbackBehavior = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ForwardedIPConfig' {FallbackBehavior
fallbackBehavior :: FallbackBehavior
$sel:fallbackBehavior:ForwardedIPConfig' :: ForwardedIPConfig -> FallbackBehavior
fallbackBehavior} -> FallbackBehavior
fallbackBehavior) (\s :: ForwardedIPConfig
s@ForwardedIPConfig' {} FallbackBehavior
a -> ForwardedIPConfig
s {$sel:fallbackBehavior:ForwardedIPConfig' :: FallbackBehavior
fallbackBehavior = FallbackBehavior
a} :: ForwardedIPConfig)

instance Data.FromJSON ForwardedIPConfig where
  parseJSON :: Value -> Parser ForwardedIPConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ForwardedIPConfig"
      ( \Object
x ->
          Text -> FallbackBehavior -> ForwardedIPConfig
ForwardedIPConfig'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"HeaderName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"FallbackBehavior")
      )

instance Prelude.Hashable ForwardedIPConfig where
  hashWithSalt :: Int -> ForwardedIPConfig -> Int
hashWithSalt Int
_salt ForwardedIPConfig' {Text
FallbackBehavior
fallbackBehavior :: FallbackBehavior
headerName :: Text
$sel:fallbackBehavior:ForwardedIPConfig' :: ForwardedIPConfig -> FallbackBehavior
$sel:headerName:ForwardedIPConfig' :: ForwardedIPConfig -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
headerName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` FallbackBehavior
fallbackBehavior

instance Prelude.NFData ForwardedIPConfig where
  rnf :: ForwardedIPConfig -> ()
rnf ForwardedIPConfig' {Text
FallbackBehavior
fallbackBehavior :: FallbackBehavior
headerName :: Text
$sel:fallbackBehavior:ForwardedIPConfig' :: ForwardedIPConfig -> FallbackBehavior
$sel:headerName:ForwardedIPConfig' :: ForwardedIPConfig -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
headerName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf FallbackBehavior
fallbackBehavior

instance Data.ToJSON ForwardedIPConfig where
  toJSON :: ForwardedIPConfig -> Value
toJSON ForwardedIPConfig' {Text
FallbackBehavior
fallbackBehavior :: FallbackBehavior
headerName :: Text
$sel:fallbackBehavior:ForwardedIPConfig' :: ForwardedIPConfig -> FallbackBehavior
$sel:headerName:ForwardedIPConfig' :: ForwardedIPConfig -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"HeaderName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
headerName),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"FallbackBehavior" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= FallbackBehavior
fallbackBehavior)
          ]
      )