{-# 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-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)
module Amazonka.S3.Types.LoggingEnabled where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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.
    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
(LoggingEnabled -> LoggingEnabled -> Bool)
-> (LoggingEnabled -> LoggingEnabled -> Bool) -> Eq LoggingEnabled
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]
(Int -> ReadS LoggingEnabled)
-> ReadS [LoggingEnabled]
-> ReadPrec LoggingEnabled
-> ReadPrec [LoggingEnabled]
-> Read 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
(Int -> LoggingEnabled -> ShowS)
-> (LoggingEnabled -> String)
-> ([LoggingEnabled] -> ShowS)
-> Show LoggingEnabled
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. LoggingEnabled -> Rep LoggingEnabled x)
-> (forall x. Rep LoggingEnabled x -> LoggingEnabled)
-> Generic LoggingEnabled
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.
--
-- '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' :: Maybe [TargetGrant] -> Text -> Text -> LoggingEnabled
LoggingEnabled'
    { $sel:targetGrants:LoggingEnabled' :: Maybe [TargetGrant]
targetGrants = Maybe [TargetGrant]
forall a. Maybe a
Prelude.Nothing,
      $sel:targetBucket:LoggingEnabled' :: Text
targetBucket = Text
pTargetBucket_,
      $sel:targetPrefix:LoggingEnabled' :: Text
targetPrefix = Text
pTargetPrefix_
    }

-- | Container for granting information.
loggingEnabled_targetGrants :: Lens.Lens' LoggingEnabled (Prelude.Maybe [TargetGrant])
loggingEnabled_targetGrants :: (Maybe [TargetGrant] -> f (Maybe [TargetGrant]))
-> LoggingEnabled -> f LoggingEnabled
loggingEnabled_targetGrants = (LoggingEnabled -> Maybe [TargetGrant])
-> (LoggingEnabled -> Maybe [TargetGrant] -> LoggingEnabled)
-> Lens
     LoggingEnabled
     LoggingEnabled
     (Maybe [TargetGrant])
     (Maybe [TargetGrant])
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) ((Maybe [TargetGrant] -> f (Maybe [TargetGrant]))
 -> LoggingEnabled -> f LoggingEnabled)
-> ((Maybe [TargetGrant] -> f (Maybe [TargetGrant]))
    -> Maybe [TargetGrant] -> f (Maybe [TargetGrant]))
-> (Maybe [TargetGrant] -> f (Maybe [TargetGrant]))
-> LoggingEnabled
-> f LoggingEnabled
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [TargetGrant] [TargetGrant] [TargetGrant] [TargetGrant]
-> Iso
     (Maybe [TargetGrant])
     (Maybe [TargetGrant])
     (Maybe [TargetGrant])
     (Maybe [TargetGrant])
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 AnIso [TargetGrant] [TargetGrant] [TargetGrant] [TargetGrant]
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 :: (Text -> f Text) -> LoggingEnabled -> f LoggingEnabled
loggingEnabled_targetBucket = (LoggingEnabled -> Text)
-> (LoggingEnabled -> Text -> LoggingEnabled)
-> Lens LoggingEnabled LoggingEnabled Text Text
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 :: (Text -> f Text) -> LoggingEnabled -> f LoggingEnabled
loggingEnabled_targetPrefix = (LoggingEnabled -> Text)
-> (LoggingEnabled -> Text -> LoggingEnabled)
-> Lens LoggingEnabled LoggingEnabled Text Text
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 Core.FromXML LoggingEnabled where
  parseXML :: [Node] -> Either String LoggingEnabled
parseXML [Node]
x =
    Maybe [TargetGrant] -> Text -> Text -> LoggingEnabled
LoggingEnabled'
      (Maybe [TargetGrant] -> Text -> Text -> LoggingEnabled)
-> Either String (Maybe [TargetGrant])
-> Either String (Text -> Text -> LoggingEnabled)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"TargetGrants" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [TargetGrant]))
-> Either String (Maybe [TargetGrant])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [TargetGrant])
-> [Node] -> Either String (Maybe [TargetGrant])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [TargetGrant]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"Grant")
                  )
      Either String (Text -> Text -> LoggingEnabled)
-> Either String Text -> Either String (Text -> LoggingEnabled)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"TargetBucket")
      Either String (Text -> LoggingEnabled)
-> Either String Text -> Either String LoggingEnabled
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"TargetPrefix")

instance Prelude.Hashable LoggingEnabled

instance Prelude.NFData LoggingEnabled

instance Core.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]
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"TargetGrants"
          Name -> XML -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe XML -> XML
forall a. ToXML a => a -> XML
Core.toXML
            (Name -> [TargetGrant] -> XML
forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Core.toXMLList Name
"Grant" ([TargetGrant] -> XML) -> Maybe [TargetGrant] -> Maybe XML
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [TargetGrant]
targetGrants),
        Name
"TargetBucket" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
targetBucket,
        Name
"TargetPrefix" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
targetPrefix
      ]