{-# 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.ELB.Types.AccessLog
-- 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.ELB.Types.AccessLog where

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

-- | Information about the @AccessLog@ attribute.
--
-- /See:/ 'newAccessLog' smart constructor.
data AccessLog = AccessLog'
  { -- | The interval for publishing the access logs. You can specify an interval
    -- of either 5 minutes or 60 minutes.
    --
    -- Default: 60 minutes
    AccessLog -> Maybe Int
emitInterval :: Prelude.Maybe Prelude.Int,
    -- | The logical hierarchy you created for your Amazon S3 bucket, for example
    -- @my-bucket-prefix\/prod@. If the prefix is not provided, the log is
    -- placed at the root level of the bucket.
    AccessLog -> Maybe Text
s3BucketPrefix :: Prelude.Maybe Prelude.Text,
    -- | The name of the Amazon S3 bucket where the access logs are stored.
    AccessLog -> Maybe Text
s3BucketName :: Prelude.Maybe Prelude.Text,
    -- | Specifies whether access logs are enabled for the load balancer.
    AccessLog -> Bool
enabled :: Prelude.Bool
  }
  deriving (AccessLog -> AccessLog -> Bool
(AccessLog -> AccessLog -> Bool)
-> (AccessLog -> AccessLog -> Bool) -> Eq AccessLog
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AccessLog -> AccessLog -> Bool
$c/= :: AccessLog -> AccessLog -> Bool
== :: AccessLog -> AccessLog -> Bool
$c== :: AccessLog -> AccessLog -> Bool
Prelude.Eq, ReadPrec [AccessLog]
ReadPrec AccessLog
Int -> ReadS AccessLog
ReadS [AccessLog]
(Int -> ReadS AccessLog)
-> ReadS [AccessLog]
-> ReadPrec AccessLog
-> ReadPrec [AccessLog]
-> Read AccessLog
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AccessLog]
$creadListPrec :: ReadPrec [AccessLog]
readPrec :: ReadPrec AccessLog
$creadPrec :: ReadPrec AccessLog
readList :: ReadS [AccessLog]
$creadList :: ReadS [AccessLog]
readsPrec :: Int -> ReadS AccessLog
$creadsPrec :: Int -> ReadS AccessLog
Prelude.Read, Int -> AccessLog -> ShowS
[AccessLog] -> ShowS
AccessLog -> String
(Int -> AccessLog -> ShowS)
-> (AccessLog -> String)
-> ([AccessLog] -> ShowS)
-> Show AccessLog
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AccessLog] -> ShowS
$cshowList :: [AccessLog] -> ShowS
show :: AccessLog -> String
$cshow :: AccessLog -> String
showsPrec :: Int -> AccessLog -> ShowS
$cshowsPrec :: Int -> AccessLog -> ShowS
Prelude.Show, (forall x. AccessLog -> Rep AccessLog x)
-> (forall x. Rep AccessLog x -> AccessLog) -> Generic AccessLog
forall x. Rep AccessLog x -> AccessLog
forall x. AccessLog -> Rep AccessLog x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AccessLog x -> AccessLog
$cfrom :: forall x. AccessLog -> Rep AccessLog x
Prelude.Generic)

-- |
-- Create a value of 'AccessLog' 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:
--
-- 'emitInterval', 'accessLog_emitInterval' - The interval for publishing the access logs. You can specify an interval
-- of either 5 minutes or 60 minutes.
--
-- Default: 60 minutes
--
-- 's3BucketPrefix', 'accessLog_s3BucketPrefix' - The logical hierarchy you created for your Amazon S3 bucket, for example
-- @my-bucket-prefix\/prod@. If the prefix is not provided, the log is
-- placed at the root level of the bucket.
--
-- 's3BucketName', 'accessLog_s3BucketName' - The name of the Amazon S3 bucket where the access logs are stored.
--
-- 'enabled', 'accessLog_enabled' - Specifies whether access logs are enabled for the load balancer.
newAccessLog ::
  -- | 'enabled'
  Prelude.Bool ->
  AccessLog
newAccessLog :: Bool -> AccessLog
newAccessLog Bool
pEnabled_ =
  AccessLog' :: Maybe Int -> Maybe Text -> Maybe Text -> Bool -> AccessLog
AccessLog'
    { $sel:emitInterval:AccessLog' :: Maybe Int
emitInterval = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:s3BucketPrefix:AccessLog' :: Maybe Text
s3BucketPrefix = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:s3BucketName:AccessLog' :: Maybe Text
s3BucketName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:enabled:AccessLog' :: Bool
enabled = Bool
pEnabled_
    }

-- | The interval for publishing the access logs. You can specify an interval
-- of either 5 minutes or 60 minutes.
--
-- Default: 60 minutes
accessLog_emitInterval :: Lens.Lens' AccessLog (Prelude.Maybe Prelude.Int)
accessLog_emitInterval :: (Maybe Int -> f (Maybe Int)) -> AccessLog -> f AccessLog
accessLog_emitInterval = (AccessLog -> Maybe Int)
-> (AccessLog -> Maybe Int -> AccessLog)
-> Lens AccessLog AccessLog (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessLog' {Maybe Int
emitInterval :: Maybe Int
$sel:emitInterval:AccessLog' :: AccessLog -> Maybe Int
emitInterval} -> Maybe Int
emitInterval) (\s :: AccessLog
s@AccessLog' {} Maybe Int
a -> AccessLog
s {$sel:emitInterval:AccessLog' :: Maybe Int
emitInterval = Maybe Int
a} :: AccessLog)

-- | The logical hierarchy you created for your Amazon S3 bucket, for example
-- @my-bucket-prefix\/prod@. If the prefix is not provided, the log is
-- placed at the root level of the bucket.
accessLog_s3BucketPrefix :: Lens.Lens' AccessLog (Prelude.Maybe Prelude.Text)
accessLog_s3BucketPrefix :: (Maybe Text -> f (Maybe Text)) -> AccessLog -> f AccessLog
accessLog_s3BucketPrefix = (AccessLog -> Maybe Text)
-> (AccessLog -> Maybe Text -> AccessLog)
-> Lens AccessLog AccessLog (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessLog' {Maybe Text
s3BucketPrefix :: Maybe Text
$sel:s3BucketPrefix:AccessLog' :: AccessLog -> Maybe Text
s3BucketPrefix} -> Maybe Text
s3BucketPrefix) (\s :: AccessLog
s@AccessLog' {} Maybe Text
a -> AccessLog
s {$sel:s3BucketPrefix:AccessLog' :: Maybe Text
s3BucketPrefix = Maybe Text
a} :: AccessLog)

-- | The name of the Amazon S3 bucket where the access logs are stored.
accessLog_s3BucketName :: Lens.Lens' AccessLog (Prelude.Maybe Prelude.Text)
accessLog_s3BucketName :: (Maybe Text -> f (Maybe Text)) -> AccessLog -> f AccessLog
accessLog_s3BucketName = (AccessLog -> Maybe Text)
-> (AccessLog -> Maybe Text -> AccessLog)
-> Lens AccessLog AccessLog (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessLog' {Maybe Text
s3BucketName :: Maybe Text
$sel:s3BucketName:AccessLog' :: AccessLog -> Maybe Text
s3BucketName} -> Maybe Text
s3BucketName) (\s :: AccessLog
s@AccessLog' {} Maybe Text
a -> AccessLog
s {$sel:s3BucketName:AccessLog' :: Maybe Text
s3BucketName = Maybe Text
a} :: AccessLog)

-- | Specifies whether access logs are enabled for the load balancer.
accessLog_enabled :: Lens.Lens' AccessLog Prelude.Bool
accessLog_enabled :: (Bool -> f Bool) -> AccessLog -> f AccessLog
accessLog_enabled = (AccessLog -> Bool)
-> (AccessLog -> Bool -> AccessLog)
-> Lens AccessLog AccessLog Bool Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessLog' {Bool
enabled :: Bool
$sel:enabled:AccessLog' :: AccessLog -> Bool
enabled} -> Bool
enabled) (\s :: AccessLog
s@AccessLog' {} Bool
a -> AccessLog
s {$sel:enabled:AccessLog' :: Bool
enabled = Bool
a} :: AccessLog)

instance Core.FromXML AccessLog where
  parseXML :: [Node] -> Either String AccessLog
parseXML [Node]
x =
    Maybe Int -> Maybe Text -> Maybe Text -> Bool -> AccessLog
AccessLog'
      (Maybe Int -> Maybe Text -> Maybe Text -> Bool -> AccessLog)
-> Either String (Maybe Int)
-> Either String (Maybe Text -> Maybe Text -> Bool -> AccessLog)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Int)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"EmitInterval")
      Either String (Maybe Text -> Maybe Text -> Bool -> AccessLog)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Bool -> AccessLog)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"S3BucketPrefix")
      Either String (Maybe Text -> Bool -> AccessLog)
-> Either String (Maybe Text) -> Either String (Bool -> AccessLog)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"S3BucketName")
      Either String (Bool -> AccessLog)
-> Either String Bool -> Either String AccessLog
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
"Enabled")

instance Prelude.Hashable AccessLog

instance Prelude.NFData AccessLog

instance Core.ToQuery AccessLog where
  toQuery :: AccessLog -> QueryString
toQuery AccessLog' {Bool
Maybe Int
Maybe Text
enabled :: Bool
s3BucketName :: Maybe Text
s3BucketPrefix :: Maybe Text
emitInterval :: Maybe Int
$sel:enabled:AccessLog' :: AccessLog -> Bool
$sel:s3BucketName:AccessLog' :: AccessLog -> Maybe Text
$sel:s3BucketPrefix:AccessLog' :: AccessLog -> Maybe Text
$sel:emitInterval:AccessLog' :: AccessLog -> Maybe Int
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"EmitInterval" ByteString -> Maybe Int -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Int
emitInterval,
        ByteString
"S3BucketPrefix" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
s3BucketPrefix,
        ByteString
"S3BucketName" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
s3BucketName,
        ByteString
"Enabled" ByteString -> Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Bool
enabled
      ]