{-# 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.WAF.Types.Rule
-- 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.WAF.Types.Rule 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.WAF.Types.Predicate

-- | 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.
--
-- A combination of ByteMatchSet, IPSet, and\/or SqlInjectionMatchSet
-- objects that identify the web requests that you want to allow, block, or
-- count. For example, you might create a @Rule@ that includes the
-- following predicates:
--
-- -   An @IPSet@ that causes AWS WAF to search for web requests that
--     originate from the IP address @192.0.2.44@
--
-- -   A @ByteMatchSet@ that causes AWS WAF to search for web requests for
--     which the value of the @User-Agent@ header is @BadBot@.
--
-- To match the settings in this @Rule@, a request must originate from
-- @192.0.2.44@ AND include a @User-Agent@ header for which the value is
-- @BadBot@.
--
-- /See:/ 'newRule' smart constructor.
data Rule = Rule'
  { -- | A friendly name or description for the metrics for this @Rule@. The name
    -- can contain only alphanumeric characters (A-Z, a-z, 0-9), with maximum
    -- length 128 and minimum length one. It can\'t contain whitespace or
    -- metric names reserved for AWS WAF, including \"All\" and
    -- \"Default_Action.\" You can\'t change @MetricName@ after you create the
    -- @Rule@.
    Rule -> Maybe Text
metricName :: Prelude.Maybe Prelude.Text,
    -- | The friendly name or description for the @Rule@. You can\'t change the
    -- name of a @Rule@ after you create it.
    Rule -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | A unique identifier for a @Rule@. You use @RuleId@ to get more
    -- information about a @Rule@ (see GetRule), update a @Rule@ (see
    -- UpdateRule), insert a @Rule@ into a @WebACL@ or delete a one from a
    -- @WebACL@ (see UpdateWebACL), or delete a @Rule@ from AWS WAF (see
    -- DeleteRule).
    --
    -- @RuleId@ is returned by CreateRule and by ListRules.
    Rule -> Text
ruleId :: Prelude.Text,
    -- | The @Predicates@ object contains one @Predicate@ element for each
    -- ByteMatchSet, IPSet, or SqlInjectionMatchSet object that you want to
    -- include in a @Rule@.
    Rule -> [Predicate]
predicates :: [Predicate]
  }
  deriving (Rule -> Rule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Rule -> Rule -> Bool
$c/= :: Rule -> Rule -> Bool
== :: Rule -> Rule -> Bool
$c== :: Rule -> Rule -> Bool
Prelude.Eq, ReadPrec [Rule]
ReadPrec Rule
Int -> ReadS Rule
ReadS [Rule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Rule]
$creadListPrec :: ReadPrec [Rule]
readPrec :: ReadPrec Rule
$creadPrec :: ReadPrec Rule
readList :: ReadS [Rule]
$creadList :: ReadS [Rule]
readsPrec :: Int -> ReadS Rule
$creadsPrec :: Int -> ReadS Rule
Prelude.Read, Int -> Rule -> ShowS
[Rule] -> ShowS
Rule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Rule] -> ShowS
$cshowList :: [Rule] -> ShowS
show :: Rule -> String
$cshow :: Rule -> String
showsPrec :: Int -> Rule -> ShowS
$cshowsPrec :: Int -> Rule -> ShowS
Prelude.Show, forall x. Rep Rule x -> Rule
forall x. Rule -> Rep Rule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Rule x -> Rule
$cfrom :: forall x. Rule -> Rep Rule x
Prelude.Generic)

-- |
-- Create a value of 'Rule' 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:
--
-- 'metricName', 'rule_metricName' - A friendly name or description for the metrics for this @Rule@. The name
-- can contain only alphanumeric characters (A-Z, a-z, 0-9), with maximum
-- length 128 and minimum length one. It can\'t contain whitespace or
-- metric names reserved for AWS WAF, including \"All\" and
-- \"Default_Action.\" You can\'t change @MetricName@ after you create the
-- @Rule@.
--
-- 'name', 'rule_name' - The friendly name or description for the @Rule@. You can\'t change the
-- name of a @Rule@ after you create it.
--
-- 'ruleId', 'rule_ruleId' - A unique identifier for a @Rule@. You use @RuleId@ to get more
-- information about a @Rule@ (see GetRule), update a @Rule@ (see
-- UpdateRule), insert a @Rule@ into a @WebACL@ or delete a one from a
-- @WebACL@ (see UpdateWebACL), or delete a @Rule@ from AWS WAF (see
-- DeleteRule).
--
-- @RuleId@ is returned by CreateRule and by ListRules.
--
-- 'predicates', 'rule_predicates' - The @Predicates@ object contains one @Predicate@ element for each
-- ByteMatchSet, IPSet, or SqlInjectionMatchSet object that you want to
-- include in a @Rule@.
newRule ::
  -- | 'ruleId'
  Prelude.Text ->
  Rule
newRule :: Text -> Rule
newRule Text
pRuleId_ =
  Rule'
    { $sel:metricName:Rule' :: Maybe Text
metricName = forall a. Maybe a
Prelude.Nothing,
      $sel:name:Rule' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:ruleId:Rule' :: Text
ruleId = Text
pRuleId_,
      $sel:predicates:Rule' :: [Predicate]
predicates = forall a. Monoid a => a
Prelude.mempty
    }

-- | A friendly name or description for the metrics for this @Rule@. The name
-- can contain only alphanumeric characters (A-Z, a-z, 0-9), with maximum
-- length 128 and minimum length one. It can\'t contain whitespace or
-- metric names reserved for AWS WAF, including \"All\" and
-- \"Default_Action.\" You can\'t change @MetricName@ after you create the
-- @Rule@.
rule_metricName :: Lens.Lens' Rule (Prelude.Maybe Prelude.Text)
rule_metricName :: Lens' Rule (Maybe Text)
rule_metricName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe Text
metricName :: Maybe Text
$sel:metricName:Rule' :: Rule -> Maybe Text
metricName} -> Maybe Text
metricName) (\s :: Rule
s@Rule' {} Maybe Text
a -> Rule
s {$sel:metricName:Rule' :: Maybe Text
metricName = Maybe Text
a} :: Rule)

-- | The friendly name or description for the @Rule@. You can\'t change the
-- name of a @Rule@ after you create it.
rule_name :: Lens.Lens' Rule (Prelude.Maybe Prelude.Text)
rule_name :: Lens' Rule (Maybe Text)
rule_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe Text
name :: Maybe Text
$sel:name:Rule' :: Rule -> Maybe Text
name} -> Maybe Text
name) (\s :: Rule
s@Rule' {} Maybe Text
a -> Rule
s {$sel:name:Rule' :: Maybe Text
name = Maybe Text
a} :: Rule)

-- | A unique identifier for a @Rule@. You use @RuleId@ to get more
-- information about a @Rule@ (see GetRule), update a @Rule@ (see
-- UpdateRule), insert a @Rule@ into a @WebACL@ or delete a one from a
-- @WebACL@ (see UpdateWebACL), or delete a @Rule@ from AWS WAF (see
-- DeleteRule).
--
-- @RuleId@ is returned by CreateRule and by ListRules.
rule_ruleId :: Lens.Lens' Rule Prelude.Text
rule_ruleId :: Lens' Rule Text
rule_ruleId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Text
ruleId :: Text
$sel:ruleId:Rule' :: Rule -> Text
ruleId} -> Text
ruleId) (\s :: Rule
s@Rule' {} Text
a -> Rule
s {$sel:ruleId:Rule' :: Text
ruleId = Text
a} :: Rule)

-- | The @Predicates@ object contains one @Predicate@ element for each
-- ByteMatchSet, IPSet, or SqlInjectionMatchSet object that you want to
-- include in a @Rule@.
rule_predicates :: Lens.Lens' Rule [Predicate]
rule_predicates :: Lens' Rule [Predicate]
rule_predicates = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {[Predicate]
predicates :: [Predicate]
$sel:predicates:Rule' :: Rule -> [Predicate]
predicates} -> [Predicate]
predicates) (\s :: Rule
s@Rule' {} [Predicate]
a -> Rule
s {$sel:predicates:Rule' :: [Predicate]
predicates = [Predicate]
a} :: Rule) 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 Rule where
  parseJSON :: Value -> Parser Rule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Rule"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Text -> [Predicate] -> Rule
Rule'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"MetricName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Name")
            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
"RuleId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Predicates" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable Rule where
  hashWithSalt :: Int -> Rule -> Int
hashWithSalt Int
_salt Rule' {[Predicate]
Maybe Text
Text
predicates :: [Predicate]
ruleId :: Text
name :: Maybe Text
metricName :: Maybe Text
$sel:predicates:Rule' :: Rule -> [Predicate]
$sel:ruleId:Rule' :: Rule -> Text
$sel:name:Rule' :: Rule -> Maybe Text
$sel:metricName:Rule' :: Rule -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
metricName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
ruleId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Predicate]
predicates

instance Prelude.NFData Rule where
  rnf :: Rule -> ()
rnf Rule' {[Predicate]
Maybe Text
Text
predicates :: [Predicate]
ruleId :: Text
name :: Maybe Text
metricName :: Maybe Text
$sel:predicates:Rule' :: Rule -> [Predicate]
$sel:ruleId:Rule' :: Rule -> Text
$sel:name:Rule' :: Rule -> Maybe Text
$sel:metricName:Rule' :: Rule -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
metricName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
ruleId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Predicate]
predicates