{-# 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.RulesSource
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.NetworkFirewall.Types.RulesSource where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.NetworkFirewall.Types.RulesSourceList
import Amazonka.NetworkFirewall.Types.StatefulRule
import Amazonka.NetworkFirewall.Types.StatelessRulesAndCustomActions
import qualified Amazonka.Prelude as Prelude

-- | The stateless or stateful rules definitions for use in a single rule
-- group. Each rule group requires a single @RulesSource@. You can use an
-- instance of this for either stateless rules or stateful rules.
--
-- /See:/ 'newRulesSource' smart constructor.
data RulesSource = RulesSource'
  { -- | Stateful inspection criteria for a domain list rule group.
    RulesSource -> Maybe RulesSourceList
rulesSourceList :: Prelude.Maybe RulesSourceList,
    -- | Stateful inspection criteria, provided in Suricata compatible intrusion
    -- prevention system (IPS) rules. Suricata is an open-source network IPS
    -- that includes a standard rule-based language for network traffic
    -- inspection.
    --
    -- These rules contain the inspection criteria and the action to take for
    -- traffic that matches the criteria, so this type of rule group doesn\'t
    -- have a separate action setting.
    RulesSource -> Maybe Text
rulesString :: Prelude.Maybe Prelude.Text,
    -- | An array of individual stateful rules inspection criteria to be used
    -- together in a stateful rule group. Use this option to specify simple
    -- Suricata rules with protocol, source and destination, ports, direction,
    -- and rule options. For information about the Suricata @Rules@ format, see
    -- <https://suricata.readthedocs.io/rules/intro.html# Rules Format>.
    RulesSource -> Maybe [StatefulRule]
statefulRules :: Prelude.Maybe [StatefulRule],
    -- | Stateless inspection criteria to be used in a stateless rule group.
    RulesSource -> Maybe StatelessRulesAndCustomActions
statelessRulesAndCustomActions :: Prelude.Maybe StatelessRulesAndCustomActions
  }
  deriving (RulesSource -> RulesSource -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RulesSource -> RulesSource -> Bool
$c/= :: RulesSource -> RulesSource -> Bool
== :: RulesSource -> RulesSource -> Bool
$c== :: RulesSource -> RulesSource -> Bool
Prelude.Eq, ReadPrec [RulesSource]
ReadPrec RulesSource
Int -> ReadS RulesSource
ReadS [RulesSource]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RulesSource]
$creadListPrec :: ReadPrec [RulesSource]
readPrec :: ReadPrec RulesSource
$creadPrec :: ReadPrec RulesSource
readList :: ReadS [RulesSource]
$creadList :: ReadS [RulesSource]
readsPrec :: Int -> ReadS RulesSource
$creadsPrec :: Int -> ReadS RulesSource
Prelude.Read, Int -> RulesSource -> ShowS
[RulesSource] -> ShowS
RulesSource -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RulesSource] -> ShowS
$cshowList :: [RulesSource] -> ShowS
show :: RulesSource -> String
$cshow :: RulesSource -> String
showsPrec :: Int -> RulesSource -> ShowS
$cshowsPrec :: Int -> RulesSource -> ShowS
Prelude.Show, forall x. Rep RulesSource x -> RulesSource
forall x. RulesSource -> Rep RulesSource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RulesSource x -> RulesSource
$cfrom :: forall x. RulesSource -> Rep RulesSource x
Prelude.Generic)

-- |
-- Create a value of 'RulesSource' 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:
--
-- 'rulesSourceList', 'rulesSource_rulesSourceList' - Stateful inspection criteria for a domain list rule group.
--
-- 'rulesString', 'rulesSource_rulesString' - Stateful inspection criteria, provided in Suricata compatible intrusion
-- prevention system (IPS) rules. Suricata is an open-source network IPS
-- that includes a standard rule-based language for network traffic
-- inspection.
--
-- These rules contain the inspection criteria and the action to take for
-- traffic that matches the criteria, so this type of rule group doesn\'t
-- have a separate action setting.
--
-- 'statefulRules', 'rulesSource_statefulRules' - An array of individual stateful rules inspection criteria to be used
-- together in a stateful rule group. Use this option to specify simple
-- Suricata rules with protocol, source and destination, ports, direction,
-- and rule options. For information about the Suricata @Rules@ format, see
-- <https://suricata.readthedocs.io/rules/intro.html# Rules Format>.
--
-- 'statelessRulesAndCustomActions', 'rulesSource_statelessRulesAndCustomActions' - Stateless inspection criteria to be used in a stateless rule group.
newRulesSource ::
  RulesSource
newRulesSource :: RulesSource
newRulesSource =
  RulesSource'
    { $sel:rulesSourceList:RulesSource' :: Maybe RulesSourceList
rulesSourceList = forall a. Maybe a
Prelude.Nothing,
      $sel:rulesString:RulesSource' :: Maybe Text
rulesString = forall a. Maybe a
Prelude.Nothing,
      $sel:statefulRules:RulesSource' :: Maybe [StatefulRule]
statefulRules = forall a. Maybe a
Prelude.Nothing,
      $sel:statelessRulesAndCustomActions:RulesSource' :: Maybe StatelessRulesAndCustomActions
statelessRulesAndCustomActions = forall a. Maybe a
Prelude.Nothing
    }

-- | Stateful inspection criteria for a domain list rule group.
rulesSource_rulesSourceList :: Lens.Lens' RulesSource (Prelude.Maybe RulesSourceList)
rulesSource_rulesSourceList :: Lens' RulesSource (Maybe RulesSourceList)
rulesSource_rulesSourceList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RulesSource' {Maybe RulesSourceList
rulesSourceList :: Maybe RulesSourceList
$sel:rulesSourceList:RulesSource' :: RulesSource -> Maybe RulesSourceList
rulesSourceList} -> Maybe RulesSourceList
rulesSourceList) (\s :: RulesSource
s@RulesSource' {} Maybe RulesSourceList
a -> RulesSource
s {$sel:rulesSourceList:RulesSource' :: Maybe RulesSourceList
rulesSourceList = Maybe RulesSourceList
a} :: RulesSource)

-- | Stateful inspection criteria, provided in Suricata compatible intrusion
-- prevention system (IPS) rules. Suricata is an open-source network IPS
-- that includes a standard rule-based language for network traffic
-- inspection.
--
-- These rules contain the inspection criteria and the action to take for
-- traffic that matches the criteria, so this type of rule group doesn\'t
-- have a separate action setting.
rulesSource_rulesString :: Lens.Lens' RulesSource (Prelude.Maybe Prelude.Text)
rulesSource_rulesString :: Lens' RulesSource (Maybe Text)
rulesSource_rulesString = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RulesSource' {Maybe Text
rulesString :: Maybe Text
$sel:rulesString:RulesSource' :: RulesSource -> Maybe Text
rulesString} -> Maybe Text
rulesString) (\s :: RulesSource
s@RulesSource' {} Maybe Text
a -> RulesSource
s {$sel:rulesString:RulesSource' :: Maybe Text
rulesString = Maybe Text
a} :: RulesSource)

-- | An array of individual stateful rules inspection criteria to be used
-- together in a stateful rule group. Use this option to specify simple
-- Suricata rules with protocol, source and destination, ports, direction,
-- and rule options. For information about the Suricata @Rules@ format, see
-- <https://suricata.readthedocs.io/rules/intro.html# Rules Format>.
rulesSource_statefulRules :: Lens.Lens' RulesSource (Prelude.Maybe [StatefulRule])
rulesSource_statefulRules :: Lens' RulesSource (Maybe [StatefulRule])
rulesSource_statefulRules = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RulesSource' {Maybe [StatefulRule]
statefulRules :: Maybe [StatefulRule]
$sel:statefulRules:RulesSource' :: RulesSource -> Maybe [StatefulRule]
statefulRules} -> Maybe [StatefulRule]
statefulRules) (\s :: RulesSource
s@RulesSource' {} Maybe [StatefulRule]
a -> RulesSource
s {$sel:statefulRules:RulesSource' :: Maybe [StatefulRule]
statefulRules = Maybe [StatefulRule]
a} :: RulesSource) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Stateless inspection criteria to be used in a stateless rule group.
rulesSource_statelessRulesAndCustomActions :: Lens.Lens' RulesSource (Prelude.Maybe StatelessRulesAndCustomActions)
rulesSource_statelessRulesAndCustomActions :: Lens' RulesSource (Maybe StatelessRulesAndCustomActions)
rulesSource_statelessRulesAndCustomActions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RulesSource' {Maybe StatelessRulesAndCustomActions
statelessRulesAndCustomActions :: Maybe StatelessRulesAndCustomActions
$sel:statelessRulesAndCustomActions:RulesSource' :: RulesSource -> Maybe StatelessRulesAndCustomActions
statelessRulesAndCustomActions} -> Maybe StatelessRulesAndCustomActions
statelessRulesAndCustomActions) (\s :: RulesSource
s@RulesSource' {} Maybe StatelessRulesAndCustomActions
a -> RulesSource
s {$sel:statelessRulesAndCustomActions:RulesSource' :: Maybe StatelessRulesAndCustomActions
statelessRulesAndCustomActions = Maybe StatelessRulesAndCustomActions
a} :: RulesSource)

instance Data.FromJSON RulesSource where
  parseJSON :: Value -> Parser RulesSource
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RulesSource"
      ( \Object
x ->
          Maybe RulesSourceList
-> Maybe Text
-> Maybe [StatefulRule]
-> Maybe StatelessRulesAndCustomActions
-> RulesSource
RulesSource'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"RulesSourceList")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"RulesString")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"StatefulRules" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"StatelessRulesAndCustomActions")
      )

instance Prelude.Hashable RulesSource where
  hashWithSalt :: Int -> RulesSource -> Int
hashWithSalt Int
_salt RulesSource' {Maybe [StatefulRule]
Maybe Text
Maybe StatelessRulesAndCustomActions
Maybe RulesSourceList
statelessRulesAndCustomActions :: Maybe StatelessRulesAndCustomActions
statefulRules :: Maybe [StatefulRule]
rulesString :: Maybe Text
rulesSourceList :: Maybe RulesSourceList
$sel:statelessRulesAndCustomActions:RulesSource' :: RulesSource -> Maybe StatelessRulesAndCustomActions
$sel:statefulRules:RulesSource' :: RulesSource -> Maybe [StatefulRule]
$sel:rulesString:RulesSource' :: RulesSource -> Maybe Text
$sel:rulesSourceList:RulesSource' :: RulesSource -> Maybe RulesSourceList
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe RulesSourceList
rulesSourceList
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
rulesString
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [StatefulRule]
statefulRules
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe StatelessRulesAndCustomActions
statelessRulesAndCustomActions

instance Prelude.NFData RulesSource where
  rnf :: RulesSource -> ()
rnf RulesSource' {Maybe [StatefulRule]
Maybe Text
Maybe StatelessRulesAndCustomActions
Maybe RulesSourceList
statelessRulesAndCustomActions :: Maybe StatelessRulesAndCustomActions
statefulRules :: Maybe [StatefulRule]
rulesString :: Maybe Text
rulesSourceList :: Maybe RulesSourceList
$sel:statelessRulesAndCustomActions:RulesSource' :: RulesSource -> Maybe StatelessRulesAndCustomActions
$sel:statefulRules:RulesSource' :: RulesSource -> Maybe [StatefulRule]
$sel:rulesString:RulesSource' :: RulesSource -> Maybe Text
$sel:rulesSourceList:RulesSource' :: RulesSource -> Maybe RulesSourceList
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe RulesSourceList
rulesSourceList
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
rulesString
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [StatefulRule]
statefulRules
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe StatelessRulesAndCustomActions
statelessRulesAndCustomActions

instance Data.ToJSON RulesSource where
  toJSON :: RulesSource -> Value
toJSON RulesSource' {Maybe [StatefulRule]
Maybe Text
Maybe StatelessRulesAndCustomActions
Maybe RulesSourceList
statelessRulesAndCustomActions :: Maybe StatelessRulesAndCustomActions
statefulRules :: Maybe [StatefulRule]
rulesString :: Maybe Text
rulesSourceList :: Maybe RulesSourceList
$sel:statelessRulesAndCustomActions:RulesSource' :: RulesSource -> Maybe StatelessRulesAndCustomActions
$sel:statefulRules:RulesSource' :: RulesSource -> Maybe [StatefulRule]
$sel:rulesString:RulesSource' :: RulesSource -> Maybe Text
$sel:rulesSourceList:RulesSource' :: RulesSource -> Maybe RulesSourceList
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"RulesSourceList" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe RulesSourceList
rulesSourceList,
            (Key
"RulesString" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
rulesString,
            (Key
"StatefulRules" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [StatefulRule]
statefulRules,
            (Key
"StatelessRulesAndCustomActions" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe StatelessRulesAndCustomActions
statelessRulesAndCustomActions
          ]
      )