{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.PutLoggingConfiguration
-- 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)
--
-- 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.
--
-- Associates a LoggingConfiguration with a specified web ACL.
--
-- You can access information about all traffic that AWS WAF inspects using
-- the following steps:
--
-- 1.  Create an Amazon Kinesis Data Firehose.
--
--     Create the data firehose with a PUT source and in the region that
--     you are operating. However, if you are capturing logs for Amazon
--     CloudFront, always create the firehose in US East (N. Virginia).
--
--     Do not create the data firehose using a @Kinesis stream@ as your
--     source.
--
-- 2.  Associate that firehose to your web ACL using a
--     @PutLoggingConfiguration@ request.
--
-- When you successfully enable logging using a @PutLoggingConfiguration@
-- request, AWS WAF will create a service linked role with the necessary
-- permissions to write logs to the Amazon Kinesis Data Firehose. For more
-- information, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/logging.html Logging Web ACL Traffic Information>
-- in the /AWS WAF Developer Guide/.
module Amazonka.WAFRegional.PutLoggingConfiguration
  ( -- * Creating a Request
    PutLoggingConfiguration (..),
    newPutLoggingConfiguration,

    -- * Request Lenses
    putLoggingConfiguration_loggingConfiguration,

    -- * Destructuring the Response
    PutLoggingConfigurationResponse (..),
    newPutLoggingConfigurationResponse,

    -- * Response Lenses
    putLoggingConfigurationResponse_loggingConfiguration,
    putLoggingConfigurationResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.WAFRegional.Types

-- | /See:/ 'newPutLoggingConfiguration' smart constructor.
data PutLoggingConfiguration = PutLoggingConfiguration'
  { -- | The Amazon Kinesis Data Firehose that contains the inspected traffic
    -- information, the redacted fields details, and the Amazon Resource Name
    -- (ARN) of the web ACL to monitor.
    --
    -- When specifying @Type@ in @RedactedFields@, you must use one of the
    -- following values: @URI@, @QUERY_STRING@, @HEADER@, or @METHOD@.
    PutLoggingConfiguration -> LoggingConfiguration
loggingConfiguration :: LoggingConfiguration
  }
  deriving (PutLoggingConfiguration -> PutLoggingConfiguration -> Bool
(PutLoggingConfiguration -> PutLoggingConfiguration -> Bool)
-> (PutLoggingConfiguration -> PutLoggingConfiguration -> Bool)
-> Eq PutLoggingConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutLoggingConfiguration -> PutLoggingConfiguration -> Bool
$c/= :: PutLoggingConfiguration -> PutLoggingConfiguration -> Bool
== :: PutLoggingConfiguration -> PutLoggingConfiguration -> Bool
$c== :: PutLoggingConfiguration -> PutLoggingConfiguration -> Bool
Prelude.Eq, ReadPrec [PutLoggingConfiguration]
ReadPrec PutLoggingConfiguration
Int -> ReadS PutLoggingConfiguration
ReadS [PutLoggingConfiguration]
(Int -> ReadS PutLoggingConfiguration)
-> ReadS [PutLoggingConfiguration]
-> ReadPrec PutLoggingConfiguration
-> ReadPrec [PutLoggingConfiguration]
-> Read PutLoggingConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutLoggingConfiguration]
$creadListPrec :: ReadPrec [PutLoggingConfiguration]
readPrec :: ReadPrec PutLoggingConfiguration
$creadPrec :: ReadPrec PutLoggingConfiguration
readList :: ReadS [PutLoggingConfiguration]
$creadList :: ReadS [PutLoggingConfiguration]
readsPrec :: Int -> ReadS PutLoggingConfiguration
$creadsPrec :: Int -> ReadS PutLoggingConfiguration
Prelude.Read, Int -> PutLoggingConfiguration -> ShowS
[PutLoggingConfiguration] -> ShowS
PutLoggingConfiguration -> String
(Int -> PutLoggingConfiguration -> ShowS)
-> (PutLoggingConfiguration -> String)
-> ([PutLoggingConfiguration] -> ShowS)
-> Show PutLoggingConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutLoggingConfiguration] -> ShowS
$cshowList :: [PutLoggingConfiguration] -> ShowS
show :: PutLoggingConfiguration -> String
$cshow :: PutLoggingConfiguration -> String
showsPrec :: Int -> PutLoggingConfiguration -> ShowS
$cshowsPrec :: Int -> PutLoggingConfiguration -> ShowS
Prelude.Show, (forall x.
 PutLoggingConfiguration -> Rep PutLoggingConfiguration x)
-> (forall x.
    Rep PutLoggingConfiguration x -> PutLoggingConfiguration)
-> Generic PutLoggingConfiguration
forall x. Rep PutLoggingConfiguration x -> PutLoggingConfiguration
forall x. PutLoggingConfiguration -> Rep PutLoggingConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutLoggingConfiguration x -> PutLoggingConfiguration
$cfrom :: forall x. PutLoggingConfiguration -> Rep PutLoggingConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'PutLoggingConfiguration' 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:
--
-- 'loggingConfiguration', 'putLoggingConfiguration_loggingConfiguration' - The Amazon Kinesis Data Firehose that contains the inspected traffic
-- information, the redacted fields details, and the Amazon Resource Name
-- (ARN) of the web ACL to monitor.
--
-- When specifying @Type@ in @RedactedFields@, you must use one of the
-- following values: @URI@, @QUERY_STRING@, @HEADER@, or @METHOD@.
newPutLoggingConfiguration ::
  -- | 'loggingConfiguration'
  LoggingConfiguration ->
  PutLoggingConfiguration
newPutLoggingConfiguration :: LoggingConfiguration -> PutLoggingConfiguration
newPutLoggingConfiguration LoggingConfiguration
pLoggingConfiguration_ =
  PutLoggingConfiguration' :: LoggingConfiguration -> PutLoggingConfiguration
PutLoggingConfiguration'
    { $sel:loggingConfiguration:PutLoggingConfiguration' :: LoggingConfiguration
loggingConfiguration =
        LoggingConfiguration
pLoggingConfiguration_
    }

-- | The Amazon Kinesis Data Firehose that contains the inspected traffic
-- information, the redacted fields details, and the Amazon Resource Name
-- (ARN) of the web ACL to monitor.
--
-- When specifying @Type@ in @RedactedFields@, you must use one of the
-- following values: @URI@, @QUERY_STRING@, @HEADER@, or @METHOD@.
putLoggingConfiguration_loggingConfiguration :: Lens.Lens' PutLoggingConfiguration LoggingConfiguration
putLoggingConfiguration_loggingConfiguration :: (LoggingConfiguration -> f LoggingConfiguration)
-> PutLoggingConfiguration -> f PutLoggingConfiguration
putLoggingConfiguration_loggingConfiguration = (PutLoggingConfiguration -> LoggingConfiguration)
-> (PutLoggingConfiguration
    -> LoggingConfiguration -> PutLoggingConfiguration)
-> Lens
     PutLoggingConfiguration
     PutLoggingConfiguration
     LoggingConfiguration
     LoggingConfiguration
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutLoggingConfiguration' {LoggingConfiguration
loggingConfiguration :: LoggingConfiguration
$sel:loggingConfiguration:PutLoggingConfiguration' :: PutLoggingConfiguration -> LoggingConfiguration
loggingConfiguration} -> LoggingConfiguration
loggingConfiguration) (\s :: PutLoggingConfiguration
s@PutLoggingConfiguration' {} LoggingConfiguration
a -> PutLoggingConfiguration
s {$sel:loggingConfiguration:PutLoggingConfiguration' :: LoggingConfiguration
loggingConfiguration = LoggingConfiguration
a} :: PutLoggingConfiguration)

instance Core.AWSRequest PutLoggingConfiguration where
  type
    AWSResponse PutLoggingConfiguration =
      PutLoggingConfigurationResponse
  request :: PutLoggingConfiguration -> Request PutLoggingConfiguration
request = Service
-> PutLoggingConfiguration -> Request PutLoggingConfiguration
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutLoggingConfiguration
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutLoggingConfiguration)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse PutLoggingConfiguration))
-> Logger
-> Service
-> Proxy PutLoggingConfiguration
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutLoggingConfiguration)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe LoggingConfiguration
-> Int -> PutLoggingConfigurationResponse
PutLoggingConfigurationResponse'
            (Maybe LoggingConfiguration
 -> Int -> PutLoggingConfigurationResponse)
-> Either String (Maybe LoggingConfiguration)
-> Either String (Int -> PutLoggingConfigurationResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Key -> Either String (Maybe LoggingConfiguration)
forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Core..?> Key
"LoggingConfiguration")
            Either String (Int -> PutLoggingConfigurationResponse)
-> Either String Int
-> Either String PutLoggingConfigurationResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable PutLoggingConfiguration

instance Prelude.NFData PutLoggingConfiguration

instance Core.ToHeaders PutLoggingConfiguration where
  toHeaders :: PutLoggingConfiguration -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PutLoggingConfiguration -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AWSWAF_Regional_20161128.PutLoggingConfiguration" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON PutLoggingConfiguration where
  toJSON :: PutLoggingConfiguration -> Value
toJSON PutLoggingConfiguration' {LoggingConfiguration
loggingConfiguration :: LoggingConfiguration
$sel:loggingConfiguration:PutLoggingConfiguration' :: PutLoggingConfiguration -> LoggingConfiguration
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Key
"LoggingConfiguration"
                  Key -> LoggingConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Core..= LoggingConfiguration
loggingConfiguration
              )
          ]
      )

instance Core.ToPath PutLoggingConfiguration where
  toPath :: PutLoggingConfiguration -> ByteString
toPath = ByteString -> PutLoggingConfiguration -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery PutLoggingConfiguration where
  toQuery :: PutLoggingConfiguration -> QueryString
toQuery = QueryString -> PutLoggingConfiguration -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newPutLoggingConfigurationResponse' smart constructor.
data PutLoggingConfigurationResponse = PutLoggingConfigurationResponse'
  { -- | The LoggingConfiguration that you submitted in the request.
    PutLoggingConfigurationResponse -> Maybe LoggingConfiguration
loggingConfiguration :: Prelude.Maybe LoggingConfiguration,
    -- | The response's http status code.
    PutLoggingConfigurationResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (PutLoggingConfigurationResponse
-> PutLoggingConfigurationResponse -> Bool
(PutLoggingConfigurationResponse
 -> PutLoggingConfigurationResponse -> Bool)
-> (PutLoggingConfigurationResponse
    -> PutLoggingConfigurationResponse -> Bool)
-> Eq PutLoggingConfigurationResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutLoggingConfigurationResponse
-> PutLoggingConfigurationResponse -> Bool
$c/= :: PutLoggingConfigurationResponse
-> PutLoggingConfigurationResponse -> Bool
== :: PutLoggingConfigurationResponse
-> PutLoggingConfigurationResponse -> Bool
$c== :: PutLoggingConfigurationResponse
-> PutLoggingConfigurationResponse -> Bool
Prelude.Eq, ReadPrec [PutLoggingConfigurationResponse]
ReadPrec PutLoggingConfigurationResponse
Int -> ReadS PutLoggingConfigurationResponse
ReadS [PutLoggingConfigurationResponse]
(Int -> ReadS PutLoggingConfigurationResponse)
-> ReadS [PutLoggingConfigurationResponse]
-> ReadPrec PutLoggingConfigurationResponse
-> ReadPrec [PutLoggingConfigurationResponse]
-> Read PutLoggingConfigurationResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutLoggingConfigurationResponse]
$creadListPrec :: ReadPrec [PutLoggingConfigurationResponse]
readPrec :: ReadPrec PutLoggingConfigurationResponse
$creadPrec :: ReadPrec PutLoggingConfigurationResponse
readList :: ReadS [PutLoggingConfigurationResponse]
$creadList :: ReadS [PutLoggingConfigurationResponse]
readsPrec :: Int -> ReadS PutLoggingConfigurationResponse
$creadsPrec :: Int -> ReadS PutLoggingConfigurationResponse
Prelude.Read, Int -> PutLoggingConfigurationResponse -> ShowS
[PutLoggingConfigurationResponse] -> ShowS
PutLoggingConfigurationResponse -> String
(Int -> PutLoggingConfigurationResponse -> ShowS)
-> (PutLoggingConfigurationResponse -> String)
-> ([PutLoggingConfigurationResponse] -> ShowS)
-> Show PutLoggingConfigurationResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutLoggingConfigurationResponse] -> ShowS
$cshowList :: [PutLoggingConfigurationResponse] -> ShowS
show :: PutLoggingConfigurationResponse -> String
$cshow :: PutLoggingConfigurationResponse -> String
showsPrec :: Int -> PutLoggingConfigurationResponse -> ShowS
$cshowsPrec :: Int -> PutLoggingConfigurationResponse -> ShowS
Prelude.Show, (forall x.
 PutLoggingConfigurationResponse
 -> Rep PutLoggingConfigurationResponse x)
-> (forall x.
    Rep PutLoggingConfigurationResponse x
    -> PutLoggingConfigurationResponse)
-> Generic PutLoggingConfigurationResponse
forall x.
Rep PutLoggingConfigurationResponse x
-> PutLoggingConfigurationResponse
forall x.
PutLoggingConfigurationResponse
-> Rep PutLoggingConfigurationResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PutLoggingConfigurationResponse x
-> PutLoggingConfigurationResponse
$cfrom :: forall x.
PutLoggingConfigurationResponse
-> Rep PutLoggingConfigurationResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutLoggingConfigurationResponse' 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:
--
-- 'loggingConfiguration', 'putLoggingConfigurationResponse_loggingConfiguration' - The LoggingConfiguration that you submitted in the request.
--
-- 'httpStatus', 'putLoggingConfigurationResponse_httpStatus' - The response's http status code.
newPutLoggingConfigurationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutLoggingConfigurationResponse
newPutLoggingConfigurationResponse :: Int -> PutLoggingConfigurationResponse
newPutLoggingConfigurationResponse Int
pHttpStatus_ =
  PutLoggingConfigurationResponse' :: Maybe LoggingConfiguration
-> Int -> PutLoggingConfigurationResponse
PutLoggingConfigurationResponse'
    { $sel:loggingConfiguration:PutLoggingConfigurationResponse' :: Maybe LoggingConfiguration
loggingConfiguration =
        Maybe LoggingConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutLoggingConfigurationResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The LoggingConfiguration that you submitted in the request.
putLoggingConfigurationResponse_loggingConfiguration :: Lens.Lens' PutLoggingConfigurationResponse (Prelude.Maybe LoggingConfiguration)
putLoggingConfigurationResponse_loggingConfiguration :: (Maybe LoggingConfiguration -> f (Maybe LoggingConfiguration))
-> PutLoggingConfigurationResponse
-> f PutLoggingConfigurationResponse
putLoggingConfigurationResponse_loggingConfiguration = (PutLoggingConfigurationResponse -> Maybe LoggingConfiguration)
-> (PutLoggingConfigurationResponse
    -> Maybe LoggingConfiguration -> PutLoggingConfigurationResponse)
-> Lens
     PutLoggingConfigurationResponse
     PutLoggingConfigurationResponse
     (Maybe LoggingConfiguration)
     (Maybe LoggingConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutLoggingConfigurationResponse' {Maybe LoggingConfiguration
loggingConfiguration :: Maybe LoggingConfiguration
$sel:loggingConfiguration:PutLoggingConfigurationResponse' :: PutLoggingConfigurationResponse -> Maybe LoggingConfiguration
loggingConfiguration} -> Maybe LoggingConfiguration
loggingConfiguration) (\s :: PutLoggingConfigurationResponse
s@PutLoggingConfigurationResponse' {} Maybe LoggingConfiguration
a -> PutLoggingConfigurationResponse
s {$sel:loggingConfiguration:PutLoggingConfigurationResponse' :: Maybe LoggingConfiguration
loggingConfiguration = Maybe LoggingConfiguration
a} :: PutLoggingConfigurationResponse)

-- | The response's http status code.
putLoggingConfigurationResponse_httpStatus :: Lens.Lens' PutLoggingConfigurationResponse Prelude.Int
putLoggingConfigurationResponse_httpStatus :: (Int -> f Int)
-> PutLoggingConfigurationResponse
-> f PutLoggingConfigurationResponse
putLoggingConfigurationResponse_httpStatus = (PutLoggingConfigurationResponse -> Int)
-> (PutLoggingConfigurationResponse
    -> Int -> PutLoggingConfigurationResponse)
-> Lens
     PutLoggingConfigurationResponse
     PutLoggingConfigurationResponse
     Int
     Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutLoggingConfigurationResponse' {Int
httpStatus :: Int
$sel:httpStatus:PutLoggingConfigurationResponse' :: PutLoggingConfigurationResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: PutLoggingConfigurationResponse
s@PutLoggingConfigurationResponse' {} Int
a -> PutLoggingConfigurationResponse
s {$sel:httpStatus:PutLoggingConfigurationResponse' :: Int
httpStatus = Int
a} :: PutLoggingConfigurationResponse)

instance
  Prelude.NFData
    PutLoggingConfigurationResponse