{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Redshift.EnableLogging
-- 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)
--
-- Starts logging information, such as queries and connection attempts, for
-- the specified Amazon Redshift cluster.
module Amazonka.Redshift.EnableLogging
  ( -- * Creating a Request
    EnableLogging (..),
    newEnableLogging,

    -- * Request Lenses
    enableLogging_s3KeyPrefix,
    enableLogging_clusterIdentifier,
    enableLogging_bucketName,

    -- * Destructuring the Response
    LoggingStatus (..),
    newLoggingStatus,

    -- * Response Lenses
    loggingStatus_lastFailureTime,
    loggingStatus_lastSuccessfulDeliveryTime,
    loggingStatus_s3KeyPrefix,
    loggingStatus_bucketName,
    loggingStatus_loggingEnabled,
    loggingStatus_lastFailureMessage,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Redshift.Types
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- |
--
-- /See:/ 'newEnableLogging' smart constructor.
data EnableLogging = EnableLogging'
  { -- | The prefix applied to the log file names.
    --
    -- Constraints:
    --
    -- -   Cannot exceed 512 characters
    --
    -- -   Cannot contain spaces( ), double quotes (\"), single quotes (\'), a
    --     backslash (\\), or control characters. The hexadecimal codes for
    --     invalid characters are:
    --
    --     -   x00 to x20
    --
    --     -   x22
    --
    --     -   x27
    --
    --     -   x5c
    --
    --     -   x7f or larger
    EnableLogging -> Maybe Text
s3KeyPrefix :: Prelude.Maybe Prelude.Text,
    -- | The identifier of the cluster on which logging is to be started.
    --
    -- Example: @examplecluster@
    EnableLogging -> Text
clusterIdentifier :: Prelude.Text,
    -- | The name of an existing S3 bucket where the log files are to be stored.
    --
    -- Constraints:
    --
    -- -   Must be in the same region as the cluster
    --
    -- -   The cluster must have read bucket and put object permissions
    EnableLogging -> Text
bucketName :: Prelude.Text
  }
  deriving (EnableLogging -> EnableLogging -> Bool
(EnableLogging -> EnableLogging -> Bool)
-> (EnableLogging -> EnableLogging -> Bool) -> Eq EnableLogging
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnableLogging -> EnableLogging -> Bool
$c/= :: EnableLogging -> EnableLogging -> Bool
== :: EnableLogging -> EnableLogging -> Bool
$c== :: EnableLogging -> EnableLogging -> Bool
Prelude.Eq, ReadPrec [EnableLogging]
ReadPrec EnableLogging
Int -> ReadS EnableLogging
ReadS [EnableLogging]
(Int -> ReadS EnableLogging)
-> ReadS [EnableLogging]
-> ReadPrec EnableLogging
-> ReadPrec [EnableLogging]
-> Read EnableLogging
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EnableLogging]
$creadListPrec :: ReadPrec [EnableLogging]
readPrec :: ReadPrec EnableLogging
$creadPrec :: ReadPrec EnableLogging
readList :: ReadS [EnableLogging]
$creadList :: ReadS [EnableLogging]
readsPrec :: Int -> ReadS EnableLogging
$creadsPrec :: Int -> ReadS EnableLogging
Prelude.Read, Int -> EnableLogging -> ShowS
[EnableLogging] -> ShowS
EnableLogging -> String
(Int -> EnableLogging -> ShowS)
-> (EnableLogging -> String)
-> ([EnableLogging] -> ShowS)
-> Show EnableLogging
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EnableLogging] -> ShowS
$cshowList :: [EnableLogging] -> ShowS
show :: EnableLogging -> String
$cshow :: EnableLogging -> String
showsPrec :: Int -> EnableLogging -> ShowS
$cshowsPrec :: Int -> EnableLogging -> ShowS
Prelude.Show, (forall x. EnableLogging -> Rep EnableLogging x)
-> (forall x. Rep EnableLogging x -> EnableLogging)
-> Generic EnableLogging
forall x. Rep EnableLogging x -> EnableLogging
forall x. EnableLogging -> Rep EnableLogging x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EnableLogging x -> EnableLogging
$cfrom :: forall x. EnableLogging -> Rep EnableLogging x
Prelude.Generic)

-- |
-- Create a value of 'EnableLogging' 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:
--
-- 's3KeyPrefix', 'enableLogging_s3KeyPrefix' - The prefix applied to the log file names.
--
-- Constraints:
--
-- -   Cannot exceed 512 characters
--
-- -   Cannot contain spaces( ), double quotes (\"), single quotes (\'), a
--     backslash (\\), or control characters. The hexadecimal codes for
--     invalid characters are:
--
--     -   x00 to x20
--
--     -   x22
--
--     -   x27
--
--     -   x5c
--
--     -   x7f or larger
--
-- 'clusterIdentifier', 'enableLogging_clusterIdentifier' - The identifier of the cluster on which logging is to be started.
--
-- Example: @examplecluster@
--
-- 'bucketName', 'enableLogging_bucketName' - The name of an existing S3 bucket where the log files are to be stored.
--
-- Constraints:
--
-- -   Must be in the same region as the cluster
--
-- -   The cluster must have read bucket and put object permissions
newEnableLogging ::
  -- | 'clusterIdentifier'
  Prelude.Text ->
  -- | 'bucketName'
  Prelude.Text ->
  EnableLogging
newEnableLogging :: Text -> Text -> EnableLogging
newEnableLogging Text
pClusterIdentifier_ Text
pBucketName_ =
  EnableLogging' :: Maybe Text -> Text -> Text -> EnableLogging
EnableLogging'
    { $sel:s3KeyPrefix:EnableLogging' :: Maybe Text
s3KeyPrefix = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:clusterIdentifier:EnableLogging' :: Text
clusterIdentifier = Text
pClusterIdentifier_,
      $sel:bucketName:EnableLogging' :: Text
bucketName = Text
pBucketName_
    }

-- | The prefix applied to the log file names.
--
-- Constraints:
--
-- -   Cannot exceed 512 characters
--
-- -   Cannot contain spaces( ), double quotes (\"), single quotes (\'), a
--     backslash (\\), or control characters. The hexadecimal codes for
--     invalid characters are:
--
--     -   x00 to x20
--
--     -   x22
--
--     -   x27
--
--     -   x5c
--
--     -   x7f or larger
enableLogging_s3KeyPrefix :: Lens.Lens' EnableLogging (Prelude.Maybe Prelude.Text)
enableLogging_s3KeyPrefix :: (Maybe Text -> f (Maybe Text)) -> EnableLogging -> f EnableLogging
enableLogging_s3KeyPrefix = (EnableLogging -> Maybe Text)
-> (EnableLogging -> Maybe Text -> EnableLogging)
-> Lens EnableLogging EnableLogging (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableLogging' {Maybe Text
s3KeyPrefix :: Maybe Text
$sel:s3KeyPrefix:EnableLogging' :: EnableLogging -> Maybe Text
s3KeyPrefix} -> Maybe Text
s3KeyPrefix) (\s :: EnableLogging
s@EnableLogging' {} Maybe Text
a -> EnableLogging
s {$sel:s3KeyPrefix:EnableLogging' :: Maybe Text
s3KeyPrefix = Maybe Text
a} :: EnableLogging)

-- | The identifier of the cluster on which logging is to be started.
--
-- Example: @examplecluster@
enableLogging_clusterIdentifier :: Lens.Lens' EnableLogging Prelude.Text
enableLogging_clusterIdentifier :: (Text -> f Text) -> EnableLogging -> f EnableLogging
enableLogging_clusterIdentifier = (EnableLogging -> Text)
-> (EnableLogging -> Text -> EnableLogging)
-> Lens EnableLogging EnableLogging Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableLogging' {Text
clusterIdentifier :: Text
$sel:clusterIdentifier:EnableLogging' :: EnableLogging -> Text
clusterIdentifier} -> Text
clusterIdentifier) (\s :: EnableLogging
s@EnableLogging' {} Text
a -> EnableLogging
s {$sel:clusterIdentifier:EnableLogging' :: Text
clusterIdentifier = Text
a} :: EnableLogging)

-- | The name of an existing S3 bucket where the log files are to be stored.
--
-- Constraints:
--
-- -   Must be in the same region as the cluster
--
-- -   The cluster must have read bucket and put object permissions
enableLogging_bucketName :: Lens.Lens' EnableLogging Prelude.Text
enableLogging_bucketName :: (Text -> f Text) -> EnableLogging -> f EnableLogging
enableLogging_bucketName = (EnableLogging -> Text)
-> (EnableLogging -> Text -> EnableLogging)
-> Lens EnableLogging EnableLogging Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableLogging' {Text
bucketName :: Text
$sel:bucketName:EnableLogging' :: EnableLogging -> Text
bucketName} -> Text
bucketName) (\s :: EnableLogging
s@EnableLogging' {} Text
a -> EnableLogging
s {$sel:bucketName:EnableLogging' :: Text
bucketName = Text
a} :: EnableLogging)

instance Core.AWSRequest EnableLogging where
  type AWSResponse EnableLogging = LoggingStatus
  request :: EnableLogging -> Request EnableLogging
request = Service -> EnableLogging -> Request EnableLogging
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy EnableLogging
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse EnableLogging)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse EnableLogging))
-> Logger
-> Service
-> Proxy EnableLogging
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse EnableLogging)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"EnableLoggingResult"
      (\Int
s ResponseHeaders
h [Node]
x -> [Node] -> Either String LoggingStatus
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)

instance Prelude.Hashable EnableLogging

instance Prelude.NFData EnableLogging

instance Core.ToHeaders EnableLogging where
  toHeaders :: EnableLogging -> ResponseHeaders
toHeaders = ResponseHeaders -> EnableLogging -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToPath EnableLogging where
  toPath :: EnableLogging -> ByteString
toPath = ByteString -> EnableLogging -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery EnableLogging where
  toQuery :: EnableLogging -> QueryString
toQuery EnableLogging' {Maybe Text
Text
bucketName :: Text
clusterIdentifier :: Text
s3KeyPrefix :: Maybe Text
$sel:bucketName:EnableLogging' :: EnableLogging -> Text
$sel:clusterIdentifier:EnableLogging' :: EnableLogging -> Text
$sel:s3KeyPrefix:EnableLogging' :: EnableLogging -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"EnableLogging" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2012-12-01" :: Prelude.ByteString),
        ByteString
"S3KeyPrefix" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
s3KeyPrefix,
        ByteString
"ClusterIdentifier" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
clusterIdentifier,
        ByteString
"BucketName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
bucketName
      ]