{-# 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.WebACL
-- 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.WAFRegional.Types.WebACL 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.WAFRegional.Types.ActivatedRule
import Amazonka.WAFRegional.Types.WafAction

-- | 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.
--
-- Contains the @Rules@ that identify the requests that you want to allow,
-- block, or count. In a @WebACL@, you also specify a default action
-- (@ALLOW@ or @BLOCK@), and the action for each @Rule@ that you add to a
-- @WebACL@, for example, block requests from specified IP addresses or
-- block requests from specified referrers. You also associate the @WebACL@
-- with a CloudFront distribution to identify the requests that you want
-- AWS WAF to filter. If you add more than one @Rule@ to a @WebACL@, a
-- request needs to match only one of the specifications to be allowed,
-- blocked, or counted. For more information, see UpdateWebACL.
--
-- /See:/ 'newWebACL' smart constructor.
data WebACL = WebACL'
  { -- | A friendly name or description for the metrics for this @WebACL@. 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
    -- @WebACL@.
    WebACL -> Maybe Text
metricName :: Prelude.Maybe Prelude.Text,
    -- | A friendly name or description of the @WebACL@. You can\'t change the
    -- name of a @WebACL@ after you create it.
    WebACL -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | Tha Amazon Resource Name (ARN) of the web ACL.
    WebACL -> Maybe Text
webACLArn :: Prelude.Maybe Prelude.Text,
    -- | A unique identifier for a @WebACL@. You use @WebACLId@ to get
    -- information about a @WebACL@ (see GetWebACL), update a @WebACL@ (see
    -- UpdateWebACL), and delete a @WebACL@ from AWS WAF (see DeleteWebACL).
    --
    -- @WebACLId@ is returned by CreateWebACL and by ListWebACLs.
    WebACL -> Text
webACLId :: Prelude.Text,
    -- | The action to perform if none of the @Rules@ contained in the @WebACL@
    -- match. The action is specified by the WafAction object.
    WebACL -> WafAction
defaultAction :: WafAction,
    -- | An array that contains the action for each @Rule@ in a @WebACL@, the
    -- priority of the @Rule@, and the ID of the @Rule@.
    WebACL -> [ActivatedRule]
rules :: [ActivatedRule]
  }
  deriving (WebACL -> WebACL -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WebACL -> WebACL -> Bool
$c/= :: WebACL -> WebACL -> Bool
== :: WebACL -> WebACL -> Bool
$c== :: WebACL -> WebACL -> Bool
Prelude.Eq, ReadPrec [WebACL]
ReadPrec WebACL
Int -> ReadS WebACL
ReadS [WebACL]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [WebACL]
$creadListPrec :: ReadPrec [WebACL]
readPrec :: ReadPrec WebACL
$creadPrec :: ReadPrec WebACL
readList :: ReadS [WebACL]
$creadList :: ReadS [WebACL]
readsPrec :: Int -> ReadS WebACL
$creadsPrec :: Int -> ReadS WebACL
Prelude.Read, Int -> WebACL -> ShowS
[WebACL] -> ShowS
WebACL -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WebACL] -> ShowS
$cshowList :: [WebACL] -> ShowS
show :: WebACL -> String
$cshow :: WebACL -> String
showsPrec :: Int -> WebACL -> ShowS
$cshowsPrec :: Int -> WebACL -> ShowS
Prelude.Show, forall x. Rep WebACL x -> WebACL
forall x. WebACL -> Rep WebACL x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep WebACL x -> WebACL
$cfrom :: forall x. WebACL -> Rep WebACL x
Prelude.Generic)

-- |
-- Create a value of 'WebACL' 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', 'webACL_metricName' - A friendly name or description for the metrics for this @WebACL@. 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
-- @WebACL@.
--
-- 'name', 'webACL_name' - A friendly name or description of the @WebACL@. You can\'t change the
-- name of a @WebACL@ after you create it.
--
-- 'webACLArn', 'webACL_webACLArn' - Tha Amazon Resource Name (ARN) of the web ACL.
--
-- 'webACLId', 'webACL_webACLId' - A unique identifier for a @WebACL@. You use @WebACLId@ to get
-- information about a @WebACL@ (see GetWebACL), update a @WebACL@ (see
-- UpdateWebACL), and delete a @WebACL@ from AWS WAF (see DeleteWebACL).
--
-- @WebACLId@ is returned by CreateWebACL and by ListWebACLs.
--
-- 'defaultAction', 'webACL_defaultAction' - The action to perform if none of the @Rules@ contained in the @WebACL@
-- match. The action is specified by the WafAction object.
--
-- 'rules', 'webACL_rules' - An array that contains the action for each @Rule@ in a @WebACL@, the
-- priority of the @Rule@, and the ID of the @Rule@.
newWebACL ::
  -- | 'webACLId'
  Prelude.Text ->
  -- | 'defaultAction'
  WafAction ->
  WebACL
newWebACL :: Text -> WafAction -> WebACL
newWebACL Text
pWebACLId_ WafAction
pDefaultAction_ =
  WebACL'
    { $sel:metricName:WebACL' :: Maybe Text
metricName = forall a. Maybe a
Prelude.Nothing,
      $sel:name:WebACL' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:webACLArn:WebACL' :: Maybe Text
webACLArn = forall a. Maybe a
Prelude.Nothing,
      $sel:webACLId:WebACL' :: Text
webACLId = Text
pWebACLId_,
      $sel:defaultAction:WebACL' :: WafAction
defaultAction = WafAction
pDefaultAction_,
      $sel:rules:WebACL' :: [ActivatedRule]
rules = forall a. Monoid a => a
Prelude.mempty
    }

-- | A friendly name or description for the metrics for this @WebACL@. 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
-- @WebACL@.
webACL_metricName :: Lens.Lens' WebACL (Prelude.Maybe Prelude.Text)
webACL_metricName :: Lens' WebACL (Maybe Text)
webACL_metricName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebACL' {Maybe Text
metricName :: Maybe Text
$sel:metricName:WebACL' :: WebACL -> Maybe Text
metricName} -> Maybe Text
metricName) (\s :: WebACL
s@WebACL' {} Maybe Text
a -> WebACL
s {$sel:metricName:WebACL' :: Maybe Text
metricName = Maybe Text
a} :: WebACL)

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

-- | Tha Amazon Resource Name (ARN) of the web ACL.
webACL_webACLArn :: Lens.Lens' WebACL (Prelude.Maybe Prelude.Text)
webACL_webACLArn :: Lens' WebACL (Maybe Text)
webACL_webACLArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebACL' {Maybe Text
webACLArn :: Maybe Text
$sel:webACLArn:WebACL' :: WebACL -> Maybe Text
webACLArn} -> Maybe Text
webACLArn) (\s :: WebACL
s@WebACL' {} Maybe Text
a -> WebACL
s {$sel:webACLArn:WebACL' :: Maybe Text
webACLArn = Maybe Text
a} :: WebACL)

-- | A unique identifier for a @WebACL@. You use @WebACLId@ to get
-- information about a @WebACL@ (see GetWebACL), update a @WebACL@ (see
-- UpdateWebACL), and delete a @WebACL@ from AWS WAF (see DeleteWebACL).
--
-- @WebACLId@ is returned by CreateWebACL and by ListWebACLs.
webACL_webACLId :: Lens.Lens' WebACL Prelude.Text
webACL_webACLId :: Lens' WebACL Text
webACL_webACLId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebACL' {Text
webACLId :: Text
$sel:webACLId:WebACL' :: WebACL -> Text
webACLId} -> Text
webACLId) (\s :: WebACL
s@WebACL' {} Text
a -> WebACL
s {$sel:webACLId:WebACL' :: Text
webACLId = Text
a} :: WebACL)

-- | The action to perform if none of the @Rules@ contained in the @WebACL@
-- match. The action is specified by the WafAction object.
webACL_defaultAction :: Lens.Lens' WebACL WafAction
webACL_defaultAction :: Lens' WebACL WafAction
webACL_defaultAction = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebACL' {WafAction
defaultAction :: WafAction
$sel:defaultAction:WebACL' :: WebACL -> WafAction
defaultAction} -> WafAction
defaultAction) (\s :: WebACL
s@WebACL' {} WafAction
a -> WebACL
s {$sel:defaultAction:WebACL' :: WafAction
defaultAction = WafAction
a} :: WebACL)

-- | An array that contains the action for each @Rule@ in a @WebACL@, the
-- priority of the @Rule@, and the ID of the @Rule@.
webACL_rules :: Lens.Lens' WebACL [ActivatedRule]
webACL_rules :: Lens' WebACL [ActivatedRule]
webACL_rules = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WebACL' {[ActivatedRule]
rules :: [ActivatedRule]
$sel:rules:WebACL' :: WebACL -> [ActivatedRule]
rules} -> [ActivatedRule]
rules) (\s :: WebACL
s@WebACL' {} [ActivatedRule]
a -> WebACL
s {$sel:rules:WebACL' :: [ActivatedRule]
rules = [ActivatedRule]
a} :: WebACL) 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 WebACL where
  parseJSON :: Value -> Parser WebACL
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"WebACL"
      ( \Object
x ->
          Maybe Text
-> Maybe Text
-> Maybe Text
-> Text
-> WafAction
-> [ActivatedRule]
-> WebACL
WebACL'
            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 (Maybe a)
Data..:? Key
"WebACLArn")
            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
"WebACLId")
            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
"DefaultAction")
            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
"Rules" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable WebACL where
  hashWithSalt :: Int -> WebACL -> Int
hashWithSalt Int
_salt WebACL' {[ActivatedRule]
Maybe Text
Text
WafAction
rules :: [ActivatedRule]
defaultAction :: WafAction
webACLId :: Text
webACLArn :: Maybe Text
name :: Maybe Text
metricName :: Maybe Text
$sel:rules:WebACL' :: WebACL -> [ActivatedRule]
$sel:defaultAction:WebACL' :: WebACL -> WafAction
$sel:webACLId:WebACL' :: WebACL -> Text
$sel:webACLArn:WebACL' :: WebACL -> Maybe Text
$sel:name:WebACL' :: WebACL -> Maybe Text
$sel:metricName:WebACL' :: WebACL -> 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` Maybe Text
webACLArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
webACLId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` WafAction
defaultAction
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [ActivatedRule]
rules

instance Prelude.NFData WebACL where
  rnf :: WebACL -> ()
rnf WebACL' {[ActivatedRule]
Maybe Text
Text
WafAction
rules :: [ActivatedRule]
defaultAction :: WafAction
webACLId :: Text
webACLArn :: Maybe Text
name :: Maybe Text
metricName :: Maybe Text
$sel:rules:WebACL' :: WebACL -> [ActivatedRule]
$sel:defaultAction:WebACL' :: WebACL -> WafAction
$sel:webACLId:WebACL' :: WebACL -> Text
$sel:webACLArn:WebACL' :: WebACL -> Maybe Text
$sel:name:WebACL' :: WebACL -> Maybe Text
$sel:metricName:WebACL' :: WebACL -> 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 Maybe Text
webACLArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
webACLId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf WafAction
defaultAction
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [ActivatedRule]
rules