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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.WAFRegional.Types.FieldToMatch

-- | This is __AWS WAF Classic__ documentation. For more information, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/classic-waf-chapter.html AWS WAF Classic>
-- in the developer guide.
--
-- __For the latest version of AWS WAF__, use the AWS WAFV2 API and see the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html AWS WAF Developer Guide>.
-- With the latest version, AWS WAF has a single set of endpoints for
-- regional and global use.
--
-- The Amazon Kinesis Data Firehose, @RedactedFields@ information, and the
-- web ACL Amazon Resource Name (ARN).
--
-- /See:/ 'newLoggingConfiguration' smart constructor.
data LoggingConfiguration = LoggingConfiguration'
  { -- | The parts of the request that you want redacted from the logs. For
    -- example, if you redact the cookie field, the cookie field in the
    -- firehose will be @xxx@.
    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,
    -- | An array of Amazon Kinesis Data Firehose ARNs.
    LoggingConfiguration -> NonEmpty Text
logDestinationConfigs :: Prelude.NonEmpty Prelude.Text
  }
  deriving (LoggingConfiguration -> LoggingConfiguration -> Bool
(LoggingConfiguration -> LoggingConfiguration -> Bool)
-> (LoggingConfiguration -> LoggingConfiguration -> Bool)
-> Eq LoggingConfiguration
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]
(Int -> ReadS LoggingConfiguration)
-> ReadS [LoggingConfiguration]
-> ReadPrec LoggingConfiguration
-> ReadPrec [LoggingConfiguration]
-> Read 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
(Int -> LoggingConfiguration -> ShowS)
-> (LoggingConfiguration -> String)
-> ([LoggingConfiguration] -> ShowS)
-> Show LoggingConfiguration
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. LoggingConfiguration -> Rep LoggingConfiguration x)
-> (forall x. Rep LoggingConfiguration x -> LoggingConfiguration)
-> Generic LoggingConfiguration
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:
--
-- 'redactedFields', 'loggingConfiguration_redactedFields' - The parts of the request that you want redacted from the logs. For
-- example, if you redact the cookie field, the cookie field in the
-- firehose will be @xxx@.
--
-- 'resourceArn', 'loggingConfiguration_resourceArn' - The Amazon Resource Name (ARN) of the web ACL that you want to associate
-- with @LogDestinationConfigs@.
--
-- 'logDestinationConfigs', 'loggingConfiguration_logDestinationConfigs' - An array of Amazon Kinesis Data Firehose ARNs.
newLoggingConfiguration ::
  -- | 'resourceArn'
  Prelude.Text ->
  -- | 'logDestinationConfigs'
  Prelude.NonEmpty Prelude.Text ->
  LoggingConfiguration
newLoggingConfiguration :: Text -> NonEmpty Text -> LoggingConfiguration
newLoggingConfiguration
  Text
pResourceArn_
  NonEmpty Text
pLogDestinationConfigs_ =
    LoggingConfiguration' :: Maybe [FieldToMatch]
-> Text -> NonEmpty Text -> LoggingConfiguration
LoggingConfiguration'
      { $sel:redactedFields:LoggingConfiguration' :: Maybe [FieldToMatch]
redactedFields =
          Maybe [FieldToMatch]
forall a. Maybe a
Prelude.Nothing,
        $sel:resourceArn:LoggingConfiguration' :: Text
resourceArn = Text
pResourceArn_,
        $sel:logDestinationConfigs:LoggingConfiguration' :: NonEmpty Text
logDestinationConfigs =
          Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pLogDestinationConfigs_
      }

-- | The parts of the request that you want redacted from the logs. For
-- example, if you redact the cookie field, the cookie field in the
-- firehose will be @xxx@.
loggingConfiguration_redactedFields :: Lens.Lens' LoggingConfiguration (Prelude.Maybe [FieldToMatch])
loggingConfiguration_redactedFields :: (Maybe [FieldToMatch] -> f (Maybe [FieldToMatch]))
-> LoggingConfiguration -> f LoggingConfiguration
loggingConfiguration_redactedFields = (LoggingConfiguration -> Maybe [FieldToMatch])
-> (LoggingConfiguration
    -> Maybe [FieldToMatch] -> LoggingConfiguration)
-> Lens
     LoggingConfiguration
     LoggingConfiguration
     (Maybe [FieldToMatch])
     (Maybe [FieldToMatch])
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) ((Maybe [FieldToMatch] -> f (Maybe [FieldToMatch]))
 -> LoggingConfiguration -> f LoggingConfiguration)
-> ((Maybe [FieldToMatch] -> f (Maybe [FieldToMatch]))
    -> Maybe [FieldToMatch] -> f (Maybe [FieldToMatch]))
-> (Maybe [FieldToMatch] -> f (Maybe [FieldToMatch]))
-> LoggingConfiguration
-> f LoggingConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [FieldToMatch] [FieldToMatch] [FieldToMatch] [FieldToMatch]
-> Iso
     (Maybe [FieldToMatch])
     (Maybe [FieldToMatch])
     (Maybe [FieldToMatch])
     (Maybe [FieldToMatch])
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 [FieldToMatch] [FieldToMatch] [FieldToMatch] [FieldToMatch]
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 :: (Text -> f Text) -> LoggingConfiguration -> f LoggingConfiguration
loggingConfiguration_resourceArn = (LoggingConfiguration -> Text)
-> (LoggingConfiguration -> Text -> LoggingConfiguration)
-> Lens LoggingConfiguration LoggingConfiguration Text Text
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)

-- | An array of Amazon Kinesis Data Firehose ARNs.
loggingConfiguration_logDestinationConfigs :: Lens.Lens' LoggingConfiguration (Prelude.NonEmpty Prelude.Text)
loggingConfiguration_logDestinationConfigs :: (NonEmpty Text -> f (NonEmpty Text))
-> LoggingConfiguration -> f LoggingConfiguration
loggingConfiguration_logDestinationConfigs = (LoggingConfiguration -> NonEmpty Text)
-> (LoggingConfiguration -> NonEmpty Text -> LoggingConfiguration)
-> Lens
     LoggingConfiguration
     LoggingConfiguration
     (NonEmpty Text)
     (NonEmpty Text)
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) ((NonEmpty Text -> f (NonEmpty Text))
 -> LoggingConfiguration -> f LoggingConfiguration)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> LoggingConfiguration
-> f LoggingConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON LoggingConfiguration where
  parseJSON :: Value -> Parser LoggingConfiguration
parseJSON =
    String
-> (Object -> Parser LoggingConfiguration)
-> Value
-> Parser LoggingConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"LoggingConfiguration"
      ( \Object
x ->
          Maybe [FieldToMatch]
-> Text -> NonEmpty Text -> LoggingConfiguration
LoggingConfiguration'
            (Maybe [FieldToMatch]
 -> Text -> NonEmpty Text -> LoggingConfiguration)
-> Parser (Maybe [FieldToMatch])
-> Parser (Text -> NonEmpty Text -> LoggingConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [FieldToMatch]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RedactedFields" Parser (Maybe (Maybe [FieldToMatch]))
-> Maybe [FieldToMatch] -> Parser (Maybe [FieldToMatch])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [FieldToMatch]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Text -> NonEmpty Text -> LoggingConfiguration)
-> Parser Text -> Parser (NonEmpty Text -> LoggingConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ResourceArn")
            Parser (NonEmpty Text -> LoggingConfiguration)
-> Parser (NonEmpty Text) -> Parser LoggingConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (NonEmpty Text)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"LogDestinationConfigs")
      )

instance Prelude.Hashable LoggingConfiguration

instance Prelude.NFData LoggingConfiguration

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