{-# 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.LogDestinationConfig
-- 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.LogDestinationConfig 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.LogDestinationType
import Amazonka.NetworkFirewall.Types.LogType
import qualified Amazonka.Prelude as Prelude

-- | Defines where Network Firewall sends logs for the firewall for one log
-- type. This is used in LoggingConfiguration. You can send each type of
-- log to an Amazon S3 bucket, a CloudWatch log group, or a Kinesis Data
-- Firehose delivery stream.
--
-- Network Firewall generates logs for stateful rule groups. You can save
-- alert and flow log types. The stateful rules engine records flow logs
-- for all network traffic that it receives. It records alert logs for
-- traffic that matches stateful rules that have the rule action set to
-- @DROP@ or @ALERT@.
--
-- /See:/ 'newLogDestinationConfig' smart constructor.
data LogDestinationConfig = LogDestinationConfig'
  { -- | The type of log to send. Alert logs report traffic that matches a
    -- StatefulRule with an action setting that sends an alert log message.
    -- Flow logs are standard network traffic flow logs.
    LogDestinationConfig -> LogType
logType :: LogType,
    -- | The type of storage destination to send these logs to. You can send logs
    -- to an Amazon S3 bucket, a CloudWatch log group, or a Kinesis Data
    -- Firehose delivery stream.
    LogDestinationConfig -> LogDestinationType
logDestinationType :: LogDestinationType,
    -- | The named location for the logs, provided in a key:value mapping that is
    -- specific to the chosen destination type.
    --
    -- -   For an Amazon S3 bucket, provide the name of the bucket, with key
    --     @bucketName@, and optionally provide a prefix, with key @prefix@.
    --     The following example specifies an Amazon S3 bucket named
    --     @DOC-EXAMPLE-BUCKET@ and the prefix @alerts@:
    --
    --     @\"LogDestination\": { \"bucketName\": \"DOC-EXAMPLE-BUCKET\", \"prefix\": \"alerts\" }@
    --
    -- -   For a CloudWatch log group, provide the name of the CloudWatch log
    --     group, with key @logGroup@. The following example specifies a log
    --     group named @alert-log-group@:
    --
    --     @\"LogDestination\": { \"logGroup\": \"alert-log-group\" }@
    --
    -- -   For a Kinesis Data Firehose delivery stream, provide the name of the
    --     delivery stream, with key @deliveryStream@. The following example
    --     specifies a delivery stream named @alert-delivery-stream@:
    --
    --     @\"LogDestination\": { \"deliveryStream\": \"alert-delivery-stream\" }@
    LogDestinationConfig -> HashMap Text Text
logDestination :: Prelude.HashMap Prelude.Text Prelude.Text
  }
  deriving (LogDestinationConfig -> LogDestinationConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LogDestinationConfig -> LogDestinationConfig -> Bool
$c/= :: LogDestinationConfig -> LogDestinationConfig -> Bool
== :: LogDestinationConfig -> LogDestinationConfig -> Bool
$c== :: LogDestinationConfig -> LogDestinationConfig -> Bool
Prelude.Eq, ReadPrec [LogDestinationConfig]
ReadPrec LogDestinationConfig
Int -> ReadS LogDestinationConfig
ReadS [LogDestinationConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LogDestinationConfig]
$creadListPrec :: ReadPrec [LogDestinationConfig]
readPrec :: ReadPrec LogDestinationConfig
$creadPrec :: ReadPrec LogDestinationConfig
readList :: ReadS [LogDestinationConfig]
$creadList :: ReadS [LogDestinationConfig]
readsPrec :: Int -> ReadS LogDestinationConfig
$creadsPrec :: Int -> ReadS LogDestinationConfig
Prelude.Read, Int -> LogDestinationConfig -> ShowS
[LogDestinationConfig] -> ShowS
LogDestinationConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LogDestinationConfig] -> ShowS
$cshowList :: [LogDestinationConfig] -> ShowS
show :: LogDestinationConfig -> String
$cshow :: LogDestinationConfig -> String
showsPrec :: Int -> LogDestinationConfig -> ShowS
$cshowsPrec :: Int -> LogDestinationConfig -> ShowS
Prelude.Show, forall x. Rep LogDestinationConfig x -> LogDestinationConfig
forall x. LogDestinationConfig -> Rep LogDestinationConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LogDestinationConfig x -> LogDestinationConfig
$cfrom :: forall x. LogDestinationConfig -> Rep LogDestinationConfig x
Prelude.Generic)

-- |
-- Create a value of 'LogDestinationConfig' 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:
--
-- 'logType', 'logDestinationConfig_logType' - The type of log to send. Alert logs report traffic that matches a
-- StatefulRule with an action setting that sends an alert log message.
-- Flow logs are standard network traffic flow logs.
--
-- 'logDestinationType', 'logDestinationConfig_logDestinationType' - The type of storage destination to send these logs to. You can send logs
-- to an Amazon S3 bucket, a CloudWatch log group, or a Kinesis Data
-- Firehose delivery stream.
--
-- 'logDestination', 'logDestinationConfig_logDestination' - The named location for the logs, provided in a key:value mapping that is
-- specific to the chosen destination type.
--
-- -   For an Amazon S3 bucket, provide the name of the bucket, with key
--     @bucketName@, and optionally provide a prefix, with key @prefix@.
--     The following example specifies an Amazon S3 bucket named
--     @DOC-EXAMPLE-BUCKET@ and the prefix @alerts@:
--
--     @\"LogDestination\": { \"bucketName\": \"DOC-EXAMPLE-BUCKET\", \"prefix\": \"alerts\" }@
--
-- -   For a CloudWatch log group, provide the name of the CloudWatch log
--     group, with key @logGroup@. The following example specifies a log
--     group named @alert-log-group@:
--
--     @\"LogDestination\": { \"logGroup\": \"alert-log-group\" }@
--
-- -   For a Kinesis Data Firehose delivery stream, provide the name of the
--     delivery stream, with key @deliveryStream@. The following example
--     specifies a delivery stream named @alert-delivery-stream@:
--
--     @\"LogDestination\": { \"deliveryStream\": \"alert-delivery-stream\" }@
newLogDestinationConfig ::
  -- | 'logType'
  LogType ->
  -- | 'logDestinationType'
  LogDestinationType ->
  LogDestinationConfig
newLogDestinationConfig :: LogType -> LogDestinationType -> LogDestinationConfig
newLogDestinationConfig
  LogType
pLogType_
  LogDestinationType
pLogDestinationType_ =
    LogDestinationConfig'
      { $sel:logType:LogDestinationConfig' :: LogType
logType = LogType
pLogType_,
        $sel:logDestinationType:LogDestinationConfig' :: LogDestinationType
logDestinationType = LogDestinationType
pLogDestinationType_,
        $sel:logDestination:LogDestinationConfig' :: HashMap Text Text
logDestination = forall a. Monoid a => a
Prelude.mempty
      }

-- | The type of log to send. Alert logs report traffic that matches a
-- StatefulRule with an action setting that sends an alert log message.
-- Flow logs are standard network traffic flow logs.
logDestinationConfig_logType :: Lens.Lens' LogDestinationConfig LogType
logDestinationConfig_logType :: Lens' LogDestinationConfig LogType
logDestinationConfig_logType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogDestinationConfig' {LogType
logType :: LogType
$sel:logType:LogDestinationConfig' :: LogDestinationConfig -> LogType
logType} -> LogType
logType) (\s :: LogDestinationConfig
s@LogDestinationConfig' {} LogType
a -> LogDestinationConfig
s {$sel:logType:LogDestinationConfig' :: LogType
logType = LogType
a} :: LogDestinationConfig)

-- | The type of storage destination to send these logs to. You can send logs
-- to an Amazon S3 bucket, a CloudWatch log group, or a Kinesis Data
-- Firehose delivery stream.
logDestinationConfig_logDestinationType :: Lens.Lens' LogDestinationConfig LogDestinationType
logDestinationConfig_logDestinationType :: Lens' LogDestinationConfig LogDestinationType
logDestinationConfig_logDestinationType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogDestinationConfig' {LogDestinationType
logDestinationType :: LogDestinationType
$sel:logDestinationType:LogDestinationConfig' :: LogDestinationConfig -> LogDestinationType
logDestinationType} -> LogDestinationType
logDestinationType) (\s :: LogDestinationConfig
s@LogDestinationConfig' {} LogDestinationType
a -> LogDestinationConfig
s {$sel:logDestinationType:LogDestinationConfig' :: LogDestinationType
logDestinationType = LogDestinationType
a} :: LogDestinationConfig)

-- | The named location for the logs, provided in a key:value mapping that is
-- specific to the chosen destination type.
--
-- -   For an Amazon S3 bucket, provide the name of the bucket, with key
--     @bucketName@, and optionally provide a prefix, with key @prefix@.
--     The following example specifies an Amazon S3 bucket named
--     @DOC-EXAMPLE-BUCKET@ and the prefix @alerts@:
--
--     @\"LogDestination\": { \"bucketName\": \"DOC-EXAMPLE-BUCKET\", \"prefix\": \"alerts\" }@
--
-- -   For a CloudWatch log group, provide the name of the CloudWatch log
--     group, with key @logGroup@. The following example specifies a log
--     group named @alert-log-group@:
--
--     @\"LogDestination\": { \"logGroup\": \"alert-log-group\" }@
--
-- -   For a Kinesis Data Firehose delivery stream, provide the name of the
--     delivery stream, with key @deliveryStream@. The following example
--     specifies a delivery stream named @alert-delivery-stream@:
--
--     @\"LogDestination\": { \"deliveryStream\": \"alert-delivery-stream\" }@
logDestinationConfig_logDestination :: Lens.Lens' LogDestinationConfig (Prelude.HashMap Prelude.Text Prelude.Text)
logDestinationConfig_logDestination :: Lens' LogDestinationConfig (HashMap Text Text)
logDestinationConfig_logDestination = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LogDestinationConfig' {HashMap Text Text
logDestination :: HashMap Text Text
$sel:logDestination:LogDestinationConfig' :: LogDestinationConfig -> HashMap Text Text
logDestination} -> HashMap Text Text
logDestination) (\s :: LogDestinationConfig
s@LogDestinationConfig' {} HashMap Text Text
a -> LogDestinationConfig
s {$sel:logDestination:LogDestinationConfig' :: HashMap Text Text
logDestination = HashMap Text Text
a} :: LogDestinationConfig) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON LogDestinationConfig where
  parseJSON :: Value -> Parser LogDestinationConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"LogDestinationConfig"
      ( \Object
x ->
          LogType
-> LogDestinationType -> HashMap Text Text -> LogDestinationConfig
LogDestinationConfig'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"LogType")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"LogDestinationType")
            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
"LogDestination"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable LogDestinationConfig where
  hashWithSalt :: Int -> LogDestinationConfig -> Int
hashWithSalt Int
_salt LogDestinationConfig' {HashMap Text Text
LogDestinationType
LogType
logDestination :: HashMap Text Text
logDestinationType :: LogDestinationType
logType :: LogType
$sel:logDestination:LogDestinationConfig' :: LogDestinationConfig -> HashMap Text Text
$sel:logDestinationType:LogDestinationConfig' :: LogDestinationConfig -> LogDestinationType
$sel:logType:LogDestinationConfig' :: LogDestinationConfig -> LogType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` LogType
logType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` LogDestinationType
logDestinationType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` HashMap Text Text
logDestination

instance Prelude.NFData LogDestinationConfig where
  rnf :: LogDestinationConfig -> ()
rnf LogDestinationConfig' {HashMap Text Text
LogDestinationType
LogType
logDestination :: HashMap Text Text
logDestinationType :: LogDestinationType
logType :: LogType
$sel:logDestination:LogDestinationConfig' :: LogDestinationConfig -> HashMap Text Text
$sel:logDestinationType:LogDestinationConfig' :: LogDestinationConfig -> LogDestinationType
$sel:logType:LogDestinationConfig' :: LogDestinationConfig -> LogType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf LogType
logType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf LogDestinationType
logDestinationType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf HashMap Text Text
logDestination

instance Data.ToJSON LogDestinationConfig where
  toJSON :: LogDestinationConfig -> Value
toJSON LogDestinationConfig' {HashMap Text Text
LogDestinationType
LogType
logDestination :: HashMap Text Text
logDestinationType :: LogDestinationType
logType :: LogType
$sel:logDestination:LogDestinationConfig' :: LogDestinationConfig -> HashMap Text Text
$sel:logDestinationType:LogDestinationConfig' :: LogDestinationConfig -> LogDestinationType
$sel:logType:LogDestinationConfig' :: LogDestinationConfig -> LogType
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"LogType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= LogType
logType),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"LogDestinationType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= LogDestinationType
logDestinationType),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"LogDestination" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= HashMap Text Text
logDestination)
          ]
      )