{-# 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.WAFV2.Types.LoggingConfiguration
-- 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.WAFV2.Types.LoggingConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import Amazonka.WAFV2.Types.FieldToMatch
import Amazonka.WAFV2.Types.LoggingFilter

-- | Defines an association between logging destinations and a web ACL
-- resource, for logging from WAF. As part of the association, you can
-- specify parts of the standard logging fields to keep out of the logs and
-- you can specify filters so that you log only a subset of the logging
-- records.
--
-- You can define one logging destination per web ACL.
--
-- You can access information about the traffic that WAF inspects using the
-- following steps:
--
-- 1.  Create your logging destination. You can use an Amazon CloudWatch
--     Logs log group, an Amazon Simple Storage Service (Amazon S3) bucket,
--     or an Amazon Kinesis Data Firehose.
--
--     The name that you give the destination must start with
--     @aws-waf-logs-@. Depending on the type of destination, you might
--     need to configure additional settings or permissions.
--
--     For configuration requirements and pricing information for each
--     destination type, see
--     <https://docs.aws.amazon.com/waf/latest/developerguide/logging.html Logging web ACL traffic>
--     in the /WAF Developer Guide/.
--
-- 2.  Associate your logging destination to your web ACL using a
--     @PutLoggingConfiguration@ request.
--
-- When you successfully enable logging using a @PutLoggingConfiguration@
-- request, WAF creates an additional role or policy that is required to
-- write logs to the logging destination. For an Amazon CloudWatch Logs log
-- group, WAF creates a resource policy on the log group. For an Amazon S3
-- bucket, WAF creates a bucket policy. For an Amazon Kinesis Data
-- Firehose, WAF creates a service-linked role.
--
-- For additional information about web ACL logging, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/logging.html Logging web ACL traffic information>
-- in the /WAF Developer Guide/.
--
-- /See:/ 'newLoggingConfiguration' smart constructor.
data LoggingConfiguration = LoggingConfiguration'
  { -- | Filtering that specifies which web requests are kept in the logs and
    -- which are dropped. You can filter on the rule action and on the web
    -- request labels that were applied by matching rules during web ACL
    -- evaluation.
    LoggingConfiguration -> Maybe LoggingFilter
loggingFilter :: Prelude.Maybe LoggingFilter,
    -- | Indicates whether the logging configuration was created by Firewall
    -- Manager, as part of an WAF policy configuration. If true, only Firewall
    -- Manager can modify or delete the configuration.
    LoggingConfiguration -> Maybe Bool
managedByFirewallManager :: Prelude.Maybe Prelude.Bool,
    -- | The parts of the request that you want to keep out of the logs. For
    -- example, if you redact the @SingleHeader@ field, the @HEADER@ field in
    -- the logs will be @xxx@.
    --
    -- You can specify only the following fields for redaction: @UriPath@,
    -- @QueryString@, @SingleHeader@, @Method@, and @JsonBody@.
    LoggingConfiguration -> Maybe [FieldToMatch]
redactedFields :: Prelude.Maybe [FieldToMatch],
    -- | The Amazon Resource Name (ARN) of the web ACL that you want to associate
    -- with @LogDestinationConfigs@.
    LoggingConfiguration -> Text
resourceArn :: Prelude.Text,
    -- | The logging destination configuration that you want to associate with
    -- the web ACL.
    --
    -- You can associate one logging destination to a web ACL.
    LoggingConfiguration -> NonEmpty Text
logDestinationConfigs :: Prelude.NonEmpty Prelude.Text
  }
  deriving (LoggingConfiguration -> LoggingConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LoggingConfiguration -> LoggingConfiguration -> Bool
$c/= :: LoggingConfiguration -> LoggingConfiguration -> Bool
== :: LoggingConfiguration -> LoggingConfiguration -> Bool
$c== :: LoggingConfiguration -> LoggingConfiguration -> Bool
Prelude.Eq, ReadPrec [LoggingConfiguration]
ReadPrec LoggingConfiguration
Int -> ReadS LoggingConfiguration
ReadS [LoggingConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LoggingConfiguration]
$creadListPrec :: ReadPrec [LoggingConfiguration]
readPrec :: ReadPrec LoggingConfiguration
$creadPrec :: ReadPrec LoggingConfiguration
readList :: ReadS [LoggingConfiguration]
$creadList :: ReadS [LoggingConfiguration]
readsPrec :: Int -> ReadS LoggingConfiguration
$creadsPrec :: Int -> ReadS LoggingConfiguration
Prelude.Read, Int -> LoggingConfiguration -> ShowS
[LoggingConfiguration] -> ShowS
LoggingConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LoggingConfiguration] -> ShowS
$cshowList :: [LoggingConfiguration] -> ShowS
show :: LoggingConfiguration -> String
$cshow :: LoggingConfiguration -> String
showsPrec :: Int -> LoggingConfiguration -> ShowS
$cshowsPrec :: Int -> LoggingConfiguration -> ShowS
Prelude.Show, forall x. Rep LoggingConfiguration x -> LoggingConfiguration
forall x. LoggingConfiguration -> Rep LoggingConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LoggingConfiguration x -> LoggingConfiguration
$cfrom :: forall x. LoggingConfiguration -> Rep LoggingConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'LoggingConfiguration' 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:
--
-- 'loggingFilter', 'loggingConfiguration_loggingFilter' - Filtering that specifies which web requests are kept in the logs and
-- which are dropped. You can filter on the rule action and on the web
-- request labels that were applied by matching rules during web ACL
-- evaluation.
--
-- 'managedByFirewallManager', 'loggingConfiguration_managedByFirewallManager' - Indicates whether the logging configuration was created by Firewall
-- Manager, as part of an WAF policy configuration. If true, only Firewall
-- Manager can modify or delete the configuration.
--
-- 'redactedFields', 'loggingConfiguration_redactedFields' - The parts of the request that you want to keep out of the logs. For
-- example, if you redact the @SingleHeader@ field, the @HEADER@ field in
-- the logs will be @xxx@.
--
-- You can specify only the following fields for redaction: @UriPath@,
-- @QueryString@, @SingleHeader@, @Method@, and @JsonBody@.
--
-- 'resourceArn', 'loggingConfiguration_resourceArn' - The Amazon Resource Name (ARN) of the web ACL that you want to associate
-- with @LogDestinationConfigs@.
--
-- 'logDestinationConfigs', 'loggingConfiguration_logDestinationConfigs' - The logging destination configuration that you want to associate with
-- the web ACL.
--
-- You can associate one logging destination to a web ACL.
newLoggingConfiguration ::
  -- | 'resourceArn'
  Prelude.Text ->
  -- | 'logDestinationConfigs'
  Prelude.NonEmpty Prelude.Text ->
  LoggingConfiguration
newLoggingConfiguration :: Text -> NonEmpty Text -> LoggingConfiguration
newLoggingConfiguration
  Text
pResourceArn_
  NonEmpty Text
pLogDestinationConfigs_ =
    LoggingConfiguration'
      { $sel:loggingFilter:LoggingConfiguration' :: Maybe LoggingFilter
loggingFilter =
          forall a. Maybe a
Prelude.Nothing,
        $sel:managedByFirewallManager:LoggingConfiguration' :: Maybe Bool
managedByFirewallManager = forall a. Maybe a
Prelude.Nothing,
        $sel:redactedFields:LoggingConfiguration' :: Maybe [FieldToMatch]
redactedFields = forall a. Maybe a
Prelude.Nothing,
        $sel:resourceArn:LoggingConfiguration' :: Text
resourceArn = Text
pResourceArn_,
        $sel:logDestinationConfigs:LoggingConfiguration' :: NonEmpty Text
logDestinationConfigs =
          forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pLogDestinationConfigs_
      }

-- | Filtering that specifies which web requests are kept in the logs and
-- which are dropped. You can filter on the rule action and on the web
-- request labels that were applied by matching rules during web ACL
-- evaluation.
loggingConfiguration_loggingFilter :: Lens.Lens' LoggingConfiguration (Prelude.Maybe LoggingFilter)
loggingConfiguration_loggingFilter :: Lens' LoggingConfiguration (Maybe LoggingFilter)
loggingConfiguration_loggingFilter = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoggingConfiguration' {Maybe LoggingFilter
loggingFilter :: Maybe LoggingFilter
$sel:loggingFilter:LoggingConfiguration' :: LoggingConfiguration -> Maybe LoggingFilter
loggingFilter} -> Maybe LoggingFilter
loggingFilter) (\s :: LoggingConfiguration
s@LoggingConfiguration' {} Maybe LoggingFilter
a -> LoggingConfiguration
s {$sel:loggingFilter:LoggingConfiguration' :: Maybe LoggingFilter
loggingFilter = Maybe LoggingFilter
a} :: LoggingConfiguration)

-- | Indicates whether the logging configuration was created by Firewall
-- Manager, as part of an WAF policy configuration. If true, only Firewall
-- Manager can modify or delete the configuration.
loggingConfiguration_managedByFirewallManager :: Lens.Lens' LoggingConfiguration (Prelude.Maybe Prelude.Bool)
loggingConfiguration_managedByFirewallManager :: Lens' LoggingConfiguration (Maybe Bool)
loggingConfiguration_managedByFirewallManager = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoggingConfiguration' {Maybe Bool
managedByFirewallManager :: Maybe Bool
$sel:managedByFirewallManager:LoggingConfiguration' :: LoggingConfiguration -> Maybe Bool
managedByFirewallManager} -> Maybe Bool
managedByFirewallManager) (\s :: LoggingConfiguration
s@LoggingConfiguration' {} Maybe Bool
a -> LoggingConfiguration
s {$sel:managedByFirewallManager:LoggingConfiguration' :: Maybe Bool
managedByFirewallManager = Maybe Bool
a} :: LoggingConfiguration)

-- | The parts of the request that you want to keep out of the logs. For
-- example, if you redact the @SingleHeader@ field, the @HEADER@ field in
-- the logs will be @xxx@.
--
-- You can specify only the following fields for redaction: @UriPath@,
-- @QueryString@, @SingleHeader@, @Method@, and @JsonBody@.
loggingConfiguration_redactedFields :: Lens.Lens' LoggingConfiguration (Prelude.Maybe [FieldToMatch])
loggingConfiguration_redactedFields :: Lens' LoggingConfiguration (Maybe [FieldToMatch])
loggingConfiguration_redactedFields = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoggingConfiguration' {Maybe [FieldToMatch]
redactedFields :: Maybe [FieldToMatch]
$sel:redactedFields:LoggingConfiguration' :: LoggingConfiguration -> Maybe [FieldToMatch]
redactedFields} -> Maybe [FieldToMatch]
redactedFields) (\s :: LoggingConfiguration
s@LoggingConfiguration' {} Maybe [FieldToMatch]
a -> LoggingConfiguration
s {$sel:redactedFields:LoggingConfiguration' :: Maybe [FieldToMatch]
redactedFields = Maybe [FieldToMatch]
a} :: LoggingConfiguration) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The Amazon Resource Name (ARN) of the web ACL that you want to associate
-- with @LogDestinationConfigs@.
loggingConfiguration_resourceArn :: Lens.Lens' LoggingConfiguration Prelude.Text
loggingConfiguration_resourceArn :: Lens' LoggingConfiguration Text
loggingConfiguration_resourceArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoggingConfiguration' {Text
resourceArn :: Text
$sel:resourceArn:LoggingConfiguration' :: LoggingConfiguration -> Text
resourceArn} -> Text
resourceArn) (\s :: LoggingConfiguration
s@LoggingConfiguration' {} Text
a -> LoggingConfiguration
s {$sel:resourceArn:LoggingConfiguration' :: Text
resourceArn = Text
a} :: LoggingConfiguration)

-- | The logging destination configuration that you want to associate with
-- the web ACL.
--
-- You can associate one logging destination to a web ACL.
loggingConfiguration_logDestinationConfigs :: Lens.Lens' LoggingConfiguration (Prelude.NonEmpty Prelude.Text)
loggingConfiguration_logDestinationConfigs :: Lens' LoggingConfiguration (NonEmpty Text)
loggingConfiguration_logDestinationConfigs = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoggingConfiguration' {NonEmpty Text
logDestinationConfigs :: NonEmpty Text
$sel:logDestinationConfigs:LoggingConfiguration' :: LoggingConfiguration -> NonEmpty Text
logDestinationConfigs} -> NonEmpty Text
logDestinationConfigs) (\s :: LoggingConfiguration
s@LoggingConfiguration' {} NonEmpty Text
a -> LoggingConfiguration
s {$sel:logDestinationConfigs:LoggingConfiguration' :: NonEmpty Text
logDestinationConfigs = NonEmpty Text
a} :: LoggingConfiguration) 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 LoggingConfiguration where
  parseJSON :: Value -> Parser LoggingConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"LoggingConfiguration"
      ( \Object
x ->
          Maybe LoggingFilter
-> Maybe Bool
-> Maybe [FieldToMatch]
-> Text
-> NonEmpty Text
-> LoggingConfiguration
LoggingConfiguration'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"LoggingFilter")
            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
"ManagedByFirewallManager")
            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
"RedactedFields" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"ResourceArn")
            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
"LogDestinationConfigs")
      )

instance Prelude.Hashable LoggingConfiguration where
  hashWithSalt :: Int -> LoggingConfiguration -> Int
hashWithSalt Int
_salt LoggingConfiguration' {Maybe Bool
Maybe [FieldToMatch]
Maybe LoggingFilter
NonEmpty Text
Text
logDestinationConfigs :: NonEmpty Text
resourceArn :: Text
redactedFields :: Maybe [FieldToMatch]
managedByFirewallManager :: Maybe Bool
loggingFilter :: Maybe LoggingFilter
$sel:logDestinationConfigs:LoggingConfiguration' :: LoggingConfiguration -> NonEmpty Text
$sel:resourceArn:LoggingConfiguration' :: LoggingConfiguration -> Text
$sel:redactedFields:LoggingConfiguration' :: LoggingConfiguration -> Maybe [FieldToMatch]
$sel:managedByFirewallManager:LoggingConfiguration' :: LoggingConfiguration -> Maybe Bool
$sel:loggingFilter:LoggingConfiguration' :: LoggingConfiguration -> Maybe LoggingFilter
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe LoggingFilter
loggingFilter
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
managedByFirewallManager
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [FieldToMatch]
redactedFields
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
resourceArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
logDestinationConfigs

instance Prelude.NFData LoggingConfiguration where
  rnf :: LoggingConfiguration -> ()
rnf LoggingConfiguration' {Maybe Bool
Maybe [FieldToMatch]
Maybe LoggingFilter
NonEmpty Text
Text
logDestinationConfigs :: NonEmpty Text
resourceArn :: Text
redactedFields :: Maybe [FieldToMatch]
managedByFirewallManager :: Maybe Bool
loggingFilter :: Maybe LoggingFilter
$sel:logDestinationConfigs:LoggingConfiguration' :: LoggingConfiguration -> NonEmpty Text
$sel:resourceArn:LoggingConfiguration' :: LoggingConfiguration -> Text
$sel:redactedFields:LoggingConfiguration' :: LoggingConfiguration -> Maybe [FieldToMatch]
$sel:managedByFirewallManager:LoggingConfiguration' :: LoggingConfiguration -> Maybe Bool
$sel:loggingFilter:LoggingConfiguration' :: LoggingConfiguration -> Maybe LoggingFilter
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe LoggingFilter
loggingFilter
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
managedByFirewallManager
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [FieldToMatch]
redactedFields
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
resourceArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
logDestinationConfigs

instance Data.ToJSON LoggingConfiguration where
  toJSON :: LoggingConfiguration -> Value
toJSON LoggingConfiguration' {Maybe Bool
Maybe [FieldToMatch]
Maybe LoggingFilter
NonEmpty Text
Text
logDestinationConfigs :: NonEmpty Text
resourceArn :: Text
redactedFields :: Maybe [FieldToMatch]
managedByFirewallManager :: Maybe Bool
loggingFilter :: Maybe LoggingFilter
$sel:logDestinationConfigs:LoggingConfiguration' :: LoggingConfiguration -> NonEmpty Text
$sel:resourceArn:LoggingConfiguration' :: LoggingConfiguration -> Text
$sel:redactedFields:LoggingConfiguration' :: LoggingConfiguration -> Maybe [FieldToMatch]
$sel:managedByFirewallManager:LoggingConfiguration' :: LoggingConfiguration -> Maybe Bool
$sel:loggingFilter:LoggingConfiguration' :: LoggingConfiguration -> Maybe LoggingFilter
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"LoggingFilter" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe LoggingFilter
loggingFilter,
            (Key
"ManagedByFirewallManager" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
managedByFirewallManager,
            (Key
"RedactedFields" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [FieldToMatch]
redactedFields,
            forall a. a -> Maybe a
Prelude.Just (Key
"ResourceArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
resourceArn),
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"LogDestinationConfigs"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
logDestinationConfigs
              )
          ]
      )