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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.NetworkFirewall.Types.IPSet
import Amazonka.NetworkFirewall.Types.PortSet
import qualified Amazonka.Prelude as Prelude

-- | Settings that are available for use in the rules in the RuleGroup where
-- this is defined.
--
-- /See:/ 'newRuleVariables' smart constructor.
data RuleVariables = RuleVariables'
  { -- | A list of port ranges.
    RuleVariables -> Maybe (HashMap Text PortSet)
portSets :: Prelude.Maybe (Prelude.HashMap Prelude.Text PortSet),
    -- | A list of IP addresses and address ranges, in CIDR notation.
    RuleVariables -> Maybe (HashMap Text IPSet)
iPSets :: Prelude.Maybe (Prelude.HashMap Prelude.Text IPSet)
  }
  deriving (RuleVariables -> RuleVariables -> Bool
(RuleVariables -> RuleVariables -> Bool)
-> (RuleVariables -> RuleVariables -> Bool) -> Eq RuleVariables
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RuleVariables -> RuleVariables -> Bool
$c/= :: RuleVariables -> RuleVariables -> Bool
== :: RuleVariables -> RuleVariables -> Bool
$c== :: RuleVariables -> RuleVariables -> Bool
Prelude.Eq, ReadPrec [RuleVariables]
ReadPrec RuleVariables
Int -> ReadS RuleVariables
ReadS [RuleVariables]
(Int -> ReadS RuleVariables)
-> ReadS [RuleVariables]
-> ReadPrec RuleVariables
-> ReadPrec [RuleVariables]
-> Read RuleVariables
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RuleVariables]
$creadListPrec :: ReadPrec [RuleVariables]
readPrec :: ReadPrec RuleVariables
$creadPrec :: ReadPrec RuleVariables
readList :: ReadS [RuleVariables]
$creadList :: ReadS [RuleVariables]
readsPrec :: Int -> ReadS RuleVariables
$creadsPrec :: Int -> ReadS RuleVariables
Prelude.Read, Int -> RuleVariables -> ShowS
[RuleVariables] -> ShowS
RuleVariables -> String
(Int -> RuleVariables -> ShowS)
-> (RuleVariables -> String)
-> ([RuleVariables] -> ShowS)
-> Show RuleVariables
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RuleVariables] -> ShowS
$cshowList :: [RuleVariables] -> ShowS
show :: RuleVariables -> String
$cshow :: RuleVariables -> String
showsPrec :: Int -> RuleVariables -> ShowS
$cshowsPrec :: Int -> RuleVariables -> ShowS
Prelude.Show, (forall x. RuleVariables -> Rep RuleVariables x)
-> (forall x. Rep RuleVariables x -> RuleVariables)
-> Generic RuleVariables
forall x. Rep RuleVariables x -> RuleVariables
forall x. RuleVariables -> Rep RuleVariables x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RuleVariables x -> RuleVariables
$cfrom :: forall x. RuleVariables -> Rep RuleVariables x
Prelude.Generic)

-- |
-- Create a value of 'RuleVariables' 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:
--
-- 'portSets', 'ruleVariables_portSets' - A list of port ranges.
--
-- 'iPSets', 'ruleVariables_iPSets' - A list of IP addresses and address ranges, in CIDR notation.
newRuleVariables ::
  RuleVariables
newRuleVariables :: RuleVariables
newRuleVariables =
  RuleVariables' :: Maybe (HashMap Text PortSet)
-> Maybe (HashMap Text IPSet) -> RuleVariables
RuleVariables'
    { $sel:portSets:RuleVariables' :: Maybe (HashMap Text PortSet)
portSets = Maybe (HashMap Text PortSet)
forall a. Maybe a
Prelude.Nothing,
      $sel:iPSets:RuleVariables' :: Maybe (HashMap Text IPSet)
iPSets = Maybe (HashMap Text IPSet)
forall a. Maybe a
Prelude.Nothing
    }

-- | A list of port ranges.
ruleVariables_portSets :: Lens.Lens' RuleVariables (Prelude.Maybe (Prelude.HashMap Prelude.Text PortSet))
ruleVariables_portSets :: (Maybe (HashMap Text PortSet) -> f (Maybe (HashMap Text PortSet)))
-> RuleVariables -> f RuleVariables
ruleVariables_portSets = (RuleVariables -> Maybe (HashMap Text PortSet))
-> (RuleVariables -> Maybe (HashMap Text PortSet) -> RuleVariables)
-> Lens
     RuleVariables
     RuleVariables
     (Maybe (HashMap Text PortSet))
     (Maybe (HashMap Text PortSet))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleVariables' {Maybe (HashMap Text PortSet)
portSets :: Maybe (HashMap Text PortSet)
$sel:portSets:RuleVariables' :: RuleVariables -> Maybe (HashMap Text PortSet)
portSets} -> Maybe (HashMap Text PortSet)
portSets) (\s :: RuleVariables
s@RuleVariables' {} Maybe (HashMap Text PortSet)
a -> RuleVariables
s {$sel:portSets:RuleVariables' :: Maybe (HashMap Text PortSet)
portSets = Maybe (HashMap Text PortSet)
a} :: RuleVariables) ((Maybe (HashMap Text PortSet) -> f (Maybe (HashMap Text PortSet)))
 -> RuleVariables -> f RuleVariables)
-> ((Maybe (HashMap Text PortSet)
     -> f (Maybe (HashMap Text PortSet)))
    -> Maybe (HashMap Text PortSet)
    -> f (Maybe (HashMap Text PortSet)))
-> (Maybe (HashMap Text PortSet)
    -> f (Maybe (HashMap Text PortSet)))
-> RuleVariables
-> f RuleVariables
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text PortSet)
  (HashMap Text PortSet)
  (HashMap Text PortSet)
  (HashMap Text PortSet)
-> Iso
     (Maybe (HashMap Text PortSet))
     (Maybe (HashMap Text PortSet))
     (Maybe (HashMap Text PortSet))
     (Maybe (HashMap Text PortSet))
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
  (HashMap Text PortSet)
  (HashMap Text PortSet)
  (HashMap Text PortSet)
  (HashMap Text PortSet)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A list of IP addresses and address ranges, in CIDR notation.
ruleVariables_iPSets :: Lens.Lens' RuleVariables (Prelude.Maybe (Prelude.HashMap Prelude.Text IPSet))
ruleVariables_iPSets :: (Maybe (HashMap Text IPSet) -> f (Maybe (HashMap Text IPSet)))
-> RuleVariables -> f RuleVariables
ruleVariables_iPSets = (RuleVariables -> Maybe (HashMap Text IPSet))
-> (RuleVariables -> Maybe (HashMap Text IPSet) -> RuleVariables)
-> Lens
     RuleVariables
     RuleVariables
     (Maybe (HashMap Text IPSet))
     (Maybe (HashMap Text IPSet))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleVariables' {Maybe (HashMap Text IPSet)
iPSets :: Maybe (HashMap Text IPSet)
$sel:iPSets:RuleVariables' :: RuleVariables -> Maybe (HashMap Text IPSet)
iPSets} -> Maybe (HashMap Text IPSet)
iPSets) (\s :: RuleVariables
s@RuleVariables' {} Maybe (HashMap Text IPSet)
a -> RuleVariables
s {$sel:iPSets:RuleVariables' :: Maybe (HashMap Text IPSet)
iPSets = Maybe (HashMap Text IPSet)
a} :: RuleVariables) ((Maybe (HashMap Text IPSet) -> f (Maybe (HashMap Text IPSet)))
 -> RuleVariables -> f RuleVariables)
-> ((Maybe (HashMap Text IPSet) -> f (Maybe (HashMap Text IPSet)))
    -> Maybe (HashMap Text IPSet) -> f (Maybe (HashMap Text IPSet)))
-> (Maybe (HashMap Text IPSet) -> f (Maybe (HashMap Text IPSet)))
-> RuleVariables
-> f RuleVariables
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text IPSet)
  (HashMap Text IPSet)
  (HashMap Text IPSet)
  (HashMap Text IPSet)
-> Iso
     (Maybe (HashMap Text IPSet))
     (Maybe (HashMap Text IPSet))
     (Maybe (HashMap Text IPSet))
     (Maybe (HashMap Text IPSet))
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
  (HashMap Text IPSet)
  (HashMap Text IPSet)
  (HashMap Text IPSet)
  (HashMap Text IPSet)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON RuleVariables where
  parseJSON :: Value -> Parser RuleVariables
parseJSON =
    String
-> (Object -> Parser RuleVariables)
-> Value
-> Parser RuleVariables
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RuleVariables"
      ( \Object
x ->
          Maybe (HashMap Text PortSet)
-> Maybe (HashMap Text IPSet) -> RuleVariables
RuleVariables'
            (Maybe (HashMap Text PortSet)
 -> Maybe (HashMap Text IPSet) -> RuleVariables)
-> Parser (Maybe (HashMap Text PortSet))
-> Parser (Maybe (HashMap Text IPSet) -> RuleVariables)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text PortSet)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PortSets" Parser (Maybe (Maybe (HashMap Text PortSet)))
-> Maybe (HashMap Text PortSet)
-> Parser (Maybe (HashMap Text PortSet))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text PortSet)
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe (HashMap Text IPSet) -> RuleVariables)
-> Parser (Maybe (HashMap Text IPSet)) -> Parser RuleVariables
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text IPSet)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"IPSets" Parser (Maybe (Maybe (HashMap Text IPSet)))
-> Maybe (HashMap Text IPSet)
-> Parser (Maybe (HashMap Text IPSet))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text IPSet)
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable RuleVariables

instance Prelude.NFData RuleVariables

instance Core.ToJSON RuleVariables where
  toJSON :: RuleVariables -> Value
toJSON RuleVariables' {Maybe (HashMap Text IPSet)
Maybe (HashMap Text PortSet)
iPSets :: Maybe (HashMap Text IPSet)
portSets :: Maybe (HashMap Text PortSet)
$sel:iPSets:RuleVariables' :: RuleVariables -> Maybe (HashMap Text IPSet)
$sel:portSets:RuleVariables' :: RuleVariables -> Maybe (HashMap Text PortSet)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"PortSets" Text -> HashMap Text PortSet -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text PortSet -> Pair)
-> Maybe (HashMap Text PortSet) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text PortSet)
portSets,
            (Text
"IPSets" Text -> HashMap Text IPSet -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text IPSet -> Pair)
-> Maybe (HashMap Text IPSet) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text IPSet)
iPSets
          ]
      )