{-# 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.Lightsail.Types.BucketAccessLogConfig
-- 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.Lightsail.Types.BucketAccessLogConfig 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

-- | Describes the access log configuration for a bucket in the Amazon
-- Lightsail object storage service.
--
-- For more information about bucket access logs, see
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-bucket-access-logs Logging bucket requests using access logging in Amazon Lightsail>
-- in the /Amazon Lightsail Developer Guide/.
--
-- /See:/ 'newBucketAccessLogConfig' smart constructor.
data BucketAccessLogConfig = BucketAccessLogConfig'
  { -- | The name of the bucket where the access logs are saved. The destination
    -- can be a Lightsail bucket in the same account, and in the same Amazon
    -- Web Services Region as the source bucket.
    --
    -- This parameter is required when enabling the access log for a bucket,
    -- and should be omitted when disabling the access log.
    BucketAccessLogConfig -> Maybe Text
destination :: Prelude.Maybe Prelude.Text,
    -- | The optional object prefix for the bucket access log.
    --
    -- The prefix is an optional addition to the object key that organizes your
    -- access log files in the destination bucket. For example, if you specify
    -- a @logs\/@ prefix, then each log object will begin with the @logs\/@
    -- prefix in its key (for example,
    -- @logs\/2021-11-01-21-32-16-E568B2907131C0C0@).
    --
    -- This parameter can be optionally specified when enabling the access log
    -- for a bucket, and should be omitted when disabling the access log.
    BucketAccessLogConfig -> Maybe Text
prefix :: Prelude.Maybe Prelude.Text,
    -- | A Boolean value that indicates whether bucket access logging is enabled
    -- for the bucket.
    BucketAccessLogConfig -> Bool
enabled :: Prelude.Bool
  }
  deriving (BucketAccessLogConfig -> BucketAccessLogConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BucketAccessLogConfig -> BucketAccessLogConfig -> Bool
$c/= :: BucketAccessLogConfig -> BucketAccessLogConfig -> Bool
== :: BucketAccessLogConfig -> BucketAccessLogConfig -> Bool
$c== :: BucketAccessLogConfig -> BucketAccessLogConfig -> Bool
Prelude.Eq, ReadPrec [BucketAccessLogConfig]
ReadPrec BucketAccessLogConfig
Int -> ReadS BucketAccessLogConfig
ReadS [BucketAccessLogConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BucketAccessLogConfig]
$creadListPrec :: ReadPrec [BucketAccessLogConfig]
readPrec :: ReadPrec BucketAccessLogConfig
$creadPrec :: ReadPrec BucketAccessLogConfig
readList :: ReadS [BucketAccessLogConfig]
$creadList :: ReadS [BucketAccessLogConfig]
readsPrec :: Int -> ReadS BucketAccessLogConfig
$creadsPrec :: Int -> ReadS BucketAccessLogConfig
Prelude.Read, Int -> BucketAccessLogConfig -> ShowS
[BucketAccessLogConfig] -> ShowS
BucketAccessLogConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BucketAccessLogConfig] -> ShowS
$cshowList :: [BucketAccessLogConfig] -> ShowS
show :: BucketAccessLogConfig -> String
$cshow :: BucketAccessLogConfig -> String
showsPrec :: Int -> BucketAccessLogConfig -> ShowS
$cshowsPrec :: Int -> BucketAccessLogConfig -> ShowS
Prelude.Show, forall x. Rep BucketAccessLogConfig x -> BucketAccessLogConfig
forall x. BucketAccessLogConfig -> Rep BucketAccessLogConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BucketAccessLogConfig x -> BucketAccessLogConfig
$cfrom :: forall x. BucketAccessLogConfig -> Rep BucketAccessLogConfig x
Prelude.Generic)

-- |
-- Create a value of 'BucketAccessLogConfig' 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:
--
-- 'destination', 'bucketAccessLogConfig_destination' - The name of the bucket where the access logs are saved. The destination
-- can be a Lightsail bucket in the same account, and in the same Amazon
-- Web Services Region as the source bucket.
--
-- This parameter is required when enabling the access log for a bucket,
-- and should be omitted when disabling the access log.
--
-- 'prefix', 'bucketAccessLogConfig_prefix' - The optional object prefix for the bucket access log.
--
-- The prefix is an optional addition to the object key that organizes your
-- access log files in the destination bucket. For example, if you specify
-- a @logs\/@ prefix, then each log object will begin with the @logs\/@
-- prefix in its key (for example,
-- @logs\/2021-11-01-21-32-16-E568B2907131C0C0@).
--
-- This parameter can be optionally specified when enabling the access log
-- for a bucket, and should be omitted when disabling the access log.
--
-- 'enabled', 'bucketAccessLogConfig_enabled' - A Boolean value that indicates whether bucket access logging is enabled
-- for the bucket.
newBucketAccessLogConfig ::
  -- | 'enabled'
  Prelude.Bool ->
  BucketAccessLogConfig
newBucketAccessLogConfig :: Bool -> BucketAccessLogConfig
newBucketAccessLogConfig Bool
pEnabled_ =
  BucketAccessLogConfig'
    { $sel:destination:BucketAccessLogConfig' :: Maybe Text
destination =
        forall a. Maybe a
Prelude.Nothing,
      $sel:prefix:BucketAccessLogConfig' :: Maybe Text
prefix = forall a. Maybe a
Prelude.Nothing,
      $sel:enabled:BucketAccessLogConfig' :: Bool
enabled = Bool
pEnabled_
    }

-- | The name of the bucket where the access logs are saved. The destination
-- can be a Lightsail bucket in the same account, and in the same Amazon
-- Web Services Region as the source bucket.
--
-- This parameter is required when enabling the access log for a bucket,
-- and should be omitted when disabling the access log.
bucketAccessLogConfig_destination :: Lens.Lens' BucketAccessLogConfig (Prelude.Maybe Prelude.Text)
bucketAccessLogConfig_destination :: Lens' BucketAccessLogConfig (Maybe Text)
bucketAccessLogConfig_destination = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BucketAccessLogConfig' {Maybe Text
destination :: Maybe Text
$sel:destination:BucketAccessLogConfig' :: BucketAccessLogConfig -> Maybe Text
destination} -> Maybe Text
destination) (\s :: BucketAccessLogConfig
s@BucketAccessLogConfig' {} Maybe Text
a -> BucketAccessLogConfig
s {$sel:destination:BucketAccessLogConfig' :: Maybe Text
destination = Maybe Text
a} :: BucketAccessLogConfig)

-- | The optional object prefix for the bucket access log.
--
-- The prefix is an optional addition to the object key that organizes your
-- access log files in the destination bucket. For example, if you specify
-- a @logs\/@ prefix, then each log object will begin with the @logs\/@
-- prefix in its key (for example,
-- @logs\/2021-11-01-21-32-16-E568B2907131C0C0@).
--
-- This parameter can be optionally specified when enabling the access log
-- for a bucket, and should be omitted when disabling the access log.
bucketAccessLogConfig_prefix :: Lens.Lens' BucketAccessLogConfig (Prelude.Maybe Prelude.Text)
bucketAccessLogConfig_prefix :: Lens' BucketAccessLogConfig (Maybe Text)
bucketAccessLogConfig_prefix = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BucketAccessLogConfig' {Maybe Text
prefix :: Maybe Text
$sel:prefix:BucketAccessLogConfig' :: BucketAccessLogConfig -> Maybe Text
prefix} -> Maybe Text
prefix) (\s :: BucketAccessLogConfig
s@BucketAccessLogConfig' {} Maybe Text
a -> BucketAccessLogConfig
s {$sel:prefix:BucketAccessLogConfig' :: Maybe Text
prefix = Maybe Text
a} :: BucketAccessLogConfig)

-- | A Boolean value that indicates whether bucket access logging is enabled
-- for the bucket.
bucketAccessLogConfig_enabled :: Lens.Lens' BucketAccessLogConfig Prelude.Bool
bucketAccessLogConfig_enabled :: Lens' BucketAccessLogConfig Bool
bucketAccessLogConfig_enabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BucketAccessLogConfig' {Bool
enabled :: Bool
$sel:enabled:BucketAccessLogConfig' :: BucketAccessLogConfig -> Bool
enabled} -> Bool
enabled) (\s :: BucketAccessLogConfig
s@BucketAccessLogConfig' {} Bool
a -> BucketAccessLogConfig
s {$sel:enabled:BucketAccessLogConfig' :: Bool
enabled = Bool
a} :: BucketAccessLogConfig)

instance Data.FromJSON BucketAccessLogConfig where
  parseJSON :: Value -> Parser BucketAccessLogConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"BucketAccessLogConfig"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Bool -> BucketAccessLogConfig
BucketAccessLogConfig'
            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
"destination")
            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
"prefix")
            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
"enabled")
      )

instance Prelude.Hashable BucketAccessLogConfig where
  hashWithSalt :: Int -> BucketAccessLogConfig -> Int
hashWithSalt Int
_salt BucketAccessLogConfig' {Bool
Maybe Text
enabled :: Bool
prefix :: Maybe Text
destination :: Maybe Text
$sel:enabled:BucketAccessLogConfig' :: BucketAccessLogConfig -> Bool
$sel:prefix:BucketAccessLogConfig' :: BucketAccessLogConfig -> Maybe Text
$sel:destination:BucketAccessLogConfig' :: BucketAccessLogConfig -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
destination
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
prefix
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Bool
enabled

instance Prelude.NFData BucketAccessLogConfig where
  rnf :: BucketAccessLogConfig -> ()
rnf BucketAccessLogConfig' {Bool
Maybe Text
enabled :: Bool
prefix :: Maybe Text
destination :: Maybe Text
$sel:enabled:BucketAccessLogConfig' :: BucketAccessLogConfig -> Bool
$sel:prefix:BucketAccessLogConfig' :: BucketAccessLogConfig -> Maybe Text
$sel:destination:BucketAccessLogConfig' :: BucketAccessLogConfig -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
destination
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
prefix
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Bool
enabled

instance Data.ToJSON BucketAccessLogConfig where
  toJSON :: BucketAccessLogConfig -> Value
toJSON BucketAccessLogConfig' {Bool
Maybe Text
enabled :: Bool
prefix :: Maybe Text
destination :: Maybe Text
$sel:enabled:BucketAccessLogConfig' :: BucketAccessLogConfig -> Bool
$sel:prefix:BucketAccessLogConfig' :: BucketAccessLogConfig -> Maybe Text
$sel:destination:BucketAccessLogConfig' :: BucketAccessLogConfig -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"destination" 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 Text
destination,
            (Key
"prefix" 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 Text
prefix,
            forall a. a -> Maybe a
Prelude.Just (Key
"enabled" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Bool
enabled)
          ]
      )