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

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

-- | A custom action to use in stateless rule actions settings. This is used
-- in CustomAction.
--
-- /See:/ 'newActionDefinition' smart constructor.
data ActionDefinition = ActionDefinition'
  { -- | Stateless inspection criteria that publishes the specified metrics to
    -- Amazon CloudWatch for the matching packet. This setting defines a
    -- CloudWatch dimension value to be published.
    --
    -- You can pair this custom action with any of the standard stateless rule
    -- actions. For example, you could pair this in a rule action with the
    -- standard action that forwards the packet for stateful inspection. Then,
    -- when a packet matches the rule, Network Firewall publishes metrics for
    -- the packet and forwards it.
    ActionDefinition -> Maybe PublishMetricAction
publishMetricAction :: Prelude.Maybe PublishMetricAction
  }
  deriving (ActionDefinition -> ActionDefinition -> Bool
(ActionDefinition -> ActionDefinition -> Bool)
-> (ActionDefinition -> ActionDefinition -> Bool)
-> Eq ActionDefinition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ActionDefinition -> ActionDefinition -> Bool
$c/= :: ActionDefinition -> ActionDefinition -> Bool
== :: ActionDefinition -> ActionDefinition -> Bool
$c== :: ActionDefinition -> ActionDefinition -> Bool
Prelude.Eq, ReadPrec [ActionDefinition]
ReadPrec ActionDefinition
Int -> ReadS ActionDefinition
ReadS [ActionDefinition]
(Int -> ReadS ActionDefinition)
-> ReadS [ActionDefinition]
-> ReadPrec ActionDefinition
-> ReadPrec [ActionDefinition]
-> Read ActionDefinition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ActionDefinition]
$creadListPrec :: ReadPrec [ActionDefinition]
readPrec :: ReadPrec ActionDefinition
$creadPrec :: ReadPrec ActionDefinition
readList :: ReadS [ActionDefinition]
$creadList :: ReadS [ActionDefinition]
readsPrec :: Int -> ReadS ActionDefinition
$creadsPrec :: Int -> ReadS ActionDefinition
Prelude.Read, Int -> ActionDefinition -> ShowS
[ActionDefinition] -> ShowS
ActionDefinition -> String
(Int -> ActionDefinition -> ShowS)
-> (ActionDefinition -> String)
-> ([ActionDefinition] -> ShowS)
-> Show ActionDefinition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ActionDefinition] -> ShowS
$cshowList :: [ActionDefinition] -> ShowS
show :: ActionDefinition -> String
$cshow :: ActionDefinition -> String
showsPrec :: Int -> ActionDefinition -> ShowS
$cshowsPrec :: Int -> ActionDefinition -> ShowS
Prelude.Show, (forall x. ActionDefinition -> Rep ActionDefinition x)
-> (forall x. Rep ActionDefinition x -> ActionDefinition)
-> Generic ActionDefinition
forall x. Rep ActionDefinition x -> ActionDefinition
forall x. ActionDefinition -> Rep ActionDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ActionDefinition x -> ActionDefinition
$cfrom :: forall x. ActionDefinition -> Rep ActionDefinition x
Prelude.Generic)

-- |
-- Create a value of 'ActionDefinition' 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:
--
-- 'publishMetricAction', 'actionDefinition_publishMetricAction' - Stateless inspection criteria that publishes the specified metrics to
-- Amazon CloudWatch for the matching packet. This setting defines a
-- CloudWatch dimension value to be published.
--
-- You can pair this custom action with any of the standard stateless rule
-- actions. For example, you could pair this in a rule action with the
-- standard action that forwards the packet for stateful inspection. Then,
-- when a packet matches the rule, Network Firewall publishes metrics for
-- the packet and forwards it.
newActionDefinition ::
  ActionDefinition
newActionDefinition :: ActionDefinition
newActionDefinition =
  ActionDefinition' :: Maybe PublishMetricAction -> ActionDefinition
ActionDefinition'
    { $sel:publishMetricAction:ActionDefinition' :: Maybe PublishMetricAction
publishMetricAction =
        Maybe PublishMetricAction
forall a. Maybe a
Prelude.Nothing
    }

-- | Stateless inspection criteria that publishes the specified metrics to
-- Amazon CloudWatch for the matching packet. This setting defines a
-- CloudWatch dimension value to be published.
--
-- You can pair this custom action with any of the standard stateless rule
-- actions. For example, you could pair this in a rule action with the
-- standard action that forwards the packet for stateful inspection. Then,
-- when a packet matches the rule, Network Firewall publishes metrics for
-- the packet and forwards it.
actionDefinition_publishMetricAction :: Lens.Lens' ActionDefinition (Prelude.Maybe PublishMetricAction)
actionDefinition_publishMetricAction :: (Maybe PublishMetricAction -> f (Maybe PublishMetricAction))
-> ActionDefinition -> f ActionDefinition
actionDefinition_publishMetricAction = (ActionDefinition -> Maybe PublishMetricAction)
-> (ActionDefinition
    -> Maybe PublishMetricAction -> ActionDefinition)
-> Lens
     ActionDefinition
     ActionDefinition
     (Maybe PublishMetricAction)
     (Maybe PublishMetricAction)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ActionDefinition' {Maybe PublishMetricAction
publishMetricAction :: Maybe PublishMetricAction
$sel:publishMetricAction:ActionDefinition' :: ActionDefinition -> Maybe PublishMetricAction
publishMetricAction} -> Maybe PublishMetricAction
publishMetricAction) (\s :: ActionDefinition
s@ActionDefinition' {} Maybe PublishMetricAction
a -> ActionDefinition
s {$sel:publishMetricAction:ActionDefinition' :: Maybe PublishMetricAction
publishMetricAction = Maybe PublishMetricAction
a} :: ActionDefinition)

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

instance Prelude.Hashable ActionDefinition

instance Prelude.NFData ActionDefinition

instance Core.ToJSON ActionDefinition where
  toJSON :: ActionDefinition -> Value
toJSON ActionDefinition' {Maybe PublishMetricAction
publishMetricAction :: Maybe PublishMetricAction
$sel:publishMetricAction:ActionDefinition' :: ActionDefinition -> Maybe PublishMetricAction
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"PublishMetricAction" Text -> PublishMetricAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (PublishMetricAction -> Pair)
-> Maybe PublishMetricAction -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe PublishMetricAction
publishMetricAction
          ]
      )