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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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, 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,
    -- | Stateful inspection criteria for a domain list rule group.
    RulesSource -> Maybe RulesSourceList
rulesSourceList :: Prelude.Maybe RulesSourceList,
    -- | 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/en/suricata-5.0.0/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
(RulesSource -> RulesSource -> Bool)
-> (RulesSource -> RulesSource -> Bool) -> Eq RulesSource
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]
(Int -> ReadS RulesSource)
-> ReadS [RulesSource]
-> ReadPrec RulesSource
-> ReadPrec [RulesSource]
-> Read 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
(Int -> RulesSource -> ShowS)
-> (RulesSource -> String)
-> ([RulesSource] -> ShowS)
-> Show RulesSource
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. RulesSource -> Rep RulesSource x)
-> (forall x. Rep RulesSource x -> RulesSource)
-> Generic RulesSource
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:
--
-- '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.
--
-- 'rulesSourceList', 'rulesSource_rulesSourceList' - Stateful inspection criteria for a domain list rule group.
--
-- '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/en/suricata-5.0.0/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' :: Maybe Text
-> Maybe RulesSourceList
-> Maybe [StatefulRule]
-> Maybe StatelessRulesAndCustomActions
-> RulesSource
RulesSource'
    { $sel:rulesString:RulesSource' :: Maybe Text
rulesString = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:rulesSourceList:RulesSource' :: Maybe RulesSourceList
rulesSourceList = Maybe RulesSourceList
forall a. Maybe a
Prelude.Nothing,
      $sel:statefulRules:RulesSource' :: Maybe [StatefulRule]
statefulRules = Maybe [StatefulRule]
forall a. Maybe a
Prelude.Nothing,
      $sel:statelessRulesAndCustomActions:RulesSource' :: Maybe StatelessRulesAndCustomActions
statelessRulesAndCustomActions = Maybe StatelessRulesAndCustomActions
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe Text -> f (Maybe Text)) -> RulesSource -> f RulesSource
rulesSource_rulesString = (RulesSource -> Maybe Text)
-> (RulesSource -> Maybe Text -> RulesSource)
-> Lens RulesSource RulesSource (Maybe Text) (Maybe Text)
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)

-- | Stateful inspection criteria for a domain list rule group.
rulesSource_rulesSourceList :: Lens.Lens' RulesSource (Prelude.Maybe RulesSourceList)
rulesSource_rulesSourceList :: (Maybe RulesSourceList -> f (Maybe RulesSourceList))
-> RulesSource -> f RulesSource
rulesSource_rulesSourceList = (RulesSource -> Maybe RulesSourceList)
-> (RulesSource -> Maybe RulesSourceList -> RulesSource)
-> Lens
     RulesSource
     RulesSource
     (Maybe RulesSourceList)
     (Maybe 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)

-- | 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/en/suricata-5.0.0/rules/intro.html# Rules Format>.
rulesSource_statefulRules :: Lens.Lens' RulesSource (Prelude.Maybe [StatefulRule])
rulesSource_statefulRules :: (Maybe [StatefulRule] -> f (Maybe [StatefulRule]))
-> RulesSource -> f RulesSource
rulesSource_statefulRules = (RulesSource -> Maybe [StatefulRule])
-> (RulesSource -> Maybe [StatefulRule] -> RulesSource)
-> Lens
     RulesSource
     RulesSource
     (Maybe [StatefulRule])
     (Maybe [StatefulRule])
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) ((Maybe [StatefulRule] -> f (Maybe [StatefulRule]))
 -> RulesSource -> f RulesSource)
-> ((Maybe [StatefulRule] -> f (Maybe [StatefulRule]))
    -> Maybe [StatefulRule] -> f (Maybe [StatefulRule]))
-> (Maybe [StatefulRule] -> f (Maybe [StatefulRule]))
-> RulesSource
-> f RulesSource
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [StatefulRule] [StatefulRule] [StatefulRule] [StatefulRule]
-> Iso
     (Maybe [StatefulRule])
     (Maybe [StatefulRule])
     (Maybe [StatefulRule])
     (Maybe [StatefulRule])
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 AnIso [StatefulRule] [StatefulRule] [StatefulRule] [StatefulRule]
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 :: (Maybe StatelessRulesAndCustomActions
 -> f (Maybe StatelessRulesAndCustomActions))
-> RulesSource -> f RulesSource
rulesSource_statelessRulesAndCustomActions = (RulesSource -> Maybe StatelessRulesAndCustomActions)
-> (RulesSource
    -> Maybe StatelessRulesAndCustomActions -> RulesSource)
-> Lens
     RulesSource
     RulesSource
     (Maybe StatelessRulesAndCustomActions)
     (Maybe 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 Core.FromJSON RulesSource where
  parseJSON :: Value -> Parser RulesSource
parseJSON =
    String
-> (Object -> Parser RulesSource) -> Value -> Parser RulesSource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RulesSource"
      ( \Object
x ->
          Maybe Text
-> Maybe RulesSourceList
-> Maybe [StatefulRule]
-> Maybe StatelessRulesAndCustomActions
-> RulesSource
RulesSource'
            (Maybe Text
 -> Maybe RulesSourceList
 -> Maybe [StatefulRule]
 -> Maybe StatelessRulesAndCustomActions
 -> RulesSource)
-> Parser (Maybe Text)
-> Parser
     (Maybe RulesSourceList
      -> Maybe [StatefulRule]
      -> Maybe StatelessRulesAndCustomActions
      -> RulesSource)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RulesString")
            Parser
  (Maybe RulesSourceList
   -> Maybe [StatefulRule]
   -> Maybe StatelessRulesAndCustomActions
   -> RulesSource)
-> Parser (Maybe RulesSourceList)
-> Parser
     (Maybe [StatefulRule]
      -> Maybe StatelessRulesAndCustomActions -> RulesSource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe RulesSourceList)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RulesSourceList")
            Parser
  (Maybe [StatefulRule]
   -> Maybe StatelessRulesAndCustomActions -> RulesSource)
-> Parser (Maybe [StatefulRule])
-> Parser (Maybe StatelessRulesAndCustomActions -> RulesSource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [StatefulRule]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"StatefulRules" Parser (Maybe (Maybe [StatefulRule]))
-> Maybe [StatefulRule] -> Parser (Maybe [StatefulRule])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [StatefulRule]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe StatelessRulesAndCustomActions -> RulesSource)
-> Parser (Maybe StatelessRulesAndCustomActions)
-> Parser RulesSource
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe StatelessRulesAndCustomActions)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"StatelessRulesAndCustomActions")
      )

instance Prelude.Hashable RulesSource

instance Prelude.NFData RulesSource

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