{-# 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.S3.Types.LoggingEnabled
-- 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.S3.Types.LoggingEnabled 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 Amazonka.S3.Internal
import Amazonka.S3.Types.TargetGrant

-- | Describes where logs are stored and the prefix that Amazon S3 assigns to
-- all log object keys for a bucket. For more information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTlogging.html PUT Bucket logging>
-- in the /Amazon S3 API Reference/.
--
-- /See:/ 'newLoggingEnabled' smart constructor.
data LoggingEnabled = LoggingEnabled'
  { -- | Container for granting information.
    --
    -- Buckets that use the bucket owner enforced setting for Object Ownership
    -- don\'t support target grants. For more information, see
    -- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/enable-server-access-logging.html#grant-log-delivery-permissions-general Permissions for server access log delivery>
    -- in the /Amazon S3 User Guide/.
    LoggingEnabled -> Maybe [TargetGrant]
targetGrants :: Prelude.Maybe [TargetGrant],
    -- | Specifies the bucket where you want Amazon S3 to store server access
    -- logs. You can have your logs delivered to any bucket that you own,
    -- including the same bucket that is being logged. You can also configure
    -- multiple buckets to deliver their logs to the same target bucket. In
    -- this case, you should choose a different @TargetPrefix@ for each source
    -- bucket so that the delivered log files can be distinguished by key.
    LoggingEnabled -> Text
targetBucket :: Prelude.Text,
    -- | A prefix for all log object keys. If you store log files from multiple
    -- Amazon S3 buckets in a single bucket, you can use a prefix to
    -- distinguish which log files came from which bucket.
    LoggingEnabled -> Text
targetPrefix :: Prelude.Text
  }
  deriving (LoggingEnabled -> LoggingEnabled -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LoggingEnabled -> LoggingEnabled -> Bool
$c/= :: LoggingEnabled -> LoggingEnabled -> Bool
== :: LoggingEnabled -> LoggingEnabled -> Bool
$c== :: LoggingEnabled -> LoggingEnabled -> Bool
Prelude.Eq, ReadPrec [LoggingEnabled]
ReadPrec LoggingEnabled
Int -> ReadS LoggingEnabled
ReadS [LoggingEnabled]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LoggingEnabled]
$creadListPrec :: ReadPrec [LoggingEnabled]
readPrec :: ReadPrec LoggingEnabled
$creadPrec :: ReadPrec LoggingEnabled
readList :: ReadS [LoggingEnabled]
$creadList :: ReadS [LoggingEnabled]
readsPrec :: Int -> ReadS LoggingEnabled
$creadsPrec :: Int -> ReadS LoggingEnabled
Prelude.Read, Int -> LoggingEnabled -> ShowS
[LoggingEnabled] -> ShowS
LoggingEnabled -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LoggingEnabled] -> ShowS
$cshowList :: [LoggingEnabled] -> ShowS
show :: LoggingEnabled -> String
$cshow :: LoggingEnabled -> String
showsPrec :: Int -> LoggingEnabled -> ShowS
$cshowsPrec :: Int -> LoggingEnabled -> ShowS
Prelude.Show, forall x. Rep LoggingEnabled x -> LoggingEnabled
forall x. LoggingEnabled -> Rep LoggingEnabled x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LoggingEnabled x -> LoggingEnabled
$cfrom :: forall x. LoggingEnabled -> Rep LoggingEnabled x
Prelude.Generic)

-- |
-- Create a value of 'LoggingEnabled' 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:
--
-- 'targetGrants', 'loggingEnabled_targetGrants' - Container for granting information.
--
-- Buckets that use the bucket owner enforced setting for Object Ownership
-- don\'t support target grants. For more information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/enable-server-access-logging.html#grant-log-delivery-permissions-general Permissions for server access log delivery>
-- in the /Amazon S3 User Guide/.
--
-- 'targetBucket', 'loggingEnabled_targetBucket' - Specifies the bucket where you want Amazon S3 to store server access
-- logs. You can have your logs delivered to any bucket that you own,
-- including the same bucket that is being logged. You can also configure
-- multiple buckets to deliver their logs to the same target bucket. In
-- this case, you should choose a different @TargetPrefix@ for each source
-- bucket so that the delivered log files can be distinguished by key.
--
-- 'targetPrefix', 'loggingEnabled_targetPrefix' - A prefix for all log object keys. If you store log files from multiple
-- Amazon S3 buckets in a single bucket, you can use a prefix to
-- distinguish which log files came from which bucket.
newLoggingEnabled ::
  -- | 'targetBucket'
  Prelude.Text ->
  -- | 'targetPrefix'
  Prelude.Text ->
  LoggingEnabled
newLoggingEnabled :: Text -> Text -> LoggingEnabled
newLoggingEnabled Text
pTargetBucket_ Text
pTargetPrefix_ =
  LoggingEnabled'
    { $sel:targetGrants:LoggingEnabled' :: Maybe [TargetGrant]
targetGrants = forall a. Maybe a
Prelude.Nothing,
      $sel:targetBucket:LoggingEnabled' :: Text
targetBucket = Text
pTargetBucket_,
      $sel:targetPrefix:LoggingEnabled' :: Text
targetPrefix = Text
pTargetPrefix_
    }

-- | Container for granting information.
--
-- Buckets that use the bucket owner enforced setting for Object Ownership
-- don\'t support target grants. For more information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/enable-server-access-logging.html#grant-log-delivery-permissions-general Permissions for server access log delivery>
-- in the /Amazon S3 User Guide/.
loggingEnabled_targetGrants :: Lens.Lens' LoggingEnabled (Prelude.Maybe [TargetGrant])
loggingEnabled_targetGrants :: Lens' LoggingEnabled (Maybe [TargetGrant])
loggingEnabled_targetGrants = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoggingEnabled' {Maybe [TargetGrant]
targetGrants :: Maybe [TargetGrant]
$sel:targetGrants:LoggingEnabled' :: LoggingEnabled -> Maybe [TargetGrant]
targetGrants} -> Maybe [TargetGrant]
targetGrants) (\s :: LoggingEnabled
s@LoggingEnabled' {} Maybe [TargetGrant]
a -> LoggingEnabled
s {$sel:targetGrants:LoggingEnabled' :: Maybe [TargetGrant]
targetGrants = Maybe [TargetGrant]
a} :: LoggingEnabled) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Specifies the bucket where you want Amazon S3 to store server access
-- logs. You can have your logs delivered to any bucket that you own,
-- including the same bucket that is being logged. You can also configure
-- multiple buckets to deliver their logs to the same target bucket. In
-- this case, you should choose a different @TargetPrefix@ for each source
-- bucket so that the delivered log files can be distinguished by key.
loggingEnabled_targetBucket :: Lens.Lens' LoggingEnabled Prelude.Text
loggingEnabled_targetBucket :: Lens' LoggingEnabled Text
loggingEnabled_targetBucket = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoggingEnabled' {Text
targetBucket :: Text
$sel:targetBucket:LoggingEnabled' :: LoggingEnabled -> Text
targetBucket} -> Text
targetBucket) (\s :: LoggingEnabled
s@LoggingEnabled' {} Text
a -> LoggingEnabled
s {$sel:targetBucket:LoggingEnabled' :: Text
targetBucket = Text
a} :: LoggingEnabled)

-- | A prefix for all log object keys. If you store log files from multiple
-- Amazon S3 buckets in a single bucket, you can use a prefix to
-- distinguish which log files came from which bucket.
loggingEnabled_targetPrefix :: Lens.Lens' LoggingEnabled Prelude.Text
loggingEnabled_targetPrefix :: Lens' LoggingEnabled Text
loggingEnabled_targetPrefix = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoggingEnabled' {Text
targetPrefix :: Text
$sel:targetPrefix:LoggingEnabled' :: LoggingEnabled -> Text
targetPrefix} -> Text
targetPrefix) (\s :: LoggingEnabled
s@LoggingEnabled' {} Text
a -> LoggingEnabled
s {$sel:targetPrefix:LoggingEnabled' :: Text
targetPrefix = Text
a} :: LoggingEnabled)

instance Data.FromXML LoggingEnabled where
  parseXML :: [Node] -> Either String LoggingEnabled
parseXML [Node]
x =
    Maybe [TargetGrant] -> Text -> Text -> LoggingEnabled
LoggingEnabled'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x
                      forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"TargetGrants"
                      forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                      forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"Grant")
                  )
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"TargetBucket")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"TargetPrefix")

instance Prelude.Hashable LoggingEnabled where
  hashWithSalt :: Int -> LoggingEnabled -> Int
hashWithSalt Int
_salt LoggingEnabled' {Maybe [TargetGrant]
Text
targetPrefix :: Text
targetBucket :: Text
targetGrants :: Maybe [TargetGrant]
$sel:targetPrefix:LoggingEnabled' :: LoggingEnabled -> Text
$sel:targetBucket:LoggingEnabled' :: LoggingEnabled -> Text
$sel:targetGrants:LoggingEnabled' :: LoggingEnabled -> Maybe [TargetGrant]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [TargetGrant]
targetGrants
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
targetBucket
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
targetPrefix

instance Prelude.NFData LoggingEnabled where
  rnf :: LoggingEnabled -> ()
rnf LoggingEnabled' {Maybe [TargetGrant]
Text
targetPrefix :: Text
targetBucket :: Text
targetGrants :: Maybe [TargetGrant]
$sel:targetPrefix:LoggingEnabled' :: LoggingEnabled -> Text
$sel:targetBucket:LoggingEnabled' :: LoggingEnabled -> Text
$sel:targetGrants:LoggingEnabled' :: LoggingEnabled -> Maybe [TargetGrant]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [TargetGrant]
targetGrants
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
targetBucket
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
targetPrefix

instance Data.ToXML LoggingEnabled where
  toXML :: LoggingEnabled -> XML
toXML LoggingEnabled' {Maybe [TargetGrant]
Text
targetPrefix :: Text
targetBucket :: Text
targetGrants :: Maybe [TargetGrant]
$sel:targetPrefix:LoggingEnabled' :: LoggingEnabled -> Text
$sel:targetBucket:LoggingEnabled' :: LoggingEnabled -> Text
$sel:targetGrants:LoggingEnabled' :: LoggingEnabled -> Maybe [TargetGrant]
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"TargetGrants"
          forall a. ToXML a => Name -> a -> XML
Data.@= forall a. ToXML a => a -> XML
Data.toXML
            (forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Data.toXMLList Name
"Grant" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [TargetGrant]
targetGrants),
        Name
"TargetBucket" forall a. ToXML a => Name -> a -> XML
Data.@= Text
targetBucket,
        Name
"TargetPrefix" forall a. ToXML a => Name -> a -> XML
Data.@= Text
targetPrefix
      ]