{-# 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.WAFV2.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)
--
-- Enables the specified LoggingConfiguration, to start logging from a web
-- ACL, according to the configuration provided.
--
-- 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/.
--
-- This operation completely replaces the mutable specifications that you
-- already have for the logging configuration with the ones that you
-- provide to this call. To modify the logging configuration, retrieve it
-- by calling GetLoggingConfiguration, update the settings as needed, and
-- then provide the complete logging configuration specification to this
-- call.
module Amazonka.WAFV2.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.WAFV2.Types

-- | /See:/ 'newPutLoggingConfiguration' smart constructor.
data PutLoggingConfiguration = PutLoggingConfiguration'
  { 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' -
newPutLoggingConfiguration ::
  -- | 'loggingConfiguration'
  LoggingConfiguration ->
  PutLoggingConfiguration
newPutLoggingConfiguration :: LoggingConfiguration -> PutLoggingConfiguration
newPutLoggingConfiguration LoggingConfiguration
pLoggingConfiguration_ =
  PutLoggingConfiguration'
    { $sel:loggingConfiguration:PutLoggingConfiguration' :: LoggingConfiguration
loggingConfiguration =
        LoggingConfiguration
pLoggingConfiguration_
    }

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_20190729.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'
  { 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' -
--
-- '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_
    }

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