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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.NetworkFirewall.Types.LogDestinationType
import Amazonka.NetworkFirewall.Types.LogType
import qualified Amazonka.Prelude as Prelude

-- | Defines where AWS 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
(LogDestinationConfig -> LogDestinationConfig -> Bool)
-> (LogDestinationConfig -> LogDestinationConfig -> Bool)
-> Eq LogDestinationConfig
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]
(Int -> ReadS LogDestinationConfig)
-> ReadS [LogDestinationConfig]
-> ReadPrec LogDestinationConfig
-> ReadPrec [LogDestinationConfig]
-> Read 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
(Int -> LogDestinationConfig -> ShowS)
-> (LogDestinationConfig -> String)
-> ([LogDestinationConfig] -> ShowS)
-> Show LogDestinationConfig
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. LogDestinationConfig -> Rep LogDestinationConfig x)
-> (forall x. Rep LogDestinationConfig x -> LogDestinationConfig)
-> Generic LogDestinationConfig
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' :: LogType
-> LogDestinationType -> HashMap Text Text -> LogDestinationConfig
LogDestinationConfig'
      { $sel:logType:LogDestinationConfig' :: LogType
logType = LogType
pLogType_,
        $sel:logDestinationType:LogDestinationConfig' :: LogDestinationType
logDestinationType = LogDestinationType
pLogDestinationType_,
        $sel:logDestination:LogDestinationConfig' :: HashMap Text Text
logDestination = HashMap Text Text
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 :: (LogType -> f LogType)
-> LogDestinationConfig -> f LogDestinationConfig
logDestinationConfig_logType = (LogDestinationConfig -> LogType)
-> (LogDestinationConfig -> LogType -> LogDestinationConfig)
-> Lens LogDestinationConfig LogDestinationConfig LogType 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 :: (LogDestinationType -> f LogDestinationType)
-> LogDestinationConfig -> f LogDestinationConfig
logDestinationConfig_logDestinationType = (LogDestinationConfig -> LogDestinationType)
-> (LogDestinationConfig
    -> LogDestinationType -> LogDestinationConfig)
-> Lens
     LogDestinationConfig
     LogDestinationConfig
     LogDestinationType
     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 :: (HashMap Text Text -> f (HashMap Text Text))
-> LogDestinationConfig -> f LogDestinationConfig
logDestinationConfig_logDestination = (LogDestinationConfig -> HashMap Text Text)
-> (LogDestinationConfig
    -> HashMap Text Text -> LogDestinationConfig)
-> Lens
     LogDestinationConfig
     LogDestinationConfig
     (HashMap Text Text)
     (HashMap Text Text)
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) ((HashMap Text Text -> f (HashMap Text Text))
 -> LogDestinationConfig -> f LogDestinationConfig)
-> ((HashMap Text Text -> f (HashMap Text Text))
    -> HashMap Text Text -> f (HashMap Text Text))
-> (HashMap Text Text -> f (HashMap Text Text))
-> LogDestinationConfig
-> f LogDestinationConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text Text -> f (HashMap Text Text))
-> HashMap Text Text -> f (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable LogDestinationConfig

instance Prelude.NFData LogDestinationConfig

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"LogType" Text -> LogType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= LogType
logType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"LogDestinationType" Text -> LogDestinationType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= LogDestinationType
logDestinationType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"LogDestination" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text Text
logDestination)
          ]
      )