{-# 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.RegexPatternSetReferenceStatement
-- 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.RegexPatternSetReferenceStatement 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.FieldToMatch
import Amazonka.WAFV2.Types.TextTransformation

-- | A rule statement used to search web request components for matches with
-- regular expressions. To use this, create a RegexPatternSet that
-- specifies the expressions that you want to detect, then use the ARN of
-- that set in this statement. A web request matches the pattern set rule
-- statement if the request component matches any of the patterns in the
-- set. To create a regex pattern set, see CreateRegexPatternSet.
--
-- Each regex pattern set rule statement references a regex pattern set.
-- You create and maintain the set independent of your rules. This allows
-- you to use the single set in multiple rules. When you update the
-- referenced set, WAF automatically updates all rules that reference it.
--
-- /See:/ 'newRegexPatternSetReferenceStatement' smart constructor.
data RegexPatternSetReferenceStatement = RegexPatternSetReferenceStatement'
  { -- | The Amazon Resource Name (ARN) of the RegexPatternSet that this
    -- statement references.
    RegexPatternSetReferenceStatement -> Text
arn :: Prelude.Text,
    -- | The part of the web request that you want WAF to inspect.
    RegexPatternSetReferenceStatement -> FieldToMatch
fieldToMatch :: FieldToMatch,
    -- | Text transformations eliminate some of the unusual formatting that
    -- attackers use in web requests in an effort to bypass detection. If you
    -- specify one or more transformations in a rule statement, WAF performs
    -- all transformations on the content of the request component identified
    -- by @FieldToMatch@, starting from the lowest priority setting, before
    -- inspecting the content for a match.
    RegexPatternSetReferenceStatement -> NonEmpty TextTransformation
textTransformations :: Prelude.NonEmpty TextTransformation
  }
  deriving (RegexPatternSetReferenceStatement
-> RegexPatternSetReferenceStatement -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegexPatternSetReferenceStatement
-> RegexPatternSetReferenceStatement -> Bool
$c/= :: RegexPatternSetReferenceStatement
-> RegexPatternSetReferenceStatement -> Bool
== :: RegexPatternSetReferenceStatement
-> RegexPatternSetReferenceStatement -> Bool
$c== :: RegexPatternSetReferenceStatement
-> RegexPatternSetReferenceStatement -> Bool
Prelude.Eq, ReadPrec [RegexPatternSetReferenceStatement]
ReadPrec RegexPatternSetReferenceStatement
Int -> ReadS RegexPatternSetReferenceStatement
ReadS [RegexPatternSetReferenceStatement]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegexPatternSetReferenceStatement]
$creadListPrec :: ReadPrec [RegexPatternSetReferenceStatement]
readPrec :: ReadPrec RegexPatternSetReferenceStatement
$creadPrec :: ReadPrec RegexPatternSetReferenceStatement
readList :: ReadS [RegexPatternSetReferenceStatement]
$creadList :: ReadS [RegexPatternSetReferenceStatement]
readsPrec :: Int -> ReadS RegexPatternSetReferenceStatement
$creadsPrec :: Int -> ReadS RegexPatternSetReferenceStatement
Prelude.Read, Int -> RegexPatternSetReferenceStatement -> ShowS
[RegexPatternSetReferenceStatement] -> ShowS
RegexPatternSetReferenceStatement -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegexPatternSetReferenceStatement] -> ShowS
$cshowList :: [RegexPatternSetReferenceStatement] -> ShowS
show :: RegexPatternSetReferenceStatement -> String
$cshow :: RegexPatternSetReferenceStatement -> String
showsPrec :: Int -> RegexPatternSetReferenceStatement -> ShowS
$cshowsPrec :: Int -> RegexPatternSetReferenceStatement -> ShowS
Prelude.Show, forall x.
Rep RegexPatternSetReferenceStatement x
-> RegexPatternSetReferenceStatement
forall x.
RegexPatternSetReferenceStatement
-> Rep RegexPatternSetReferenceStatement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep RegexPatternSetReferenceStatement x
-> RegexPatternSetReferenceStatement
$cfrom :: forall x.
RegexPatternSetReferenceStatement
-> Rep RegexPatternSetReferenceStatement x
Prelude.Generic)

-- |
-- Create a value of 'RegexPatternSetReferenceStatement' 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:
--
-- 'arn', 'regexPatternSetReferenceStatement_arn' - The Amazon Resource Name (ARN) of the RegexPatternSet that this
-- statement references.
--
-- 'fieldToMatch', 'regexPatternSetReferenceStatement_fieldToMatch' - The part of the web request that you want WAF to inspect.
--
-- 'textTransformations', 'regexPatternSetReferenceStatement_textTransformations' - Text transformations eliminate some of the unusual formatting that
-- attackers use in web requests in an effort to bypass detection. If you
-- specify one or more transformations in a rule statement, WAF performs
-- all transformations on the content of the request component identified
-- by @FieldToMatch@, starting from the lowest priority setting, before
-- inspecting the content for a match.
newRegexPatternSetReferenceStatement ::
  -- | 'arn'
  Prelude.Text ->
  -- | 'fieldToMatch'
  FieldToMatch ->
  -- | 'textTransformations'
  Prelude.NonEmpty TextTransformation ->
  RegexPatternSetReferenceStatement
newRegexPatternSetReferenceStatement :: Text
-> FieldToMatch
-> NonEmpty TextTransformation
-> RegexPatternSetReferenceStatement
newRegexPatternSetReferenceStatement
  Text
pARN_
  FieldToMatch
pFieldToMatch_
  NonEmpty TextTransformation
pTextTransformations_ =
    RegexPatternSetReferenceStatement'
      { $sel:arn:RegexPatternSetReferenceStatement' :: Text
arn = Text
pARN_,
        $sel:fieldToMatch:RegexPatternSetReferenceStatement' :: FieldToMatch
fieldToMatch = FieldToMatch
pFieldToMatch_,
        $sel:textTransformations:RegexPatternSetReferenceStatement' :: NonEmpty TextTransformation
textTransformations =
          forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced
            forall t b. AReview t b -> b -> t
Lens.# NonEmpty TextTransformation
pTextTransformations_
      }

-- | The Amazon Resource Name (ARN) of the RegexPatternSet that this
-- statement references.
regexPatternSetReferenceStatement_arn :: Lens.Lens' RegexPatternSetReferenceStatement Prelude.Text
regexPatternSetReferenceStatement_arn :: Lens' RegexPatternSetReferenceStatement Text
regexPatternSetReferenceStatement_arn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegexPatternSetReferenceStatement' {Text
arn :: Text
$sel:arn:RegexPatternSetReferenceStatement' :: RegexPatternSetReferenceStatement -> Text
arn} -> Text
arn) (\s :: RegexPatternSetReferenceStatement
s@RegexPatternSetReferenceStatement' {} Text
a -> RegexPatternSetReferenceStatement
s {$sel:arn:RegexPatternSetReferenceStatement' :: Text
arn = Text
a} :: RegexPatternSetReferenceStatement)

-- | The part of the web request that you want WAF to inspect.
regexPatternSetReferenceStatement_fieldToMatch :: Lens.Lens' RegexPatternSetReferenceStatement FieldToMatch
regexPatternSetReferenceStatement_fieldToMatch :: Lens' RegexPatternSetReferenceStatement FieldToMatch
regexPatternSetReferenceStatement_fieldToMatch = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegexPatternSetReferenceStatement' {FieldToMatch
fieldToMatch :: FieldToMatch
$sel:fieldToMatch:RegexPatternSetReferenceStatement' :: RegexPatternSetReferenceStatement -> FieldToMatch
fieldToMatch} -> FieldToMatch
fieldToMatch) (\s :: RegexPatternSetReferenceStatement
s@RegexPatternSetReferenceStatement' {} FieldToMatch
a -> RegexPatternSetReferenceStatement
s {$sel:fieldToMatch:RegexPatternSetReferenceStatement' :: FieldToMatch
fieldToMatch = FieldToMatch
a} :: RegexPatternSetReferenceStatement)

-- | Text transformations eliminate some of the unusual formatting that
-- attackers use in web requests in an effort to bypass detection. If you
-- specify one or more transformations in a rule statement, WAF performs
-- all transformations on the content of the request component identified
-- by @FieldToMatch@, starting from the lowest priority setting, before
-- inspecting the content for a match.
regexPatternSetReferenceStatement_textTransformations :: Lens.Lens' RegexPatternSetReferenceStatement (Prelude.NonEmpty TextTransformation)
regexPatternSetReferenceStatement_textTransformations :: Lens'
  RegexPatternSetReferenceStatement (NonEmpty TextTransformation)
regexPatternSetReferenceStatement_textTransformations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegexPatternSetReferenceStatement' {NonEmpty TextTransformation
textTransformations :: NonEmpty TextTransformation
$sel:textTransformations:RegexPatternSetReferenceStatement' :: RegexPatternSetReferenceStatement -> NonEmpty TextTransformation
textTransformations} -> NonEmpty TextTransformation
textTransformations) (\s :: RegexPatternSetReferenceStatement
s@RegexPatternSetReferenceStatement' {} NonEmpty TextTransformation
a -> RegexPatternSetReferenceStatement
s {$sel:textTransformations:RegexPatternSetReferenceStatement' :: NonEmpty TextTransformation
textTransformations = NonEmpty TextTransformation
a} :: RegexPatternSetReferenceStatement) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance
  Data.FromJSON
    RegexPatternSetReferenceStatement
  where
  parseJSON :: Value -> Parser RegexPatternSetReferenceStatement
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RegexPatternSetReferenceStatement"
      ( \Object
x ->
          Text
-> FieldToMatch
-> NonEmpty TextTransformation
-> RegexPatternSetReferenceStatement
RegexPatternSetReferenceStatement'
            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
"ARN")
            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
"FieldToMatch")
            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
"TextTransformations")
      )

instance
  Prelude.Hashable
    RegexPatternSetReferenceStatement
  where
  hashWithSalt :: Int -> RegexPatternSetReferenceStatement -> Int
hashWithSalt
    Int
_salt
    RegexPatternSetReferenceStatement' {NonEmpty TextTransformation
Text
FieldToMatch
textTransformations :: NonEmpty TextTransformation
fieldToMatch :: FieldToMatch
arn :: Text
$sel:textTransformations:RegexPatternSetReferenceStatement' :: RegexPatternSetReferenceStatement -> NonEmpty TextTransformation
$sel:fieldToMatch:RegexPatternSetReferenceStatement' :: RegexPatternSetReferenceStatement -> FieldToMatch
$sel:arn:RegexPatternSetReferenceStatement' :: RegexPatternSetReferenceStatement -> Text
..} =
      Int
_salt
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
arn
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` FieldToMatch
fieldToMatch
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty TextTransformation
textTransformations

instance
  Prelude.NFData
    RegexPatternSetReferenceStatement
  where
  rnf :: RegexPatternSetReferenceStatement -> ()
rnf RegexPatternSetReferenceStatement' {NonEmpty TextTransformation
Text
FieldToMatch
textTransformations :: NonEmpty TextTransformation
fieldToMatch :: FieldToMatch
arn :: Text
$sel:textTransformations:RegexPatternSetReferenceStatement' :: RegexPatternSetReferenceStatement -> NonEmpty TextTransformation
$sel:fieldToMatch:RegexPatternSetReferenceStatement' :: RegexPatternSetReferenceStatement -> FieldToMatch
$sel:arn:RegexPatternSetReferenceStatement' :: RegexPatternSetReferenceStatement -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
arn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf FieldToMatch
fieldToMatch
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty TextTransformation
textTransformations

instance
  Data.ToJSON
    RegexPatternSetReferenceStatement
  where
  toJSON :: RegexPatternSetReferenceStatement -> Value
toJSON RegexPatternSetReferenceStatement' {NonEmpty TextTransformation
Text
FieldToMatch
textTransformations :: NonEmpty TextTransformation
fieldToMatch :: FieldToMatch
arn :: Text
$sel:textTransformations:RegexPatternSetReferenceStatement' :: RegexPatternSetReferenceStatement -> NonEmpty TextTransformation
$sel:fieldToMatch:RegexPatternSetReferenceStatement' :: RegexPatternSetReferenceStatement -> FieldToMatch
$sel:arn:RegexPatternSetReferenceStatement' :: RegexPatternSetReferenceStatement -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"ARN" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
arn),
            forall a. a -> Maybe a
Prelude.Just (Key
"FieldToMatch" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= FieldToMatch
fieldToMatch),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"TextTransformations" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty TextTransformation
textTransformations)
          ]
      )