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

-- | A rule statement that compares a number of bytes against the size of a
-- request component, using a comparison operator, such as greater than (>)
-- or less than (\<). For example, you can use a size constraint statement
-- to look for query strings that are longer than 100 bytes.
--
-- If you configure WAF to inspect the request body, WAF inspects only the
-- first 8192 bytes (8 KB). If the request body for your web requests never
-- exceeds 8192 bytes, you could use a size constraint statement to block
-- requests that have a request body greater than 8192 bytes.
--
-- If you choose URI for the value of Part of the request to filter on, the
-- slash (\/) in the URI counts as one character. For example, the URI
-- @\/logo.jpg@ is nine characters long.
--
-- /See:/ 'newSizeConstraintStatement' smart constructor.
data SizeConstraintStatement = SizeConstraintStatement'
  { -- | The part of the web request that you want WAF to inspect.
    SizeConstraintStatement -> FieldToMatch
fieldToMatch :: FieldToMatch,
    -- | The operator to use to compare the request part to the size setting.
    SizeConstraintStatement -> ComparisonOperator
comparisonOperator :: ComparisonOperator,
    -- | The size, in byte, to compare to the request part, after any
    -- transformations.
    SizeConstraintStatement -> Natural
size :: Prelude.Natural,
    -- | 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.
    SizeConstraintStatement -> NonEmpty TextTransformation
textTransformations :: Prelude.NonEmpty TextTransformation
  }
  deriving (SizeConstraintStatement -> SizeConstraintStatement -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SizeConstraintStatement -> SizeConstraintStatement -> Bool
$c/= :: SizeConstraintStatement -> SizeConstraintStatement -> Bool
== :: SizeConstraintStatement -> SizeConstraintStatement -> Bool
$c== :: SizeConstraintStatement -> SizeConstraintStatement -> Bool
Prelude.Eq, ReadPrec [SizeConstraintStatement]
ReadPrec SizeConstraintStatement
Int -> ReadS SizeConstraintStatement
ReadS [SizeConstraintStatement]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SizeConstraintStatement]
$creadListPrec :: ReadPrec [SizeConstraintStatement]
readPrec :: ReadPrec SizeConstraintStatement
$creadPrec :: ReadPrec SizeConstraintStatement
readList :: ReadS [SizeConstraintStatement]
$creadList :: ReadS [SizeConstraintStatement]
readsPrec :: Int -> ReadS SizeConstraintStatement
$creadsPrec :: Int -> ReadS SizeConstraintStatement
Prelude.Read, Int -> SizeConstraintStatement -> ShowS
[SizeConstraintStatement] -> ShowS
SizeConstraintStatement -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SizeConstraintStatement] -> ShowS
$cshowList :: [SizeConstraintStatement] -> ShowS
show :: SizeConstraintStatement -> String
$cshow :: SizeConstraintStatement -> String
showsPrec :: Int -> SizeConstraintStatement -> ShowS
$cshowsPrec :: Int -> SizeConstraintStatement -> ShowS
Prelude.Show, forall x. Rep SizeConstraintStatement x -> SizeConstraintStatement
forall x. SizeConstraintStatement -> Rep SizeConstraintStatement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SizeConstraintStatement x -> SizeConstraintStatement
$cfrom :: forall x. SizeConstraintStatement -> Rep SizeConstraintStatement x
Prelude.Generic)

-- |
-- Create a value of 'SizeConstraintStatement' 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:
--
-- 'fieldToMatch', 'sizeConstraintStatement_fieldToMatch' - The part of the web request that you want WAF to inspect.
--
-- 'comparisonOperator', 'sizeConstraintStatement_comparisonOperator' - The operator to use to compare the request part to the size setting.
--
-- 'size', 'sizeConstraintStatement_size' - The size, in byte, to compare to the request part, after any
-- transformations.
--
-- 'textTransformations', 'sizeConstraintStatement_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.
newSizeConstraintStatement ::
  -- | 'fieldToMatch'
  FieldToMatch ->
  -- | 'comparisonOperator'
  ComparisonOperator ->
  -- | 'size'
  Prelude.Natural ->
  -- | 'textTransformations'
  Prelude.NonEmpty TextTransformation ->
  SizeConstraintStatement
newSizeConstraintStatement :: FieldToMatch
-> ComparisonOperator
-> Natural
-> NonEmpty TextTransformation
-> SizeConstraintStatement
newSizeConstraintStatement
  FieldToMatch
pFieldToMatch_
  ComparisonOperator
pComparisonOperator_
  Natural
pSize_
  NonEmpty TextTransformation
pTextTransformations_ =
    SizeConstraintStatement'
      { $sel:fieldToMatch:SizeConstraintStatement' :: FieldToMatch
fieldToMatch =
          FieldToMatch
pFieldToMatch_,
        $sel:comparisonOperator:SizeConstraintStatement' :: ComparisonOperator
comparisonOperator = ComparisonOperator
pComparisonOperator_,
        $sel:size:SizeConstraintStatement' :: Natural
size = Natural
pSize_,
        $sel:textTransformations:SizeConstraintStatement' :: 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 part of the web request that you want WAF to inspect.
sizeConstraintStatement_fieldToMatch :: Lens.Lens' SizeConstraintStatement FieldToMatch
sizeConstraintStatement_fieldToMatch :: Lens' SizeConstraintStatement FieldToMatch
sizeConstraintStatement_fieldToMatch = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SizeConstraintStatement' {FieldToMatch
fieldToMatch :: FieldToMatch
$sel:fieldToMatch:SizeConstraintStatement' :: SizeConstraintStatement -> FieldToMatch
fieldToMatch} -> FieldToMatch
fieldToMatch) (\s :: SizeConstraintStatement
s@SizeConstraintStatement' {} FieldToMatch
a -> SizeConstraintStatement
s {$sel:fieldToMatch:SizeConstraintStatement' :: FieldToMatch
fieldToMatch = FieldToMatch
a} :: SizeConstraintStatement)

-- | The operator to use to compare the request part to the size setting.
sizeConstraintStatement_comparisonOperator :: Lens.Lens' SizeConstraintStatement ComparisonOperator
sizeConstraintStatement_comparisonOperator :: Lens' SizeConstraintStatement ComparisonOperator
sizeConstraintStatement_comparisonOperator = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SizeConstraintStatement' {ComparisonOperator
comparisonOperator :: ComparisonOperator
$sel:comparisonOperator:SizeConstraintStatement' :: SizeConstraintStatement -> ComparisonOperator
comparisonOperator} -> ComparisonOperator
comparisonOperator) (\s :: SizeConstraintStatement
s@SizeConstraintStatement' {} ComparisonOperator
a -> SizeConstraintStatement
s {$sel:comparisonOperator:SizeConstraintStatement' :: ComparisonOperator
comparisonOperator = ComparisonOperator
a} :: SizeConstraintStatement)

-- | The size, in byte, to compare to the request part, after any
-- transformations.
sizeConstraintStatement_size :: Lens.Lens' SizeConstraintStatement Prelude.Natural
sizeConstraintStatement_size :: Lens' SizeConstraintStatement Natural
sizeConstraintStatement_size = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SizeConstraintStatement' {Natural
size :: Natural
$sel:size:SizeConstraintStatement' :: SizeConstraintStatement -> Natural
size} -> Natural
size) (\s :: SizeConstraintStatement
s@SizeConstraintStatement' {} Natural
a -> SizeConstraintStatement
s {$sel:size:SizeConstraintStatement' :: Natural
size = Natural
a} :: SizeConstraintStatement)

-- | 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.
sizeConstraintStatement_textTransformations :: Lens.Lens' SizeConstraintStatement (Prelude.NonEmpty TextTransformation)
sizeConstraintStatement_textTransformations :: Lens' SizeConstraintStatement (NonEmpty TextTransformation)
sizeConstraintStatement_textTransformations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SizeConstraintStatement' {NonEmpty TextTransformation
textTransformations :: NonEmpty TextTransformation
$sel:textTransformations:SizeConstraintStatement' :: SizeConstraintStatement -> NonEmpty TextTransformation
textTransformations} -> NonEmpty TextTransformation
textTransformations) (\s :: SizeConstraintStatement
s@SizeConstraintStatement' {} NonEmpty TextTransformation
a -> SizeConstraintStatement
s {$sel:textTransformations:SizeConstraintStatement' :: NonEmpty TextTransformation
textTransformations = NonEmpty TextTransformation
a} :: SizeConstraintStatement) 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 SizeConstraintStatement where
  parseJSON :: Value -> Parser SizeConstraintStatement
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SizeConstraintStatement"
      ( \Object
x ->
          FieldToMatch
-> ComparisonOperator
-> Natural
-> NonEmpty TextTransformation
-> SizeConstraintStatement
SizeConstraintStatement'
            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
"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
"ComparisonOperator")
            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
"Size")
            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 SizeConstraintStatement where
  hashWithSalt :: Int -> SizeConstraintStatement -> Int
hashWithSalt Int
_salt SizeConstraintStatement' {Natural
NonEmpty TextTransformation
ComparisonOperator
FieldToMatch
textTransformations :: NonEmpty TextTransformation
size :: Natural
comparisonOperator :: ComparisonOperator
fieldToMatch :: FieldToMatch
$sel:textTransformations:SizeConstraintStatement' :: SizeConstraintStatement -> NonEmpty TextTransformation
$sel:size:SizeConstraintStatement' :: SizeConstraintStatement -> Natural
$sel:comparisonOperator:SizeConstraintStatement' :: SizeConstraintStatement -> ComparisonOperator
$sel:fieldToMatch:SizeConstraintStatement' :: SizeConstraintStatement -> FieldToMatch
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` FieldToMatch
fieldToMatch
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ComparisonOperator
comparisonOperator
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
size
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty TextTransformation
textTransformations

instance Prelude.NFData SizeConstraintStatement where
  rnf :: SizeConstraintStatement -> ()
rnf SizeConstraintStatement' {Natural
NonEmpty TextTransformation
ComparisonOperator
FieldToMatch
textTransformations :: NonEmpty TextTransformation
size :: Natural
comparisonOperator :: ComparisonOperator
fieldToMatch :: FieldToMatch
$sel:textTransformations:SizeConstraintStatement' :: SizeConstraintStatement -> NonEmpty TextTransformation
$sel:size:SizeConstraintStatement' :: SizeConstraintStatement -> Natural
$sel:comparisonOperator:SizeConstraintStatement' :: SizeConstraintStatement -> ComparisonOperator
$sel:fieldToMatch:SizeConstraintStatement' :: SizeConstraintStatement -> FieldToMatch
..} =
    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 ComparisonOperator
comparisonOperator
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
size
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty TextTransformation
textTransformations

instance Data.ToJSON SizeConstraintStatement where
  toJSON :: SizeConstraintStatement -> Value
toJSON SizeConstraintStatement' {Natural
NonEmpty TextTransformation
ComparisonOperator
FieldToMatch
textTransformations :: NonEmpty TextTransformation
size :: Natural
comparisonOperator :: ComparisonOperator
fieldToMatch :: FieldToMatch
$sel:textTransformations:SizeConstraintStatement' :: SizeConstraintStatement -> NonEmpty TextTransformation
$sel:size:SizeConstraintStatement' :: SizeConstraintStatement -> Natural
$sel:comparisonOperator:SizeConstraintStatement' :: SizeConstraintStatement -> ComparisonOperator
$sel:fieldToMatch:SizeConstraintStatement' :: SizeConstraintStatement -> FieldToMatch
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ 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
"ComparisonOperator" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ComparisonOperator
comparisonOperator),
            forall a. a -> Maybe a
Prelude.Just (Key
"Size" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
size),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"TextTransformations" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty TextTransformation
textTransformations)
          ]
      )