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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.NetworkFirewall.Types.RuleVariables
import Amazonka.NetworkFirewall.Types.RulesSource
import Amazonka.NetworkFirewall.Types.StatefulRuleOptions
import qualified Amazonka.Prelude as Prelude

-- | The object that defines the rules in a rule group. This, along with
-- RuleGroupResponse, define the rule group. You can retrieve all objects
-- for a rule group by calling DescribeRuleGroup.
--
-- AWS Network Firewall uses a rule group to inspect and control network
-- traffic. You define stateless rule groups to inspect individual packets
-- and you define stateful rule groups to inspect packets in the context of
-- their traffic flow.
--
-- To use a rule group, you include it by reference in an Network Firewall
-- firewall policy, then you use the policy in a firewall. You can
-- reference a rule group from more than one firewall policy, and you can
-- use a firewall policy in more than one firewall.
--
-- /See:/ 'newRuleGroup' smart constructor.
data RuleGroup = RuleGroup'
  { -- | Additional options governing how Network Firewall handles stateful
    -- rules. The policies where you use your stateful rule group must have
    -- stateful rule options settings that are compatible with these settings.
    RuleGroup -> Maybe StatefulRuleOptions
statefulRuleOptions :: Prelude.Maybe StatefulRuleOptions,
    -- | Settings that are available for use in the rules in the rule group. You
    -- can only use these for stateful rule groups.
    RuleGroup -> Maybe RuleVariables
ruleVariables :: Prelude.Maybe RuleVariables,
    -- | The stateful rules or stateless rules for the rule group.
    RuleGroup -> RulesSource
rulesSource :: RulesSource
  }
  deriving (RuleGroup -> RuleGroup -> Bool
(RuleGroup -> RuleGroup -> Bool)
-> (RuleGroup -> RuleGroup -> Bool) -> Eq RuleGroup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RuleGroup -> RuleGroup -> Bool
$c/= :: RuleGroup -> RuleGroup -> Bool
== :: RuleGroup -> RuleGroup -> Bool
$c== :: RuleGroup -> RuleGroup -> Bool
Prelude.Eq, ReadPrec [RuleGroup]
ReadPrec RuleGroup
Int -> ReadS RuleGroup
ReadS [RuleGroup]
(Int -> ReadS RuleGroup)
-> ReadS [RuleGroup]
-> ReadPrec RuleGroup
-> ReadPrec [RuleGroup]
-> Read RuleGroup
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RuleGroup]
$creadListPrec :: ReadPrec [RuleGroup]
readPrec :: ReadPrec RuleGroup
$creadPrec :: ReadPrec RuleGroup
readList :: ReadS [RuleGroup]
$creadList :: ReadS [RuleGroup]
readsPrec :: Int -> ReadS RuleGroup
$creadsPrec :: Int -> ReadS RuleGroup
Prelude.Read, Int -> RuleGroup -> ShowS
[RuleGroup] -> ShowS
RuleGroup -> String
(Int -> RuleGroup -> ShowS)
-> (RuleGroup -> String)
-> ([RuleGroup] -> ShowS)
-> Show RuleGroup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RuleGroup] -> ShowS
$cshowList :: [RuleGroup] -> ShowS
show :: RuleGroup -> String
$cshow :: RuleGroup -> String
showsPrec :: Int -> RuleGroup -> ShowS
$cshowsPrec :: Int -> RuleGroup -> ShowS
Prelude.Show, (forall x. RuleGroup -> Rep RuleGroup x)
-> (forall x. Rep RuleGroup x -> RuleGroup) -> Generic RuleGroup
forall x. Rep RuleGroup x -> RuleGroup
forall x. RuleGroup -> Rep RuleGroup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RuleGroup x -> RuleGroup
$cfrom :: forall x. RuleGroup -> Rep RuleGroup x
Prelude.Generic)

-- |
-- Create a value of 'RuleGroup' 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:
--
-- 'statefulRuleOptions', 'ruleGroup_statefulRuleOptions' - Additional options governing how Network Firewall handles stateful
-- rules. The policies where you use your stateful rule group must have
-- stateful rule options settings that are compatible with these settings.
--
-- 'ruleVariables', 'ruleGroup_ruleVariables' - Settings that are available for use in the rules in the rule group. You
-- can only use these for stateful rule groups.
--
-- 'rulesSource', 'ruleGroup_rulesSource' - The stateful rules or stateless rules for the rule group.
newRuleGroup ::
  -- | 'rulesSource'
  RulesSource ->
  RuleGroup
newRuleGroup :: RulesSource -> RuleGroup
newRuleGroup RulesSource
pRulesSource_ =
  RuleGroup' :: Maybe StatefulRuleOptions
-> Maybe RuleVariables -> RulesSource -> RuleGroup
RuleGroup'
    { $sel:statefulRuleOptions:RuleGroup' :: Maybe StatefulRuleOptions
statefulRuleOptions = Maybe StatefulRuleOptions
forall a. Maybe a
Prelude.Nothing,
      $sel:ruleVariables:RuleGroup' :: Maybe RuleVariables
ruleVariables = Maybe RuleVariables
forall a. Maybe a
Prelude.Nothing,
      $sel:rulesSource:RuleGroup' :: RulesSource
rulesSource = RulesSource
pRulesSource_
    }

-- | Additional options governing how Network Firewall handles stateful
-- rules. The policies where you use your stateful rule group must have
-- stateful rule options settings that are compatible with these settings.
ruleGroup_statefulRuleOptions :: Lens.Lens' RuleGroup (Prelude.Maybe StatefulRuleOptions)
ruleGroup_statefulRuleOptions :: (Maybe StatefulRuleOptions -> f (Maybe StatefulRuleOptions))
-> RuleGroup -> f RuleGroup
ruleGroup_statefulRuleOptions = (RuleGroup -> Maybe StatefulRuleOptions)
-> (RuleGroup -> Maybe StatefulRuleOptions -> RuleGroup)
-> Lens
     RuleGroup
     RuleGroup
     (Maybe StatefulRuleOptions)
     (Maybe StatefulRuleOptions)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleGroup' {Maybe StatefulRuleOptions
statefulRuleOptions :: Maybe StatefulRuleOptions
$sel:statefulRuleOptions:RuleGroup' :: RuleGroup -> Maybe StatefulRuleOptions
statefulRuleOptions} -> Maybe StatefulRuleOptions
statefulRuleOptions) (\s :: RuleGroup
s@RuleGroup' {} Maybe StatefulRuleOptions
a -> RuleGroup
s {$sel:statefulRuleOptions:RuleGroup' :: Maybe StatefulRuleOptions
statefulRuleOptions = Maybe StatefulRuleOptions
a} :: RuleGroup)

-- | Settings that are available for use in the rules in the rule group. You
-- can only use these for stateful rule groups.
ruleGroup_ruleVariables :: Lens.Lens' RuleGroup (Prelude.Maybe RuleVariables)
ruleGroup_ruleVariables :: (Maybe RuleVariables -> f (Maybe RuleVariables))
-> RuleGroup -> f RuleGroup
ruleGroup_ruleVariables = (RuleGroup -> Maybe RuleVariables)
-> (RuleGroup -> Maybe RuleVariables -> RuleGroup)
-> Lens
     RuleGroup RuleGroup (Maybe RuleVariables) (Maybe RuleVariables)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleGroup' {Maybe RuleVariables
ruleVariables :: Maybe RuleVariables
$sel:ruleVariables:RuleGroup' :: RuleGroup -> Maybe RuleVariables
ruleVariables} -> Maybe RuleVariables
ruleVariables) (\s :: RuleGroup
s@RuleGroup' {} Maybe RuleVariables
a -> RuleGroup
s {$sel:ruleVariables:RuleGroup' :: Maybe RuleVariables
ruleVariables = Maybe RuleVariables
a} :: RuleGroup)

-- | The stateful rules or stateless rules for the rule group.
ruleGroup_rulesSource :: Lens.Lens' RuleGroup RulesSource
ruleGroup_rulesSource :: (RulesSource -> f RulesSource) -> RuleGroup -> f RuleGroup
ruleGroup_rulesSource = (RuleGroup -> RulesSource)
-> (RuleGroup -> RulesSource -> RuleGroup)
-> Lens RuleGroup RuleGroup RulesSource RulesSource
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleGroup' {RulesSource
rulesSource :: RulesSource
$sel:rulesSource:RuleGroup' :: RuleGroup -> RulesSource
rulesSource} -> RulesSource
rulesSource) (\s :: RuleGroup
s@RuleGroup' {} RulesSource
a -> RuleGroup
s {$sel:rulesSource:RuleGroup' :: RulesSource
rulesSource = RulesSource
a} :: RuleGroup)

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

instance Prelude.Hashable RuleGroup

instance Prelude.NFData RuleGroup

instance Core.ToJSON RuleGroup where
  toJSON :: RuleGroup -> Value
toJSON RuleGroup' {Maybe RuleVariables
Maybe StatefulRuleOptions
RulesSource
rulesSource :: RulesSource
ruleVariables :: Maybe RuleVariables
statefulRuleOptions :: Maybe StatefulRuleOptions
$sel:rulesSource:RuleGroup' :: RuleGroup -> RulesSource
$sel:ruleVariables:RuleGroup' :: RuleGroup -> Maybe RuleVariables
$sel:statefulRuleOptions:RuleGroup' :: RuleGroup -> Maybe StatefulRuleOptions
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"StatefulRuleOptions" Text -> StatefulRuleOptions -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (StatefulRuleOptions -> Pair)
-> Maybe StatefulRuleOptions -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe StatefulRuleOptions
statefulRuleOptions,
            (Text
"RuleVariables" Text -> RuleVariables -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (RuleVariables -> Pair) -> Maybe RuleVariables -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe RuleVariables
ruleVariables,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"RulesSource" Text -> RulesSource -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= RulesSource
rulesSource)
          ]
      )