{-# 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.RegexMatchStatement
-- 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.RegexMatchStatement 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 a match
-- against a single regular expression.
--
-- /See:/ 'newRegexMatchStatement' smart constructor.
data RegexMatchStatement = RegexMatchStatement'
  { -- | The string representing the regular expression.
    RegexMatchStatement -> Text
regexString :: Prelude.Text,
    -- | The part of the web request that you want WAF to inspect.
    RegexMatchStatement -> 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.
    RegexMatchStatement -> NonEmpty TextTransformation
textTransformations :: Prelude.NonEmpty TextTransformation
  }
  deriving (RegexMatchStatement -> RegexMatchStatement -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegexMatchStatement -> RegexMatchStatement -> Bool
$c/= :: RegexMatchStatement -> RegexMatchStatement -> Bool
== :: RegexMatchStatement -> RegexMatchStatement -> Bool
$c== :: RegexMatchStatement -> RegexMatchStatement -> Bool
Prelude.Eq, ReadPrec [RegexMatchStatement]
ReadPrec RegexMatchStatement
Int -> ReadS RegexMatchStatement
ReadS [RegexMatchStatement]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegexMatchStatement]
$creadListPrec :: ReadPrec [RegexMatchStatement]
readPrec :: ReadPrec RegexMatchStatement
$creadPrec :: ReadPrec RegexMatchStatement
readList :: ReadS [RegexMatchStatement]
$creadList :: ReadS [RegexMatchStatement]
readsPrec :: Int -> ReadS RegexMatchStatement
$creadsPrec :: Int -> ReadS RegexMatchStatement
Prelude.Read, Int -> RegexMatchStatement -> ShowS
[RegexMatchStatement] -> ShowS
RegexMatchStatement -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegexMatchStatement] -> ShowS
$cshowList :: [RegexMatchStatement] -> ShowS
show :: RegexMatchStatement -> String
$cshow :: RegexMatchStatement -> String
showsPrec :: Int -> RegexMatchStatement -> ShowS
$cshowsPrec :: Int -> RegexMatchStatement -> ShowS
Prelude.Show, forall x. Rep RegexMatchStatement x -> RegexMatchStatement
forall x. RegexMatchStatement -> Rep RegexMatchStatement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegexMatchStatement x -> RegexMatchStatement
$cfrom :: forall x. RegexMatchStatement -> Rep RegexMatchStatement x
Prelude.Generic)

-- |
-- Create a value of 'RegexMatchStatement' 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:
--
-- 'regexString', 'regexMatchStatement_regexString' - The string representing the regular expression.
--
-- 'fieldToMatch', 'regexMatchStatement_fieldToMatch' - The part of the web request that you want WAF to inspect.
--
-- 'textTransformations', 'regexMatchStatement_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.
newRegexMatchStatement ::
  -- | 'regexString'
  Prelude.Text ->
  -- | 'fieldToMatch'
  FieldToMatch ->
  -- | 'textTransformations'
  Prelude.NonEmpty TextTransformation ->
  RegexMatchStatement
newRegexMatchStatement :: Text
-> FieldToMatch
-> NonEmpty TextTransformation
-> RegexMatchStatement
newRegexMatchStatement
  Text
pRegexString_
  FieldToMatch
pFieldToMatch_
  NonEmpty TextTransformation
pTextTransformations_ =
    RegexMatchStatement'
      { $sel:regexString:RegexMatchStatement' :: Text
regexString = Text
pRegexString_,
        $sel:fieldToMatch:RegexMatchStatement' :: FieldToMatch
fieldToMatch = FieldToMatch
pFieldToMatch_,
        $sel:textTransformations:RegexMatchStatement' :: 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 string representing the regular expression.
regexMatchStatement_regexString :: Lens.Lens' RegexMatchStatement Prelude.Text
regexMatchStatement_regexString :: Lens' RegexMatchStatement Text
regexMatchStatement_regexString = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegexMatchStatement' {Text
regexString :: Text
$sel:regexString:RegexMatchStatement' :: RegexMatchStatement -> Text
regexString} -> Text
regexString) (\s :: RegexMatchStatement
s@RegexMatchStatement' {} Text
a -> RegexMatchStatement
s {$sel:regexString:RegexMatchStatement' :: Text
regexString = Text
a} :: RegexMatchStatement)

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

-- | 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.
regexMatchStatement_textTransformations :: Lens.Lens' RegexMatchStatement (Prelude.NonEmpty TextTransformation)
regexMatchStatement_textTransformations :: Lens' RegexMatchStatement (NonEmpty TextTransformation)
regexMatchStatement_textTransformations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegexMatchStatement' {NonEmpty TextTransformation
textTransformations :: NonEmpty TextTransformation
$sel:textTransformations:RegexMatchStatement' :: RegexMatchStatement -> NonEmpty TextTransformation
textTransformations} -> NonEmpty TextTransformation
textTransformations) (\s :: RegexMatchStatement
s@RegexMatchStatement' {} NonEmpty TextTransformation
a -> RegexMatchStatement
s {$sel:textTransformations:RegexMatchStatement' :: NonEmpty TextTransformation
textTransformations = NonEmpty TextTransformation
a} :: RegexMatchStatement) 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 RegexMatchStatement where
  parseJSON :: Value -> Parser RegexMatchStatement
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RegexMatchStatement"
      ( \Object
x ->
          Text
-> FieldToMatch
-> NonEmpty TextTransformation
-> RegexMatchStatement
RegexMatchStatement'
            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
"RegexString")
            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 RegexMatchStatement where
  hashWithSalt :: Int -> RegexMatchStatement -> Int
hashWithSalt Int
_salt RegexMatchStatement' {NonEmpty TextTransformation
Text
FieldToMatch
textTransformations :: NonEmpty TextTransformation
fieldToMatch :: FieldToMatch
regexString :: Text
$sel:textTransformations:RegexMatchStatement' :: RegexMatchStatement -> NonEmpty TextTransformation
$sel:fieldToMatch:RegexMatchStatement' :: RegexMatchStatement -> FieldToMatch
$sel:regexString:RegexMatchStatement' :: RegexMatchStatement -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
regexString
      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 RegexMatchStatement where
  rnf :: RegexMatchStatement -> ()
rnf RegexMatchStatement' {NonEmpty TextTransformation
Text
FieldToMatch
textTransformations :: NonEmpty TextTransformation
fieldToMatch :: FieldToMatch
regexString :: Text
$sel:textTransformations:RegexMatchStatement' :: RegexMatchStatement -> NonEmpty TextTransformation
$sel:fieldToMatch:RegexMatchStatement' :: RegexMatchStatement -> FieldToMatch
$sel:regexString:RegexMatchStatement' :: RegexMatchStatement -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
regexString
      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 RegexMatchStatement where
  toJSON :: RegexMatchStatement -> Value
toJSON RegexMatchStatement' {NonEmpty TextTransformation
Text
FieldToMatch
textTransformations :: NonEmpty TextTransformation
fieldToMatch :: FieldToMatch
regexString :: Text
$sel:textTransformations:RegexMatchStatement' :: RegexMatchStatement -> NonEmpty TextTransformation
$sel:fieldToMatch:RegexMatchStatement' :: RegexMatchStatement -> FieldToMatch
$sel:regexString:RegexMatchStatement' :: RegexMatchStatement -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"RegexString" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
regexString),
            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)
          ]
      )