{-# 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-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.WebACL where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(WebACL -> WebACL -> Bool)
-> (WebACL -> WebACL -> Bool) -> Eq WebACL
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]
(Int -> ReadS WebACL)
-> ReadS [WebACL]
-> ReadPrec WebACL
-> ReadPrec [WebACL]
-> Read 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
(Int -> WebACL -> ShowS)
-> (WebACL -> String) -> ([WebACL] -> ShowS) -> Show WebACL
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. WebACL -> Rep WebACL x)
-> (forall x. Rep WebACL x -> WebACL) -> Generic WebACL
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' :: Maybe Text
-> Maybe Text
-> Maybe Text
-> Text
-> WafAction
-> [ActivatedRule]
-> WebACL
WebACL'
    { $sel:metricName:WebACL' :: Maybe Text
metricName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:WebACL' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:webACLArn:WebACL' :: Maybe Text
webACLArn = Maybe Text
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 = [ActivatedRule]
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 :: (Maybe Text -> f (Maybe Text)) -> WebACL -> f WebACL
webACL_metricName = (WebACL -> Maybe Text)
-> (WebACL -> Maybe Text -> WebACL)
-> Lens WebACL WebACL (Maybe Text) (Maybe Text)
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 :: (Maybe Text -> f (Maybe Text)) -> WebACL -> f WebACL
webACL_name = (WebACL -> Maybe Text)
-> (WebACL -> Maybe Text -> WebACL)
-> Lens WebACL WebACL (Maybe Text) (Maybe Text)
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 :: (Maybe Text -> f (Maybe Text)) -> WebACL -> f WebACL
webACL_webACLArn = (WebACL -> Maybe Text)
-> (WebACL -> Maybe Text -> WebACL)
-> Lens WebACL WebACL (Maybe Text) (Maybe Text)
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 :: (Text -> f Text) -> WebACL -> f WebACL
webACL_webACLId = (WebACL -> Text)
-> (WebACL -> Text -> WebACL) -> Lens WebACL WebACL Text Text
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 :: (WafAction -> f WafAction) -> WebACL -> f WebACL
webACL_defaultAction = (WebACL -> WafAction)
-> (WebACL -> WafAction -> WebACL)
-> Lens WebACL WebACL WafAction WafAction
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 :: ([ActivatedRule] -> f [ActivatedRule]) -> WebACL -> f WebACL
webACL_rules = (WebACL -> [ActivatedRule])
-> (WebACL -> [ActivatedRule] -> WebACL)
-> Lens WebACL WebACL [ActivatedRule] [ActivatedRule]
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) (([ActivatedRule] -> f [ActivatedRule]) -> WebACL -> f WebACL)
-> (([ActivatedRule] -> f [ActivatedRule])
    -> [ActivatedRule] -> f [ActivatedRule])
-> ([ActivatedRule] -> f [ActivatedRule])
-> WebACL
-> f WebACL
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([ActivatedRule] -> f [ActivatedRule])
-> [ActivatedRule] -> f [ActivatedRule]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON WebACL where
  parseJSON :: Value -> Parser WebACL
parseJSON =
    String -> (Object -> Parser WebACL) -> Value -> Parser WebACL
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"WebACL"
      ( \Object
x ->
          Maybe Text
-> Maybe Text
-> Maybe Text
-> Text
-> WafAction
-> [ActivatedRule]
-> WebACL
WebACL'
            (Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Text
 -> WafAction
 -> [ActivatedRule]
 -> WebACL)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe Text -> Text -> WafAction -> [ActivatedRule] -> WebACL)
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
   -> Maybe Text -> Text -> WafAction -> [ActivatedRule] -> WebACL)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text -> Text -> WafAction -> [ActivatedRule] -> WebACL)
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
  (Maybe Text -> Text -> WafAction -> [ActivatedRule] -> WebACL)
-> Parser (Maybe Text)
-> Parser (Text -> WafAction -> [ActivatedRule] -> WebACL)
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
"WebACLArn")
            Parser (Text -> WafAction -> [ActivatedRule] -> WebACL)
-> Parser Text -> Parser (WafAction -> [ActivatedRule] -> WebACL)
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
"WebACLId")
            Parser (WafAction -> [ActivatedRule] -> WebACL)
-> Parser WafAction -> Parser ([ActivatedRule] -> WebACL)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser WafAction
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"DefaultAction")
            Parser ([ActivatedRule] -> WebACL)
-> Parser [ActivatedRule] -> Parser WebACL
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [ActivatedRule])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Rules" Parser (Maybe [ActivatedRule])
-> [ActivatedRule] -> Parser [ActivatedRule]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [ActivatedRule]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable WebACL

instance Prelude.NFData WebACL