{-# 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.SecurityHub.Types.WafAction
-- 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.SecurityHub.Types.WafAction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Details about the action that CloudFront or WAF takes when a web request
-- matches the conditions in the rule.
--
-- /See:/ 'newWafAction' smart constructor.
data WafAction = WafAction'
  { -- | Specifies how you want WAF to respond to requests that match the
    -- settings in a rule.
    --
    -- Valid settings include the following:
    --
    -- -   @ALLOW@ - WAF allows requests
    --
    -- -   @BLOCK@ - WAF blocks requests
    --
    -- -   @COUNT@ - WAF increments a counter of the requests that match all of
    --     the conditions in the rule. WAF then continues to inspect the web
    --     request based on the remaining rules in the web ACL. You can\'t
    --     specify @COUNT@ for the default action for a WebACL.
    WafAction -> Maybe Text
type' :: Prelude.Maybe Prelude.Text
  }
  deriving (WafAction -> WafAction -> Bool
(WafAction -> WafAction -> Bool)
-> (WafAction -> WafAction -> Bool) -> Eq WafAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WafAction -> WafAction -> Bool
$c/= :: WafAction -> WafAction -> Bool
== :: WafAction -> WafAction -> Bool
$c== :: WafAction -> WafAction -> Bool
Prelude.Eq, ReadPrec [WafAction]
ReadPrec WafAction
Int -> ReadS WafAction
ReadS [WafAction]
(Int -> ReadS WafAction)
-> ReadS [WafAction]
-> ReadPrec WafAction
-> ReadPrec [WafAction]
-> Read WafAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [WafAction]
$creadListPrec :: ReadPrec [WafAction]
readPrec :: ReadPrec WafAction
$creadPrec :: ReadPrec WafAction
readList :: ReadS [WafAction]
$creadList :: ReadS [WafAction]
readsPrec :: Int -> ReadS WafAction
$creadsPrec :: Int -> ReadS WafAction
Prelude.Read, Int -> WafAction -> ShowS
[WafAction] -> ShowS
WafAction -> String
(Int -> WafAction -> ShowS)
-> (WafAction -> String)
-> ([WafAction] -> ShowS)
-> Show WafAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WafAction] -> ShowS
$cshowList :: [WafAction] -> ShowS
show :: WafAction -> String
$cshow :: WafAction -> String
showsPrec :: Int -> WafAction -> ShowS
$cshowsPrec :: Int -> WafAction -> ShowS
Prelude.Show, (forall x. WafAction -> Rep WafAction x)
-> (forall x. Rep WafAction x -> WafAction) -> Generic WafAction
forall x. Rep WafAction x -> WafAction
forall x. WafAction -> Rep WafAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep WafAction x -> WafAction
$cfrom :: forall x. WafAction -> Rep WafAction x
Prelude.Generic)

-- |
-- Create a value of 'WafAction' 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:
--
-- 'type'', 'wafAction_type' - Specifies how you want WAF to respond to requests that match the
-- settings in a rule.
--
-- Valid settings include the following:
--
-- -   @ALLOW@ - WAF allows requests
--
-- -   @BLOCK@ - WAF blocks requests
--
-- -   @COUNT@ - WAF increments a counter of the requests that match all of
--     the conditions in the rule. WAF then continues to inspect the web
--     request based on the remaining rules in the web ACL. You can\'t
--     specify @COUNT@ for the default action for a WebACL.
newWafAction ::
  WafAction
newWafAction :: WafAction
newWafAction = WafAction' :: Maybe Text -> WafAction
WafAction' {$sel:type':WafAction' :: Maybe Text
type' = Maybe Text
forall a. Maybe a
Prelude.Nothing}

-- | Specifies how you want WAF to respond to requests that match the
-- settings in a rule.
--
-- Valid settings include the following:
--
-- -   @ALLOW@ - WAF allows requests
--
-- -   @BLOCK@ - WAF blocks requests
--
-- -   @COUNT@ - WAF increments a counter of the requests that match all of
--     the conditions in the rule. WAF then continues to inspect the web
--     request based on the remaining rules in the web ACL. You can\'t
--     specify @COUNT@ for the default action for a WebACL.
wafAction_type :: Lens.Lens' WafAction (Prelude.Maybe Prelude.Text)
wafAction_type :: (Maybe Text -> f (Maybe Text)) -> WafAction -> f WafAction
wafAction_type = (WafAction -> Maybe Text)
-> (WafAction -> Maybe Text -> WafAction)
-> Lens WafAction WafAction (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\WafAction' {Maybe Text
type' :: Maybe Text
$sel:type':WafAction' :: WafAction -> Maybe Text
type'} -> Maybe Text
type') (\s :: WafAction
s@WafAction' {} Maybe Text
a -> WafAction
s {$sel:type':WafAction' :: Maybe Text
type' = Maybe Text
a} :: WafAction)

instance Core.FromJSON WafAction where
  parseJSON :: Value -> Parser WafAction
parseJSON =
    String -> (Object -> Parser WafAction) -> Value -> Parser WafAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"WafAction"
      (\Object
x -> Maybe Text -> WafAction
WafAction' (Maybe Text -> WafAction)
-> Parser (Maybe Text) -> Parser WafAction
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
"Type"))

instance Prelude.Hashable WafAction

instance Prelude.NFData WafAction

instance Core.ToJSON WafAction where
  toJSON :: WafAction -> Value
toJSON WafAction' {Maybe Text
type' :: Maybe Text
$sel:type':WafAction' :: WafAction -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"Type" 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
type']
      )