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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.NetworkFirewall.Types.GeneratedRulesType
import Amazonka.NetworkFirewall.Types.TargetType
import qualified Amazonka.Prelude as Prelude

-- | Stateful inspection criteria for a domain list rule group.
--
-- For HTTPS traffic, domain filtering is SNI-based. It uses the server
-- name indicator extension of the TLS handshake.
--
-- By default, Network Firewall domain list inspection only includes
-- traffic coming from the VPC where you deploy the firewall. To inspect
-- traffic from IP addresses outside of the deployment VPC, you set the
-- @HOME_NET@ rule variable to include the CIDR range of the deployment VPC
-- plus the other CIDR ranges. For more information, see RuleVariables in
-- this guide and
-- <https://docs.aws.amazon.com/network-firewall/latest/developerguide/stateful-rule-groups-domain-names.html Stateful domain list rule groups in AWS Network Firewall>
-- in the /Network Firewall Developer Guide/.
--
-- /See:/ 'newRulesSourceList' smart constructor.
data RulesSourceList = RulesSourceList'
  { -- | The domains that you want to inspect for in your traffic flows. To
    -- provide multiple domains, separate them with commas. Valid domain
    -- specifications are the following:
    --
    -- -   Explicit names. For example, @abc.example.com@ matches only the
    --     domain @abc.example.com@.
    --
    -- -   Names that use a domain wildcard, which you indicate with an initial
    --     \'@.@\'. For example,@.example.com@ matches @example.com@ and
    --     matches all subdomains of @example.com@, such as @abc.example.com@
    --     and @www.example.com@.
    RulesSourceList -> [Text]
targets :: [Prelude.Text],
    -- | The protocols you want to inspect. Specify @TLS_SNI@ for @HTTPS@.
    -- Specify @HTTP_HOST@ for @HTTP@. You can specify either or both.
    RulesSourceList -> [TargetType]
targetTypes :: [TargetType],
    -- | Whether you want to allow or deny access to the domains in your target
    -- list.
    RulesSourceList -> GeneratedRulesType
generatedRulesType :: GeneratedRulesType
  }
  deriving (RulesSourceList -> RulesSourceList -> Bool
(RulesSourceList -> RulesSourceList -> Bool)
-> (RulesSourceList -> RulesSourceList -> Bool)
-> Eq RulesSourceList
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RulesSourceList -> RulesSourceList -> Bool
$c/= :: RulesSourceList -> RulesSourceList -> Bool
== :: RulesSourceList -> RulesSourceList -> Bool
$c== :: RulesSourceList -> RulesSourceList -> Bool
Prelude.Eq, ReadPrec [RulesSourceList]
ReadPrec RulesSourceList
Int -> ReadS RulesSourceList
ReadS [RulesSourceList]
(Int -> ReadS RulesSourceList)
-> ReadS [RulesSourceList]
-> ReadPrec RulesSourceList
-> ReadPrec [RulesSourceList]
-> Read RulesSourceList
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RulesSourceList]
$creadListPrec :: ReadPrec [RulesSourceList]
readPrec :: ReadPrec RulesSourceList
$creadPrec :: ReadPrec RulesSourceList
readList :: ReadS [RulesSourceList]
$creadList :: ReadS [RulesSourceList]
readsPrec :: Int -> ReadS RulesSourceList
$creadsPrec :: Int -> ReadS RulesSourceList
Prelude.Read, Int -> RulesSourceList -> ShowS
[RulesSourceList] -> ShowS
RulesSourceList -> String
(Int -> RulesSourceList -> ShowS)
-> (RulesSourceList -> String)
-> ([RulesSourceList] -> ShowS)
-> Show RulesSourceList
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RulesSourceList] -> ShowS
$cshowList :: [RulesSourceList] -> ShowS
show :: RulesSourceList -> String
$cshow :: RulesSourceList -> String
showsPrec :: Int -> RulesSourceList -> ShowS
$cshowsPrec :: Int -> RulesSourceList -> ShowS
Prelude.Show, (forall x. RulesSourceList -> Rep RulesSourceList x)
-> (forall x. Rep RulesSourceList x -> RulesSourceList)
-> Generic RulesSourceList
forall x. Rep RulesSourceList x -> RulesSourceList
forall x. RulesSourceList -> Rep RulesSourceList x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RulesSourceList x -> RulesSourceList
$cfrom :: forall x. RulesSourceList -> Rep RulesSourceList x
Prelude.Generic)

-- |
-- Create a value of 'RulesSourceList' 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:
--
-- 'targets', 'rulesSourceList_targets' - The domains that you want to inspect for in your traffic flows. To
-- provide multiple domains, separate them with commas. Valid domain
-- specifications are the following:
--
-- -   Explicit names. For example, @abc.example.com@ matches only the
--     domain @abc.example.com@.
--
-- -   Names that use a domain wildcard, which you indicate with an initial
--     \'@.@\'. For example,@.example.com@ matches @example.com@ and
--     matches all subdomains of @example.com@, such as @abc.example.com@
--     and @www.example.com@.
--
-- 'targetTypes', 'rulesSourceList_targetTypes' - The protocols you want to inspect. Specify @TLS_SNI@ for @HTTPS@.
-- Specify @HTTP_HOST@ for @HTTP@. You can specify either or both.
--
-- 'generatedRulesType', 'rulesSourceList_generatedRulesType' - Whether you want to allow or deny access to the domains in your target
-- list.
newRulesSourceList ::
  -- | 'generatedRulesType'
  GeneratedRulesType ->
  RulesSourceList
newRulesSourceList :: GeneratedRulesType -> RulesSourceList
newRulesSourceList GeneratedRulesType
pGeneratedRulesType_ =
  RulesSourceList' :: [Text] -> [TargetType] -> GeneratedRulesType -> RulesSourceList
RulesSourceList'
    { $sel:targets:RulesSourceList' :: [Text]
targets = [Text]
forall a. Monoid a => a
Prelude.mempty,
      $sel:targetTypes:RulesSourceList' :: [TargetType]
targetTypes = [TargetType]
forall a. Monoid a => a
Prelude.mempty,
      $sel:generatedRulesType:RulesSourceList' :: GeneratedRulesType
generatedRulesType = GeneratedRulesType
pGeneratedRulesType_
    }

-- | The domains that you want to inspect for in your traffic flows. To
-- provide multiple domains, separate them with commas. Valid domain
-- specifications are the following:
--
-- -   Explicit names. For example, @abc.example.com@ matches only the
--     domain @abc.example.com@.
--
-- -   Names that use a domain wildcard, which you indicate with an initial
--     \'@.@\'. For example,@.example.com@ matches @example.com@ and
--     matches all subdomains of @example.com@, such as @abc.example.com@
--     and @www.example.com@.
rulesSourceList_targets :: Lens.Lens' RulesSourceList [Prelude.Text]
rulesSourceList_targets :: ([Text] -> f [Text]) -> RulesSourceList -> f RulesSourceList
rulesSourceList_targets = (RulesSourceList -> [Text])
-> (RulesSourceList -> [Text] -> RulesSourceList)
-> Lens RulesSourceList RulesSourceList [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RulesSourceList' {[Text]
targets :: [Text]
$sel:targets:RulesSourceList' :: RulesSourceList -> [Text]
targets} -> [Text]
targets) (\s :: RulesSourceList
s@RulesSourceList' {} [Text]
a -> RulesSourceList
s {$sel:targets:RulesSourceList' :: [Text]
targets = [Text]
a} :: RulesSourceList) (([Text] -> f [Text]) -> RulesSourceList -> f RulesSourceList)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> RulesSourceList
-> f RulesSourceList
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The protocols you want to inspect. Specify @TLS_SNI@ for @HTTPS@.
-- Specify @HTTP_HOST@ for @HTTP@. You can specify either or both.
rulesSourceList_targetTypes :: Lens.Lens' RulesSourceList [TargetType]
rulesSourceList_targetTypes :: ([TargetType] -> f [TargetType])
-> RulesSourceList -> f RulesSourceList
rulesSourceList_targetTypes = (RulesSourceList -> [TargetType])
-> (RulesSourceList -> [TargetType] -> RulesSourceList)
-> Lens RulesSourceList RulesSourceList [TargetType] [TargetType]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RulesSourceList' {[TargetType]
targetTypes :: [TargetType]
$sel:targetTypes:RulesSourceList' :: RulesSourceList -> [TargetType]
targetTypes} -> [TargetType]
targetTypes) (\s :: RulesSourceList
s@RulesSourceList' {} [TargetType]
a -> RulesSourceList
s {$sel:targetTypes:RulesSourceList' :: [TargetType]
targetTypes = [TargetType]
a} :: RulesSourceList) (([TargetType] -> f [TargetType])
 -> RulesSourceList -> f RulesSourceList)
-> (([TargetType] -> f [TargetType])
    -> [TargetType] -> f [TargetType])
-> ([TargetType] -> f [TargetType])
-> RulesSourceList
-> f RulesSourceList
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([TargetType] -> f [TargetType]) -> [TargetType] -> f [TargetType]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Whether you want to allow or deny access to the domains in your target
-- list.
rulesSourceList_generatedRulesType :: Lens.Lens' RulesSourceList GeneratedRulesType
rulesSourceList_generatedRulesType :: (GeneratedRulesType -> f GeneratedRulesType)
-> RulesSourceList -> f RulesSourceList
rulesSourceList_generatedRulesType = (RulesSourceList -> GeneratedRulesType)
-> (RulesSourceList -> GeneratedRulesType -> RulesSourceList)
-> Lens
     RulesSourceList
     RulesSourceList
     GeneratedRulesType
     GeneratedRulesType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RulesSourceList' {GeneratedRulesType
generatedRulesType :: GeneratedRulesType
$sel:generatedRulesType:RulesSourceList' :: RulesSourceList -> GeneratedRulesType
generatedRulesType} -> GeneratedRulesType
generatedRulesType) (\s :: RulesSourceList
s@RulesSourceList' {} GeneratedRulesType
a -> RulesSourceList
s {$sel:generatedRulesType:RulesSourceList' :: GeneratedRulesType
generatedRulesType = GeneratedRulesType
a} :: RulesSourceList)

instance Core.FromJSON RulesSourceList where
  parseJSON :: Value -> Parser RulesSourceList
parseJSON =
    String
-> (Object -> Parser RulesSourceList)
-> Value
-> Parser RulesSourceList
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RulesSourceList"
      ( \Object
x ->
          [Text] -> [TargetType] -> GeneratedRulesType -> RulesSourceList
RulesSourceList'
            ([Text] -> [TargetType] -> GeneratedRulesType -> RulesSourceList)
-> Parser [Text]
-> Parser ([TargetType] -> GeneratedRulesType -> RulesSourceList)
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
"Targets" Parser (Maybe [Text]) -> [Text] -> Parser [Text]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser ([TargetType] -> GeneratedRulesType -> RulesSourceList)
-> Parser [TargetType]
-> Parser (GeneratedRulesType -> RulesSourceList)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [TargetType])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"TargetTypes" Parser (Maybe [TargetType]) -> [TargetType] -> Parser [TargetType]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [TargetType]
forall a. Monoid a => a
Prelude.mempty)
            Parser (GeneratedRulesType -> RulesSourceList)
-> Parser GeneratedRulesType -> Parser RulesSourceList
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser GeneratedRulesType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"GeneratedRulesType")
      )

instance Prelude.Hashable RulesSourceList

instance Prelude.NFData RulesSourceList

instance Core.ToJSON RulesSourceList where
  toJSON :: RulesSourceList -> Value
toJSON RulesSourceList' {[Text]
[TargetType]
GeneratedRulesType
generatedRulesType :: GeneratedRulesType
targetTypes :: [TargetType]
targets :: [Text]
$sel:generatedRulesType:RulesSourceList' :: RulesSourceList -> GeneratedRulesType
$sel:targetTypes:RulesSourceList' :: RulesSourceList -> [TargetType]
$sel:targets:RulesSourceList' :: RulesSourceList -> [Text]
..} =
    [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
"Targets" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
targets),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"TargetTypes" Text -> [TargetType] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [TargetType]
targetTypes),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"GeneratedRulesType" Text -> GeneratedRulesType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= GeneratedRulesType
generatedRulesType)
          ]
      )