{-# 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.NetworkFirewall.Types.CustomAction
-- 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.NetworkFirewall.Types.CustomAction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.NetworkFirewall.Types.ActionDefinition
import qualified Amazonka.Prelude as Prelude

-- | An optional, non-standard action to use for stateless packet handling.
-- You can define this in addition to the standard action that you must
-- specify.
--
-- You define and name the custom actions that you want to be able to use,
-- and then you reference them by name in your actions settings.
--
-- You can use custom actions in the following places:
--
-- -   In a rule group\'s StatelessRulesAndCustomActions specification. The
--     custom actions are available for use by name inside the
--     @StatelessRulesAndCustomActions@ where you define them. You can use
--     them for your stateless rule actions to specify what to do with a
--     packet that matches the rule\'s match attributes.
--
-- -   In a FirewallPolicy specification, in @StatelessCustomActions@. The
--     custom actions are available for use inside the policy where you
--     define them. You can use them for the policy\'s default stateless
--     actions settings to specify what to do with packets that don\'t
--     match any of the policy\'s stateless rules.
--
-- /See:/ 'newCustomAction' smart constructor.
data CustomAction = CustomAction'
  { -- | The descriptive name of the custom action. You can\'t change the name of
    -- a custom action after you create it.
    CustomAction -> Text
actionName :: Prelude.Text,
    -- | The custom action associated with the action name.
    CustomAction -> ActionDefinition
actionDefinition :: ActionDefinition
  }
  deriving (CustomAction -> CustomAction -> Bool
(CustomAction -> CustomAction -> Bool)
-> (CustomAction -> CustomAction -> Bool) -> Eq CustomAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomAction -> CustomAction -> Bool
$c/= :: CustomAction -> CustomAction -> Bool
== :: CustomAction -> CustomAction -> Bool
$c== :: CustomAction -> CustomAction -> Bool
Prelude.Eq, ReadPrec [CustomAction]
ReadPrec CustomAction
Int -> ReadS CustomAction
ReadS [CustomAction]
(Int -> ReadS CustomAction)
-> ReadS [CustomAction]
-> ReadPrec CustomAction
-> ReadPrec [CustomAction]
-> Read CustomAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CustomAction]
$creadListPrec :: ReadPrec [CustomAction]
readPrec :: ReadPrec CustomAction
$creadPrec :: ReadPrec CustomAction
readList :: ReadS [CustomAction]
$creadList :: ReadS [CustomAction]
readsPrec :: Int -> ReadS CustomAction
$creadsPrec :: Int -> ReadS CustomAction
Prelude.Read, Int -> CustomAction -> ShowS
[CustomAction] -> ShowS
CustomAction -> String
(Int -> CustomAction -> ShowS)
-> (CustomAction -> String)
-> ([CustomAction] -> ShowS)
-> Show CustomAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CustomAction] -> ShowS
$cshowList :: [CustomAction] -> ShowS
show :: CustomAction -> String
$cshow :: CustomAction -> String
showsPrec :: Int -> CustomAction -> ShowS
$cshowsPrec :: Int -> CustomAction -> ShowS
Prelude.Show, (forall x. CustomAction -> Rep CustomAction x)
-> (forall x. Rep CustomAction x -> CustomAction)
-> Generic CustomAction
forall x. Rep CustomAction x -> CustomAction
forall x. CustomAction -> Rep CustomAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CustomAction x -> CustomAction
$cfrom :: forall x. CustomAction -> Rep CustomAction x
Prelude.Generic)

-- |
-- Create a value of 'CustomAction' 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:
--
-- 'actionName', 'customAction_actionName' - The descriptive name of the custom action. You can\'t change the name of
-- a custom action after you create it.
--
-- 'actionDefinition', 'customAction_actionDefinition' - The custom action associated with the action name.
newCustomAction ::
  -- | 'actionName'
  Prelude.Text ->
  -- | 'actionDefinition'
  ActionDefinition ->
  CustomAction
newCustomAction :: Text -> ActionDefinition -> CustomAction
newCustomAction Text
pActionName_ ActionDefinition
pActionDefinition_ =
  CustomAction' :: Text -> ActionDefinition -> CustomAction
CustomAction'
    { $sel:actionName:CustomAction' :: Text
actionName = Text
pActionName_,
      $sel:actionDefinition:CustomAction' :: ActionDefinition
actionDefinition = ActionDefinition
pActionDefinition_
    }

-- | The descriptive name of the custom action. You can\'t change the name of
-- a custom action after you create it.
customAction_actionName :: Lens.Lens' CustomAction Prelude.Text
customAction_actionName :: (Text -> f Text) -> CustomAction -> f CustomAction
customAction_actionName = (CustomAction -> Text)
-> (CustomAction -> Text -> CustomAction)
-> Lens CustomAction CustomAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomAction' {Text
actionName :: Text
$sel:actionName:CustomAction' :: CustomAction -> Text
actionName} -> Text
actionName) (\s :: CustomAction
s@CustomAction' {} Text
a -> CustomAction
s {$sel:actionName:CustomAction' :: Text
actionName = Text
a} :: CustomAction)

-- | The custom action associated with the action name.
customAction_actionDefinition :: Lens.Lens' CustomAction ActionDefinition
customAction_actionDefinition :: (ActionDefinition -> f ActionDefinition)
-> CustomAction -> f CustomAction
customAction_actionDefinition = (CustomAction -> ActionDefinition)
-> (CustomAction -> ActionDefinition -> CustomAction)
-> Lens CustomAction CustomAction ActionDefinition ActionDefinition
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomAction' {ActionDefinition
actionDefinition :: ActionDefinition
$sel:actionDefinition:CustomAction' :: CustomAction -> ActionDefinition
actionDefinition} -> ActionDefinition
actionDefinition) (\s :: CustomAction
s@CustomAction' {} ActionDefinition
a -> CustomAction
s {$sel:actionDefinition:CustomAction' :: ActionDefinition
actionDefinition = ActionDefinition
a} :: CustomAction)

instance Core.FromJSON CustomAction where
  parseJSON :: Value -> Parser CustomAction
parseJSON =
    String
-> (Object -> Parser CustomAction) -> Value -> Parser CustomAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CustomAction"
      ( \Object
x ->
          Text -> ActionDefinition -> CustomAction
CustomAction'
            (Text -> ActionDefinition -> CustomAction)
-> Parser Text -> Parser (ActionDefinition -> CustomAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ActionName")
            Parser (ActionDefinition -> CustomAction)
-> Parser ActionDefinition -> Parser CustomAction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ActionDefinition
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ActionDefinition")
      )

instance Prelude.Hashable CustomAction

instance Prelude.NFData CustomAction

instance Core.ToJSON CustomAction where
  toJSON :: CustomAction -> Value
toJSON CustomAction' {Text
ActionDefinition
actionDefinition :: ActionDefinition
actionName :: Text
$sel:actionDefinition:CustomAction' :: CustomAction -> ActionDefinition
$sel:actionName:CustomAction' :: CustomAction -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ActionName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
actionName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ActionDefinition" Text -> ActionDefinition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ActionDefinition
actionDefinition)
          ]
      )