{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $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 :: Lens' PutLoggingConfiguration LoggingConfiguration
putLoggingConfiguration_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 :: (Service -> Service)
-> PutLoggingConfiguration -> Request PutLoggingConfiguration
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy PutLoggingConfiguration
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutLoggingConfiguration)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe LoggingConfiguration
-> Int -> PutLoggingConfigurationResponse
PutLoggingConfigurationResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"LoggingConfiguration")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable PutLoggingConfiguration where
  hashWithSalt :: Int -> PutLoggingConfiguration -> Int
hashWithSalt Int
_salt PutLoggingConfiguration' {LoggingConfiguration
loggingConfiguration :: LoggingConfiguration
$sel:loggingConfiguration:PutLoggingConfiguration' :: PutLoggingConfiguration -> LoggingConfiguration
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` LoggingConfiguration
loggingConfiguration

instance Prelude.NFData PutLoggingConfiguration where
  rnf :: PutLoggingConfiguration -> ()
rnf PutLoggingConfiguration' {LoggingConfiguration
loggingConfiguration :: LoggingConfiguration
$sel:loggingConfiguration:PutLoggingConfiguration' :: PutLoggingConfiguration -> LoggingConfiguration
..} =
    forall a. NFData a => a -> ()
Prelude.rnf LoggingConfiguration
loggingConfiguration

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

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

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

instance Data.ToQuery PutLoggingConfiguration where
  toQuery :: PutLoggingConfiguration -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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.
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'
    { $sel:loggingConfiguration:PutLoggingConfigurationResponse' :: Maybe LoggingConfiguration
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 :: Lens' PutLoggingConfigurationResponse (Maybe LoggingConfiguration)
putLoggingConfigurationResponse_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 :: Lens' PutLoggingConfigurationResponse Int
putLoggingConfigurationResponse_httpStatus = 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
  where
  rnf :: PutLoggingConfigurationResponse -> ()
rnf PutLoggingConfigurationResponse' {Int
Maybe LoggingConfiguration
httpStatus :: Int
loggingConfiguration :: Maybe LoggingConfiguration
$sel:httpStatus:PutLoggingConfigurationResponse' :: PutLoggingConfigurationResponse -> Int
$sel:loggingConfiguration:PutLoggingConfigurationResponse' :: PutLoggingConfigurationResponse -> Maybe LoggingConfiguration
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe LoggingConfiguration
loggingConfiguration
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus