{-# 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.LoggingConfig
-- 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.LoggingConfig 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 the
-- distribution.
--
-- /See:/ 'newLoggingConfig' smart constructor.
data LoggingConfig = LoggingConfig'
  { -- | 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
    -- distribution or if you want to disable logging for an existing
    -- distribution, specify @false@ for @Enabled@, and specify empty @Bucket@
    -- and @Prefix@ elements. If you specify @false@ for @Enabled@ but you
    -- specify values for @Bucket@, @prefix@, and @IncludeCookies@, the values
    -- are automatically deleted.
    LoggingConfig -> Bool
enabled :: Prelude.Bool,
    -- | Specifies whether you want CloudFront to include cookies in access logs,
    -- specify @true@ for @IncludeCookies@. If you choose to include cookies in
    -- logs, CloudFront logs all cookies regardless of how you configure the
    -- cache behaviors for this distribution. If you don\'t want to include
    -- cookies when you create a distribution or if you want to disable include
    -- cookies for an existing distribution, specify @false@ for
    -- @IncludeCookies@.
    LoggingConfig -> Bool
includeCookies :: Prelude.Bool,
    -- | The Amazon S3 bucket to store the access logs in, for example,
    -- @myawslogbucket.s3.amazonaws.com@.
    LoggingConfig -> Text
bucket :: Prelude.Text,
    -- | An optional string that you want CloudFront to prefix to the access log
    -- @filenames@ for this 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.
    LoggingConfig -> Text
prefix :: Prelude.Text
  }
  deriving (LoggingConfig -> LoggingConfig -> Bool
(LoggingConfig -> LoggingConfig -> Bool)
-> (LoggingConfig -> LoggingConfig -> Bool) -> Eq LoggingConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LoggingConfig -> LoggingConfig -> Bool
$c/= :: LoggingConfig -> LoggingConfig -> Bool
== :: LoggingConfig -> LoggingConfig -> Bool
$c== :: LoggingConfig -> LoggingConfig -> Bool
Prelude.Eq, ReadPrec [LoggingConfig]
ReadPrec LoggingConfig
Int -> ReadS LoggingConfig
ReadS [LoggingConfig]
(Int -> ReadS LoggingConfig)
-> ReadS [LoggingConfig]
-> ReadPrec LoggingConfig
-> ReadPrec [LoggingConfig]
-> Read LoggingConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LoggingConfig]
$creadListPrec :: ReadPrec [LoggingConfig]
readPrec :: ReadPrec LoggingConfig
$creadPrec :: ReadPrec LoggingConfig
readList :: ReadS [LoggingConfig]
$creadList :: ReadS [LoggingConfig]
readsPrec :: Int -> ReadS LoggingConfig
$creadsPrec :: Int -> ReadS LoggingConfig
Prelude.Read, Int -> LoggingConfig -> ShowS
[LoggingConfig] -> ShowS
LoggingConfig -> String
(Int -> LoggingConfig -> ShowS)
-> (LoggingConfig -> String)
-> ([LoggingConfig] -> ShowS)
-> Show LoggingConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LoggingConfig] -> ShowS
$cshowList :: [LoggingConfig] -> ShowS
show :: LoggingConfig -> String
$cshow :: LoggingConfig -> String
showsPrec :: Int -> LoggingConfig -> ShowS
$cshowsPrec :: Int -> LoggingConfig -> ShowS
Prelude.Show, (forall x. LoggingConfig -> Rep LoggingConfig x)
-> (forall x. Rep LoggingConfig x -> LoggingConfig)
-> Generic LoggingConfig
forall x. Rep LoggingConfig x -> LoggingConfig
forall x. LoggingConfig -> Rep LoggingConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LoggingConfig x -> LoggingConfig
$cfrom :: forall x. LoggingConfig -> Rep LoggingConfig x
Prelude.Generic)

-- |
-- Create a value of 'LoggingConfig' 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', 'loggingConfig_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
-- distribution or if you want to disable logging for an existing
-- distribution, specify @false@ for @Enabled@, and specify empty @Bucket@
-- and @Prefix@ elements. If you specify @false@ for @Enabled@ but you
-- specify values for @Bucket@, @prefix@, and @IncludeCookies@, the values
-- are automatically deleted.
--
-- 'includeCookies', 'loggingConfig_includeCookies' - Specifies whether you want CloudFront to include cookies in access logs,
-- specify @true@ for @IncludeCookies@. If you choose to include cookies in
-- logs, CloudFront logs all cookies regardless of how you configure the
-- cache behaviors for this distribution. If you don\'t want to include
-- cookies when you create a distribution or if you want to disable include
-- cookies for an existing distribution, specify @false@ for
-- @IncludeCookies@.
--
-- 'bucket', 'loggingConfig_bucket' - The Amazon S3 bucket to store the access logs in, for example,
-- @myawslogbucket.s3.amazonaws.com@.
--
-- 'prefix', 'loggingConfig_prefix' - An optional string that you want CloudFront to prefix to the access log
-- @filenames@ for this 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.
newLoggingConfig ::
  -- | 'enabled'
  Prelude.Bool ->
  -- | 'includeCookies'
  Prelude.Bool ->
  -- | 'bucket'
  Prelude.Text ->
  -- | 'prefix'
  Prelude.Text ->
  LoggingConfig
newLoggingConfig :: Bool -> Bool -> Text -> Text -> LoggingConfig
newLoggingConfig
  Bool
pEnabled_
  Bool
pIncludeCookies_
  Text
pBucket_
  Text
pPrefix_ =
    LoggingConfig' :: Bool -> Bool -> Text -> Text -> LoggingConfig
LoggingConfig'
      { $sel:enabled:LoggingConfig' :: Bool
enabled = Bool
pEnabled_,
        $sel:includeCookies:LoggingConfig' :: Bool
includeCookies = Bool
pIncludeCookies_,
        $sel:bucket:LoggingConfig' :: Text
bucket = Text
pBucket_,
        $sel:prefix:LoggingConfig' :: 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
-- distribution or if you want to disable logging for an existing
-- distribution, specify @false@ for @Enabled@, and specify empty @Bucket@
-- and @Prefix@ elements. If you specify @false@ for @Enabled@ but you
-- specify values for @Bucket@, @prefix@, and @IncludeCookies@, the values
-- are automatically deleted.
loggingConfig_enabled :: Lens.Lens' LoggingConfig Prelude.Bool
loggingConfig_enabled :: (Bool -> f Bool) -> LoggingConfig -> f LoggingConfig
loggingConfig_enabled = (LoggingConfig -> Bool)
-> (LoggingConfig -> Bool -> LoggingConfig)
-> Lens LoggingConfig LoggingConfig Bool Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoggingConfig' {Bool
enabled :: Bool
$sel:enabled:LoggingConfig' :: LoggingConfig -> Bool
enabled} -> Bool
enabled) (\s :: LoggingConfig
s@LoggingConfig' {} Bool
a -> LoggingConfig
s {$sel:enabled:LoggingConfig' :: Bool
enabled = Bool
a} :: LoggingConfig)

-- | Specifies whether you want CloudFront to include cookies in access logs,
-- specify @true@ for @IncludeCookies@. If you choose to include cookies in
-- logs, CloudFront logs all cookies regardless of how you configure the
-- cache behaviors for this distribution. If you don\'t want to include
-- cookies when you create a distribution or if you want to disable include
-- cookies for an existing distribution, specify @false@ for
-- @IncludeCookies@.
loggingConfig_includeCookies :: Lens.Lens' LoggingConfig Prelude.Bool
loggingConfig_includeCookies :: (Bool -> f Bool) -> LoggingConfig -> f LoggingConfig
loggingConfig_includeCookies = (LoggingConfig -> Bool)
-> (LoggingConfig -> Bool -> LoggingConfig)
-> Lens LoggingConfig LoggingConfig Bool Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoggingConfig' {Bool
includeCookies :: Bool
$sel:includeCookies:LoggingConfig' :: LoggingConfig -> Bool
includeCookies} -> Bool
includeCookies) (\s :: LoggingConfig
s@LoggingConfig' {} Bool
a -> LoggingConfig
s {$sel:includeCookies:LoggingConfig' :: Bool
includeCookies = Bool
a} :: LoggingConfig)

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

-- | An optional string that you want CloudFront to prefix to the access log
-- @filenames@ for this 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.
loggingConfig_prefix :: Lens.Lens' LoggingConfig Prelude.Text
loggingConfig_prefix :: (Text -> f Text) -> LoggingConfig -> f LoggingConfig
loggingConfig_prefix = (LoggingConfig -> Text)
-> (LoggingConfig -> Text -> LoggingConfig)
-> Lens LoggingConfig LoggingConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LoggingConfig' {Text
prefix :: Text
$sel:prefix:LoggingConfig' :: LoggingConfig -> Text
prefix} -> Text
prefix) (\s :: LoggingConfig
s@LoggingConfig' {} Text
a -> LoggingConfig
s {$sel:prefix:LoggingConfig' :: Text
prefix = Text
a} :: LoggingConfig)

instance Core.FromXML LoggingConfig where
  parseXML :: [Node] -> Either String LoggingConfig
parseXML [Node]
x =
    Bool -> Bool -> Text -> Text -> LoggingConfig
LoggingConfig'
      (Bool -> Bool -> Text -> Text -> LoggingConfig)
-> Either String Bool
-> Either String (Bool -> Text -> Text -> LoggingConfig)
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 (Bool -> Text -> Text -> LoggingConfig)
-> Either String Bool
-> Either String (Text -> Text -> LoggingConfig)
forall (f :: * -> *) a b. Applicative f => 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
"IncludeCookies")
      Either String (Text -> Text -> LoggingConfig)
-> Either String Text -> Either String (Text -> LoggingConfig)
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 -> LoggingConfig)
-> Either String Text -> Either String LoggingConfig
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 LoggingConfig

instance Prelude.NFData LoggingConfig

instance Core.ToXML LoggingConfig where
  toXML :: LoggingConfig -> XML
toXML LoggingConfig' {Bool
Text
prefix :: Text
bucket :: Text
includeCookies :: Bool
enabled :: Bool
$sel:prefix:LoggingConfig' :: LoggingConfig -> Text
$sel:bucket:LoggingConfig' :: LoggingConfig -> Text
$sel:includeCookies:LoggingConfig' :: LoggingConfig -> Bool
$sel:enabled:LoggingConfig' :: LoggingConfig -> 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
"IncludeCookies" Name -> Bool -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Bool
includeCookies,
        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
      ]