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

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

-- | A single stateless rule. This is used in StatelessRulesAndCustomActions.
--
-- /See:/ 'newStatelessRule' smart constructor.
data StatelessRule = StatelessRule'
  { -- | Defines the stateless 5-tuple packet inspection criteria and the action
    -- to take on a packet that matches the criteria.
    StatelessRule -> RuleDefinition
ruleDefinition :: RuleDefinition,
    -- | Indicates the order in which to run this rule relative to all of the
    -- rules that are defined for a stateless rule group. Network Firewall
    -- evaluates the rules in a rule group starting with the lowest priority
    -- setting. You must ensure that the priority settings are unique for the
    -- rule group.
    --
    -- Each stateless rule group uses exactly one
    -- @StatelessRulesAndCustomActions@ object, and each
    -- @StatelessRulesAndCustomActions@ contains exactly one @StatelessRules@
    -- object. To ensure unique priority settings for your rule groups, set
    -- unique priorities for the stateless rules that you define inside any
    -- single @StatelessRules@ object.
    --
    -- You can change the priority settings of your rules at any time. To make
    -- it easier to insert rules later, number them so there\'s a wide range in
    -- between, for example use 100, 200, and so on.
    StatelessRule -> Natural
priority :: Prelude.Natural
  }
  deriving (StatelessRule -> StatelessRule -> Bool
(StatelessRule -> StatelessRule -> Bool)
-> (StatelessRule -> StatelessRule -> Bool) -> Eq StatelessRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StatelessRule -> StatelessRule -> Bool
$c/= :: StatelessRule -> StatelessRule -> Bool
== :: StatelessRule -> StatelessRule -> Bool
$c== :: StatelessRule -> StatelessRule -> Bool
Prelude.Eq, ReadPrec [StatelessRule]
ReadPrec StatelessRule
Int -> ReadS StatelessRule
ReadS [StatelessRule]
(Int -> ReadS StatelessRule)
-> ReadS [StatelessRule]
-> ReadPrec StatelessRule
-> ReadPrec [StatelessRule]
-> Read StatelessRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StatelessRule]
$creadListPrec :: ReadPrec [StatelessRule]
readPrec :: ReadPrec StatelessRule
$creadPrec :: ReadPrec StatelessRule
readList :: ReadS [StatelessRule]
$creadList :: ReadS [StatelessRule]
readsPrec :: Int -> ReadS StatelessRule
$creadsPrec :: Int -> ReadS StatelessRule
Prelude.Read, Int -> StatelessRule -> ShowS
[StatelessRule] -> ShowS
StatelessRule -> String
(Int -> StatelessRule -> ShowS)
-> (StatelessRule -> String)
-> ([StatelessRule] -> ShowS)
-> Show StatelessRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StatelessRule] -> ShowS
$cshowList :: [StatelessRule] -> ShowS
show :: StatelessRule -> String
$cshow :: StatelessRule -> String
showsPrec :: Int -> StatelessRule -> ShowS
$cshowsPrec :: Int -> StatelessRule -> ShowS
Prelude.Show, (forall x. StatelessRule -> Rep StatelessRule x)
-> (forall x. Rep StatelessRule x -> StatelessRule)
-> Generic StatelessRule
forall x. Rep StatelessRule x -> StatelessRule
forall x. StatelessRule -> Rep StatelessRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StatelessRule x -> StatelessRule
$cfrom :: forall x. StatelessRule -> Rep StatelessRule x
Prelude.Generic)

-- |
-- Create a value of 'StatelessRule' 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:
--
-- 'ruleDefinition', 'statelessRule_ruleDefinition' - Defines the stateless 5-tuple packet inspection criteria and the action
-- to take on a packet that matches the criteria.
--
-- 'priority', 'statelessRule_priority' - Indicates the order in which to run this rule relative to all of the
-- rules that are defined for a stateless rule group. Network Firewall
-- evaluates the rules in a rule group starting with the lowest priority
-- setting. You must ensure that the priority settings are unique for the
-- rule group.
--
-- Each stateless rule group uses exactly one
-- @StatelessRulesAndCustomActions@ object, and each
-- @StatelessRulesAndCustomActions@ contains exactly one @StatelessRules@
-- object. To ensure unique priority settings for your rule groups, set
-- unique priorities for the stateless rules that you define inside any
-- single @StatelessRules@ object.
--
-- You can change the priority settings of your rules at any time. To make
-- it easier to insert rules later, number them so there\'s a wide range in
-- between, for example use 100, 200, and so on.
newStatelessRule ::
  -- | 'ruleDefinition'
  RuleDefinition ->
  -- | 'priority'
  Prelude.Natural ->
  StatelessRule
newStatelessRule :: RuleDefinition -> Natural -> StatelessRule
newStatelessRule RuleDefinition
pRuleDefinition_ Natural
pPriority_ =
  StatelessRule' :: RuleDefinition -> Natural -> StatelessRule
StatelessRule'
    { $sel:ruleDefinition:StatelessRule' :: RuleDefinition
ruleDefinition = RuleDefinition
pRuleDefinition_,
      $sel:priority:StatelessRule' :: Natural
priority = Natural
pPriority_
    }

-- | Defines the stateless 5-tuple packet inspection criteria and the action
-- to take on a packet that matches the criteria.
statelessRule_ruleDefinition :: Lens.Lens' StatelessRule RuleDefinition
statelessRule_ruleDefinition :: (RuleDefinition -> f RuleDefinition)
-> StatelessRule -> f StatelessRule
statelessRule_ruleDefinition = (StatelessRule -> RuleDefinition)
-> (StatelessRule -> RuleDefinition -> StatelessRule)
-> Lens StatelessRule StatelessRule RuleDefinition RuleDefinition
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StatelessRule' {RuleDefinition
ruleDefinition :: RuleDefinition
$sel:ruleDefinition:StatelessRule' :: StatelessRule -> RuleDefinition
ruleDefinition} -> RuleDefinition
ruleDefinition) (\s :: StatelessRule
s@StatelessRule' {} RuleDefinition
a -> StatelessRule
s {$sel:ruleDefinition:StatelessRule' :: RuleDefinition
ruleDefinition = RuleDefinition
a} :: StatelessRule)

-- | Indicates the order in which to run this rule relative to all of the
-- rules that are defined for a stateless rule group. Network Firewall
-- evaluates the rules in a rule group starting with the lowest priority
-- setting. You must ensure that the priority settings are unique for the
-- rule group.
--
-- Each stateless rule group uses exactly one
-- @StatelessRulesAndCustomActions@ object, and each
-- @StatelessRulesAndCustomActions@ contains exactly one @StatelessRules@
-- object. To ensure unique priority settings for your rule groups, set
-- unique priorities for the stateless rules that you define inside any
-- single @StatelessRules@ object.
--
-- You can change the priority settings of your rules at any time. To make
-- it easier to insert rules later, number them so there\'s a wide range in
-- between, for example use 100, 200, and so on.
statelessRule_priority :: Lens.Lens' StatelessRule Prelude.Natural
statelessRule_priority :: (Natural -> f Natural) -> StatelessRule -> f StatelessRule
statelessRule_priority = (StatelessRule -> Natural)
-> (StatelessRule -> Natural -> StatelessRule)
-> Lens StatelessRule StatelessRule Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StatelessRule' {Natural
priority :: Natural
$sel:priority:StatelessRule' :: StatelessRule -> Natural
priority} -> Natural
priority) (\s :: StatelessRule
s@StatelessRule' {} Natural
a -> StatelessRule
s {$sel:priority:StatelessRule' :: Natural
priority = Natural
a} :: StatelessRule)

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

instance Prelude.Hashable StatelessRule

instance Prelude.NFData StatelessRule

instance Core.ToJSON StatelessRule where
  toJSON :: StatelessRule -> Value
toJSON StatelessRule' {Natural
RuleDefinition
priority :: Natural
ruleDefinition :: RuleDefinition
$sel:priority:StatelessRule' :: StatelessRule -> Natural
$sel:ruleDefinition:StatelessRule' :: StatelessRule -> RuleDefinition
..} =
    [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
"RuleDefinition" Text -> RuleDefinition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= RuleDefinition
ruleDefinition),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Priority" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
priority)
          ]
      )