{-# 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.WAFRegional.Types.FieldToMatch
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.WAFRegional.Types.FieldToMatch where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.WAFRegional.Types.MatchFieldType

-- | This is __AWS WAF Classic__ documentation. For more information, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/classic-waf-chapter.html AWS WAF Classic>
-- in the developer guide.
--
-- __For the latest version of AWS WAF__, use the AWS WAFV2 API and see the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html AWS WAF Developer Guide>.
-- With the latest version, AWS WAF has a single set of endpoints for
-- regional and global use.
--
-- Specifies where in a web request to look for @TargetString@.
--
-- /See:/ 'newFieldToMatch' smart constructor.
data FieldToMatch = FieldToMatch'
  { -- | When the value of @Type@ is @HEADER@, enter the name of the header that
    -- you want AWS WAF to search, for example, @User-Agent@ or @Referer@. The
    -- name of the header is not case sensitive.
    --
    -- When the value of @Type@ is @SINGLE_QUERY_ARG@, enter the name of the
    -- parameter that you want AWS WAF to search, for example, @UserName@ or
    -- @SalesRegion@. The parameter name is not case sensitive.
    --
    -- If the value of @Type@ is any other value, omit @Data@.
    FieldToMatch -> Maybe Text
data' :: Prelude.Maybe Prelude.Text,
    -- | The part of the web request that you want AWS WAF to search for a
    -- specified string. Parts of a request that you can search include the
    -- following:
    --
    -- -   @HEADER@: A specified request header, for example, the value of the
    --     @User-Agent@ or @Referer@ header. If you choose @HEADER@ for the
    --     type, specify the name of the header in @Data@.
    --
    -- -   @METHOD@: The HTTP method, which indicated the type of operation
    --     that the request is asking the origin to perform. Amazon CloudFront
    --     supports the following methods: @DELETE@, @GET@, @HEAD@, @OPTIONS@,
    --     @PATCH@, @POST@, and @PUT@.
    --
    -- -   @QUERY_STRING@: A query string, which is the part of a URL that
    --     appears after a @?@ character, if any.
    --
    -- -   @URI@: The part of a web request that identifies a resource, for
    --     example, @\/images\/daily-ad.jpg@.
    --
    -- -   @BODY@: The part of a request that contains any additional data that
    --     you want to send to your web server as the HTTP request body, such
    --     as data from a form. The request body immediately follows the
    --     request headers. Note that only the first @8192@ bytes of the
    --     request body are forwarded to AWS WAF for inspection. To allow or
    --     block requests based on the length of the body, you can create a
    --     size constraint set. For more information, see
    --     CreateSizeConstraintSet.
    --
    -- -   @SINGLE_QUERY_ARG@: The parameter in the query string that you will
    --     inspect, such as /UserName/ or /SalesRegion/. The maximum length for
    --     @SINGLE_QUERY_ARG@ is 30 characters.
    --
    -- -   @ALL_QUERY_ARGS@: Similar to @SINGLE_QUERY_ARG@, but rather than
    --     inspecting a single parameter, AWS WAF will inspect all parameters
    --     within the query for the value or regex pattern that you specify in
    --     @TargetString@.
    FieldToMatch -> MatchFieldType
type' :: MatchFieldType
  }
  deriving (FieldToMatch -> FieldToMatch -> Bool
(FieldToMatch -> FieldToMatch -> Bool)
-> (FieldToMatch -> FieldToMatch -> Bool) -> Eq FieldToMatch
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FieldToMatch -> FieldToMatch -> Bool
$c/= :: FieldToMatch -> FieldToMatch -> Bool
== :: FieldToMatch -> FieldToMatch -> Bool
$c== :: FieldToMatch -> FieldToMatch -> Bool
Prelude.Eq, ReadPrec [FieldToMatch]
ReadPrec FieldToMatch
Int -> ReadS FieldToMatch
ReadS [FieldToMatch]
(Int -> ReadS FieldToMatch)
-> ReadS [FieldToMatch]
-> ReadPrec FieldToMatch
-> ReadPrec [FieldToMatch]
-> Read FieldToMatch
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FieldToMatch]
$creadListPrec :: ReadPrec [FieldToMatch]
readPrec :: ReadPrec FieldToMatch
$creadPrec :: ReadPrec FieldToMatch
readList :: ReadS [FieldToMatch]
$creadList :: ReadS [FieldToMatch]
readsPrec :: Int -> ReadS FieldToMatch
$creadsPrec :: Int -> ReadS FieldToMatch
Prelude.Read, Int -> FieldToMatch -> ShowS
[FieldToMatch] -> ShowS
FieldToMatch -> String
(Int -> FieldToMatch -> ShowS)
-> (FieldToMatch -> String)
-> ([FieldToMatch] -> ShowS)
-> Show FieldToMatch
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FieldToMatch] -> ShowS
$cshowList :: [FieldToMatch] -> ShowS
show :: FieldToMatch -> String
$cshow :: FieldToMatch -> String
showsPrec :: Int -> FieldToMatch -> ShowS
$cshowsPrec :: Int -> FieldToMatch -> ShowS
Prelude.Show, (forall x. FieldToMatch -> Rep FieldToMatch x)
-> (forall x. Rep FieldToMatch x -> FieldToMatch)
-> Generic FieldToMatch
forall x. Rep FieldToMatch x -> FieldToMatch
forall x. FieldToMatch -> Rep FieldToMatch x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FieldToMatch x -> FieldToMatch
$cfrom :: forall x. FieldToMatch -> Rep FieldToMatch x
Prelude.Generic)

-- |
-- Create a value of 'FieldToMatch' 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:
--
-- 'data'', 'fieldToMatch_data' - When the value of @Type@ is @HEADER@, enter the name of the header that
-- you want AWS WAF to search, for example, @User-Agent@ or @Referer@. The
-- name of the header is not case sensitive.
--
-- When the value of @Type@ is @SINGLE_QUERY_ARG@, enter the name of the
-- parameter that you want AWS WAF to search, for example, @UserName@ or
-- @SalesRegion@. The parameter name is not case sensitive.
--
-- If the value of @Type@ is any other value, omit @Data@.
--
-- 'type'', 'fieldToMatch_type' - The part of the web request that you want AWS WAF to search for a
-- specified string. Parts of a request that you can search include the
-- following:
--
-- -   @HEADER@: A specified request header, for example, the value of the
--     @User-Agent@ or @Referer@ header. If you choose @HEADER@ for the
--     type, specify the name of the header in @Data@.
--
-- -   @METHOD@: The HTTP method, which indicated the type of operation
--     that the request is asking the origin to perform. Amazon CloudFront
--     supports the following methods: @DELETE@, @GET@, @HEAD@, @OPTIONS@,
--     @PATCH@, @POST@, and @PUT@.
--
-- -   @QUERY_STRING@: A query string, which is the part of a URL that
--     appears after a @?@ character, if any.
--
-- -   @URI@: The part of a web request that identifies a resource, for
--     example, @\/images\/daily-ad.jpg@.
--
-- -   @BODY@: The part of a request that contains any additional data that
--     you want to send to your web server as the HTTP request body, such
--     as data from a form. The request body immediately follows the
--     request headers. Note that only the first @8192@ bytes of the
--     request body are forwarded to AWS WAF for inspection. To allow or
--     block requests based on the length of the body, you can create a
--     size constraint set. For more information, see
--     CreateSizeConstraintSet.
--
-- -   @SINGLE_QUERY_ARG@: The parameter in the query string that you will
--     inspect, such as /UserName/ or /SalesRegion/. The maximum length for
--     @SINGLE_QUERY_ARG@ is 30 characters.
--
-- -   @ALL_QUERY_ARGS@: Similar to @SINGLE_QUERY_ARG@, but rather than
--     inspecting a single parameter, AWS WAF will inspect all parameters
--     within the query for the value or regex pattern that you specify in
--     @TargetString@.
newFieldToMatch ::
  -- | 'type''
  MatchFieldType ->
  FieldToMatch
newFieldToMatch :: MatchFieldType -> FieldToMatch
newFieldToMatch MatchFieldType
pType_ =
  FieldToMatch' :: Maybe Text -> MatchFieldType -> FieldToMatch
FieldToMatch'
    { $sel:data':FieldToMatch' :: Maybe Text
data' = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:type':FieldToMatch' :: MatchFieldType
type' = MatchFieldType
pType_
    }

-- | When the value of @Type@ is @HEADER@, enter the name of the header that
-- you want AWS WAF to search, for example, @User-Agent@ or @Referer@. The
-- name of the header is not case sensitive.
--
-- When the value of @Type@ is @SINGLE_QUERY_ARG@, enter the name of the
-- parameter that you want AWS WAF to search, for example, @UserName@ or
-- @SalesRegion@. The parameter name is not case sensitive.
--
-- If the value of @Type@ is any other value, omit @Data@.
fieldToMatch_data :: Lens.Lens' FieldToMatch (Prelude.Maybe Prelude.Text)
fieldToMatch_data :: (Maybe Text -> f (Maybe Text)) -> FieldToMatch -> f FieldToMatch
fieldToMatch_data = (FieldToMatch -> Maybe Text)
-> (FieldToMatch -> Maybe Text -> FieldToMatch)
-> Lens FieldToMatch FieldToMatch (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FieldToMatch' {Maybe Text
data' :: Maybe Text
$sel:data':FieldToMatch' :: FieldToMatch -> Maybe Text
data'} -> Maybe Text
data') (\s :: FieldToMatch
s@FieldToMatch' {} Maybe Text
a -> FieldToMatch
s {$sel:data':FieldToMatch' :: Maybe Text
data' = Maybe Text
a} :: FieldToMatch)

-- | The part of the web request that you want AWS WAF to search for a
-- specified string. Parts of a request that you can search include the
-- following:
--
-- -   @HEADER@: A specified request header, for example, the value of the
--     @User-Agent@ or @Referer@ header. If you choose @HEADER@ for the
--     type, specify the name of the header in @Data@.
--
-- -   @METHOD@: The HTTP method, which indicated the type of operation
--     that the request is asking the origin to perform. Amazon CloudFront
--     supports the following methods: @DELETE@, @GET@, @HEAD@, @OPTIONS@,
--     @PATCH@, @POST@, and @PUT@.
--
-- -   @QUERY_STRING@: A query string, which is the part of a URL that
--     appears after a @?@ character, if any.
--
-- -   @URI@: The part of a web request that identifies a resource, for
--     example, @\/images\/daily-ad.jpg@.
--
-- -   @BODY@: The part of a request that contains any additional data that
--     you want to send to your web server as the HTTP request body, such
--     as data from a form. The request body immediately follows the
--     request headers. Note that only the first @8192@ bytes of the
--     request body are forwarded to AWS WAF for inspection. To allow or
--     block requests based on the length of the body, you can create a
--     size constraint set. For more information, see
--     CreateSizeConstraintSet.
--
-- -   @SINGLE_QUERY_ARG@: The parameter in the query string that you will
--     inspect, such as /UserName/ or /SalesRegion/. The maximum length for
--     @SINGLE_QUERY_ARG@ is 30 characters.
--
-- -   @ALL_QUERY_ARGS@: Similar to @SINGLE_QUERY_ARG@, but rather than
--     inspecting a single parameter, AWS WAF will inspect all parameters
--     within the query for the value or regex pattern that you specify in
--     @TargetString@.
fieldToMatch_type :: Lens.Lens' FieldToMatch MatchFieldType
fieldToMatch_type :: (MatchFieldType -> f MatchFieldType)
-> FieldToMatch -> f FieldToMatch
fieldToMatch_type = (FieldToMatch -> MatchFieldType)
-> (FieldToMatch -> MatchFieldType -> FieldToMatch)
-> Lens FieldToMatch FieldToMatch MatchFieldType MatchFieldType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FieldToMatch' {MatchFieldType
type' :: MatchFieldType
$sel:type':FieldToMatch' :: FieldToMatch -> MatchFieldType
type'} -> MatchFieldType
type') (\s :: FieldToMatch
s@FieldToMatch' {} MatchFieldType
a -> FieldToMatch
s {$sel:type':FieldToMatch' :: MatchFieldType
type' = MatchFieldType
a} :: FieldToMatch)

instance Core.FromJSON FieldToMatch where
  parseJSON :: Value -> Parser FieldToMatch
parseJSON =
    String
-> (Object -> Parser FieldToMatch) -> Value -> Parser FieldToMatch
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"FieldToMatch"
      ( \Object
x ->
          Maybe Text -> MatchFieldType -> FieldToMatch
FieldToMatch'
            (Maybe Text -> MatchFieldType -> FieldToMatch)
-> Parser (Maybe Text) -> Parser (MatchFieldType -> FieldToMatch)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Data") Parser (MatchFieldType -> FieldToMatch)
-> Parser MatchFieldType -> Parser FieldToMatch
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser MatchFieldType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Type")
      )

instance Prelude.Hashable FieldToMatch

instance Prelude.NFData FieldToMatch

instance Core.ToJSON FieldToMatch where
  toJSON :: FieldToMatch -> Value
toJSON FieldToMatch' {Maybe Text
MatchFieldType
type' :: MatchFieldType
data' :: Maybe Text
$sel:type':FieldToMatch' :: FieldToMatch -> MatchFieldType
$sel:data':FieldToMatch' :: FieldToMatch -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Data" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
data',
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Type" Text -> MatchFieldType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= MatchFieldType
type')
          ]
      )