{-# 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.CloudFront.Types.StreamingLoggingConfig
-- 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.CloudFront.Types.StreamingLoggingConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A complex type that controls whether access logs are written for this
-- streaming distribution.
--
-- /See:/ 'newStreamingLoggingConfig' smart constructor.
data StreamingLoggingConfig = StreamingLoggingConfig'
  { -- | Specifies whether you want CloudFront to save access logs to an Amazon
    -- S3 bucket. If you don\'t want to enable logging when you create a
    -- streaming distribution or if you want to disable logging for an existing
    -- streaming distribution, specify @false@ for @Enabled@, and specify
    -- @empty Bucket@ and @Prefix@ elements. If you specify @false@ for
    -- @Enabled@ but you specify values for @Bucket@ and @Prefix@, the values
    -- are automatically deleted.
    StreamingLoggingConfig -> Bool
enabled :: Prelude.Bool,
    -- | The Amazon S3 bucket to store the access logs in, for example,
    -- @myawslogbucket.s3.amazonaws.com@.
    StreamingLoggingConfig -> Text
bucket :: Prelude.Text,
    -- | An optional string that you want CloudFront to prefix to the access log
    -- filenames for this streaming distribution, for example, @myprefix\/@. If
    -- you want to enable logging, but you don\'t want to specify a prefix, you
    -- still must include an empty @Prefix@ element in the @Logging@ element.
    StreamingLoggingConfig -> Text
prefix :: Prelude.Text
  }
  deriving (StreamingLoggingConfig -> StreamingLoggingConfig -> Bool
(StreamingLoggingConfig -> StreamingLoggingConfig -> Bool)
-> (StreamingLoggingConfig -> StreamingLoggingConfig -> Bool)
-> Eq StreamingLoggingConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StreamingLoggingConfig -> StreamingLoggingConfig -> Bool
$c/= :: StreamingLoggingConfig -> StreamingLoggingConfig -> Bool
== :: StreamingLoggingConfig -> StreamingLoggingConfig -> Bool
$c== :: StreamingLoggingConfig -> StreamingLoggingConfig -> Bool
Prelude.Eq, ReadPrec [StreamingLoggingConfig]
ReadPrec StreamingLoggingConfig
Int -> ReadS StreamingLoggingConfig
ReadS [StreamingLoggingConfig]
(Int -> ReadS StreamingLoggingConfig)
-> ReadS [StreamingLoggingConfig]
-> ReadPrec StreamingLoggingConfig
-> ReadPrec [StreamingLoggingConfig]
-> Read StreamingLoggingConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StreamingLoggingConfig]
$creadListPrec :: ReadPrec [StreamingLoggingConfig]
readPrec :: ReadPrec StreamingLoggingConfig
$creadPrec :: ReadPrec StreamingLoggingConfig
readList :: ReadS [StreamingLoggingConfig]
$creadList :: ReadS [StreamingLoggingConfig]
readsPrec :: Int -> ReadS StreamingLoggingConfig
$creadsPrec :: Int -> ReadS StreamingLoggingConfig
Prelude.Read, Int -> StreamingLoggingConfig -> ShowS
[StreamingLoggingConfig] -> ShowS
StreamingLoggingConfig -> String
(Int -> StreamingLoggingConfig -> ShowS)
-> (StreamingLoggingConfig -> String)
-> ([StreamingLoggingConfig] -> ShowS)
-> Show StreamingLoggingConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StreamingLoggingConfig] -> ShowS
$cshowList :: [StreamingLoggingConfig] -> ShowS
show :: StreamingLoggingConfig -> String
$cshow :: StreamingLoggingConfig -> String
showsPrec :: Int -> StreamingLoggingConfig -> ShowS
$cshowsPrec :: Int -> StreamingLoggingConfig -> ShowS
Prelude.Show, (forall x. StreamingLoggingConfig -> Rep StreamingLoggingConfig x)
-> (forall x.
    Rep StreamingLoggingConfig x -> StreamingLoggingConfig)
-> Generic StreamingLoggingConfig
forall x. Rep StreamingLoggingConfig x -> StreamingLoggingConfig
forall x. StreamingLoggingConfig -> Rep StreamingLoggingConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StreamingLoggingConfig x -> StreamingLoggingConfig
$cfrom :: forall x. StreamingLoggingConfig -> Rep StreamingLoggingConfig x
Prelude.Generic)

-- |
-- Create a value of 'StreamingLoggingConfig' 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:
--
-- 'enabled', 'streamingLoggingConfig_enabled' - Specifies whether you want CloudFront to save access logs to an Amazon
-- S3 bucket. If you don\'t want to enable logging when you create a
-- streaming distribution or if you want to disable logging for an existing
-- streaming distribution, specify @false@ for @Enabled@, and specify
-- @empty Bucket@ and @Prefix@ elements. If you specify @false@ for
-- @Enabled@ but you specify values for @Bucket@ and @Prefix@, the values
-- are automatically deleted.
--
-- 'bucket', 'streamingLoggingConfig_bucket' - The Amazon S3 bucket to store the access logs in, for example,
-- @myawslogbucket.s3.amazonaws.com@.
--
-- 'prefix', 'streamingLoggingConfig_prefix' - An optional string that you want CloudFront to prefix to the access log
-- filenames for this streaming distribution, for example, @myprefix\/@. If
-- you want to enable logging, but you don\'t want to specify a prefix, you
-- still must include an empty @Prefix@ element in the @Logging@ element.
newStreamingLoggingConfig ::
  -- | 'enabled'
  Prelude.Bool ->
  -- | 'bucket'
  Prelude.Text ->
  -- | 'prefix'
  Prelude.Text ->
  StreamingLoggingConfig
newStreamingLoggingConfig :: Bool -> Text -> Text -> StreamingLoggingConfig
newStreamingLoggingConfig Bool
pEnabled_ Text
pBucket_ Text
pPrefix_ =
  StreamingLoggingConfig' :: Bool -> Text -> Text -> StreamingLoggingConfig
StreamingLoggingConfig'
    { $sel:enabled:StreamingLoggingConfig' :: Bool
enabled = Bool
pEnabled_,
      $sel:bucket:StreamingLoggingConfig' :: Text
bucket = Text
pBucket_,
      $sel:prefix:StreamingLoggingConfig' :: Text
prefix = Text
pPrefix_
    }

-- | Specifies whether you want CloudFront to save access logs to an Amazon
-- S3 bucket. If you don\'t want to enable logging when you create a
-- streaming distribution or if you want to disable logging for an existing
-- streaming distribution, specify @false@ for @Enabled@, and specify
-- @empty Bucket@ and @Prefix@ elements. If you specify @false@ for
-- @Enabled@ but you specify values for @Bucket@ and @Prefix@, the values
-- are automatically deleted.
streamingLoggingConfig_enabled :: Lens.Lens' StreamingLoggingConfig Prelude.Bool
streamingLoggingConfig_enabled :: (Bool -> f Bool)
-> StreamingLoggingConfig -> f StreamingLoggingConfig
streamingLoggingConfig_enabled = (StreamingLoggingConfig -> Bool)
-> (StreamingLoggingConfig -> Bool -> StreamingLoggingConfig)
-> Lens StreamingLoggingConfig StreamingLoggingConfig Bool Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StreamingLoggingConfig' {Bool
enabled :: Bool
$sel:enabled:StreamingLoggingConfig' :: StreamingLoggingConfig -> Bool
enabled} -> Bool
enabled) (\s :: StreamingLoggingConfig
s@StreamingLoggingConfig' {} Bool
a -> StreamingLoggingConfig
s {$sel:enabled:StreamingLoggingConfig' :: Bool
enabled = Bool
a} :: StreamingLoggingConfig)

-- | The Amazon S3 bucket to store the access logs in, for example,
-- @myawslogbucket.s3.amazonaws.com@.
streamingLoggingConfig_bucket :: Lens.Lens' StreamingLoggingConfig Prelude.Text
streamingLoggingConfig_bucket :: (Text -> f Text)
-> StreamingLoggingConfig -> f StreamingLoggingConfig
streamingLoggingConfig_bucket = (StreamingLoggingConfig -> Text)
-> (StreamingLoggingConfig -> Text -> StreamingLoggingConfig)
-> Lens StreamingLoggingConfig StreamingLoggingConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StreamingLoggingConfig' {Text
bucket :: Text
$sel:bucket:StreamingLoggingConfig' :: StreamingLoggingConfig -> Text
bucket} -> Text
bucket) (\s :: StreamingLoggingConfig
s@StreamingLoggingConfig' {} Text
a -> StreamingLoggingConfig
s {$sel:bucket:StreamingLoggingConfig' :: Text
bucket = Text
a} :: StreamingLoggingConfig)

-- | An optional string that you want CloudFront to prefix to the access log
-- filenames for this streaming distribution, for example, @myprefix\/@. If
-- you want to enable logging, but you don\'t want to specify a prefix, you
-- still must include an empty @Prefix@ element in the @Logging@ element.
streamingLoggingConfig_prefix :: Lens.Lens' StreamingLoggingConfig Prelude.Text
streamingLoggingConfig_prefix :: (Text -> f Text)
-> StreamingLoggingConfig -> f StreamingLoggingConfig
streamingLoggingConfig_prefix = (StreamingLoggingConfig -> Text)
-> (StreamingLoggingConfig -> Text -> StreamingLoggingConfig)
-> Lens StreamingLoggingConfig StreamingLoggingConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StreamingLoggingConfig' {Text
prefix :: Text
$sel:prefix:StreamingLoggingConfig' :: StreamingLoggingConfig -> Text
prefix} -> Text
prefix) (\s :: StreamingLoggingConfig
s@StreamingLoggingConfig' {} Text
a -> StreamingLoggingConfig
s {$sel:prefix:StreamingLoggingConfig' :: Text
prefix = Text
a} :: StreamingLoggingConfig)

instance Core.FromXML StreamingLoggingConfig where
  parseXML :: [Node] -> Either String StreamingLoggingConfig
parseXML [Node]
x =
    Bool -> Text -> Text -> StreamingLoggingConfig
StreamingLoggingConfig'
      (Bool -> Text -> Text -> StreamingLoggingConfig)
-> Either String Bool
-> Either String (Text -> Text -> StreamingLoggingConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String Bool
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Enabled")
      Either String (Text -> Text -> StreamingLoggingConfig)
-> Either String Text
-> Either String (Text -> StreamingLoggingConfig)
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
"Bucket")
      Either String (Text -> StreamingLoggingConfig)
-> Either String Text -> Either String StreamingLoggingConfig
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
"Prefix")

instance Prelude.Hashable StreamingLoggingConfig

instance Prelude.NFData StreamingLoggingConfig

instance Core.ToXML StreamingLoggingConfig where
  toXML :: StreamingLoggingConfig -> XML
toXML StreamingLoggingConfig' {Bool
Text
prefix :: Text
bucket :: Text
enabled :: Bool
$sel:prefix:StreamingLoggingConfig' :: StreamingLoggingConfig -> Text
$sel:bucket:StreamingLoggingConfig' :: StreamingLoggingConfig -> Text
$sel:enabled:StreamingLoggingConfig' :: StreamingLoggingConfig -> Bool
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Enabled" Name -> Bool -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Bool
enabled,
        Name
"Bucket" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
bucket,
        Name
"Prefix" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
prefix
      ]