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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(Rule -> Rule -> Bool) -> (Rule -> Rule -> Bool) -> Eq Rule
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]
(Int -> ReadS Rule)
-> ReadS [Rule] -> ReadPrec Rule -> ReadPrec [Rule] -> Read 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
(Int -> Rule -> ShowS)
-> (Rule -> String) -> ([Rule] -> ShowS) -> Show Rule
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. Rule -> Rep Rule x)
-> (forall x. Rep Rule x -> Rule) -> Generic Rule
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' :: Maybe Text -> Maybe Text -> Text -> [Predicate] -> Rule
Rule'
    { $sel:metricName:Rule' :: Maybe Text
metricName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Rule' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:ruleId:Rule' :: Text
ruleId = Text
pRuleId_,
      $sel:predicates:Rule' :: [Predicate]
predicates = [Predicate]
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 :: (Maybe Text -> f (Maybe Text)) -> Rule -> f Rule
rule_metricName = (Rule -> Maybe Text)
-> (Rule -> Maybe Text -> Rule)
-> Lens Rule Rule (Maybe Text) (Maybe Text)
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 :: (Maybe Text -> f (Maybe Text)) -> Rule -> f Rule
rule_name = (Rule -> Maybe Text)
-> (Rule -> Maybe Text -> Rule)
-> Lens Rule Rule (Maybe Text) (Maybe Text)
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 :: (Text -> f Text) -> Rule -> f Rule
rule_ruleId = (Rule -> Text)
-> (Rule -> Text -> Rule) -> Lens Rule Rule Text Text
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 :: ([Predicate] -> f [Predicate]) -> Rule -> f Rule
rule_predicates = (Rule -> [Predicate])
-> (Rule -> [Predicate] -> Rule)
-> Lens Rule Rule [Predicate] [Predicate]
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) (([Predicate] -> f [Predicate]) -> Rule -> f Rule)
-> (([Predicate] -> f [Predicate]) -> [Predicate] -> f [Predicate])
-> ([Predicate] -> f [Predicate])
-> Rule
-> f Rule
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Predicate] -> f [Predicate]) -> [Predicate] -> f [Predicate]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON Rule where
  parseJSON :: Value -> Parser Rule
parseJSON =
    String -> (Object -> Parser Rule) -> Value -> Parser Rule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Rule"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Text -> [Predicate] -> Rule
Rule'
            (Maybe Text -> Maybe Text -> Text -> [Predicate] -> Rule)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Text -> [Predicate] -> Rule)
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
"MetricName")
            Parser (Maybe Text -> Text -> [Predicate] -> Rule)
-> Parser (Maybe Text) -> Parser (Text -> [Predicate] -> Rule)
forall (f :: * -> *) a b. Applicative f => 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
"Name")
            Parser (Text -> [Predicate] -> Rule)
-> Parser Text -> Parser ([Predicate] -> Rule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"RuleId")
            Parser ([Predicate] -> Rule) -> Parser [Predicate] -> Parser Rule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [Predicate])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Predicates" Parser (Maybe [Predicate]) -> [Predicate] -> Parser [Predicate]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [Predicate]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable Rule

instance Prelude.NFData Rule