{-# 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.S3.GetBucketNotificationConfiguration
-- 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)
--
-- Returns the notification configuration of a bucket.
--
-- If notifications are not enabled on the bucket, the action returns an
-- empty @NotificationConfiguration@ element.
--
-- By default, you must be the bucket owner to read the notification
-- configuration of a bucket. However, the bucket owner can use a bucket
-- policy to grant permission to other users to read this configuration
-- with the @s3:GetBucketNotification@ permission.
--
-- For more information about setting and reading the notification
-- configuration on a bucket, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html Setting Up Notification of Bucket Events>.
-- For more information about bucket policies, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/using-iam-policies.html Using Bucket Policies>.
--
-- The following action is related to @GetBucketNotification@:
--
-- -   <https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketNotification.html PutBucketNotification>
module Amazonka.S3.GetBucketNotificationConfiguration
  ( -- * Creating a Request
    GetBucketNotificationConfiguration (..),
    newGetBucketNotificationConfiguration,

    -- * Request Lenses
    getBucketNotificationConfiguration_expectedBucketOwner,
    getBucketNotificationConfiguration_bucket,

    -- * Destructuring the Response
    NotificationConfiguration (..),
    newNotificationConfiguration,

    -- * Response Lenses
    notificationConfiguration_queueConfigurations,
    notificationConfiguration_topicConfigurations,
    notificationConfiguration_lambdaFunctionConfigurations,
  )
where

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

-- | /See:/ 'newGetBucketNotificationConfiguration' smart constructor.
data GetBucketNotificationConfiguration = GetBucketNotificationConfiguration'
  { -- | The account ID of the expected bucket owner. If the bucket is owned by a
    -- different account, the request will fail with an HTTP
    -- @403 (Access Denied)@ error.
    GetBucketNotificationConfiguration -> Maybe Text
expectedBucketOwner :: Prelude.Maybe Prelude.Text,
    -- | The name of the bucket for which to get the notification configuration.
    GetBucketNotificationConfiguration -> BucketName
bucket :: BucketName
  }
  deriving (GetBucketNotificationConfiguration
-> GetBucketNotificationConfiguration -> Bool
(GetBucketNotificationConfiguration
 -> GetBucketNotificationConfiguration -> Bool)
-> (GetBucketNotificationConfiguration
    -> GetBucketNotificationConfiguration -> Bool)
-> Eq GetBucketNotificationConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetBucketNotificationConfiguration
-> GetBucketNotificationConfiguration -> Bool
$c/= :: GetBucketNotificationConfiguration
-> GetBucketNotificationConfiguration -> Bool
== :: GetBucketNotificationConfiguration
-> GetBucketNotificationConfiguration -> Bool
$c== :: GetBucketNotificationConfiguration
-> GetBucketNotificationConfiguration -> Bool
Prelude.Eq, ReadPrec [GetBucketNotificationConfiguration]
ReadPrec GetBucketNotificationConfiguration
Int -> ReadS GetBucketNotificationConfiguration
ReadS [GetBucketNotificationConfiguration]
(Int -> ReadS GetBucketNotificationConfiguration)
-> ReadS [GetBucketNotificationConfiguration]
-> ReadPrec GetBucketNotificationConfiguration
-> ReadPrec [GetBucketNotificationConfiguration]
-> Read GetBucketNotificationConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetBucketNotificationConfiguration]
$creadListPrec :: ReadPrec [GetBucketNotificationConfiguration]
readPrec :: ReadPrec GetBucketNotificationConfiguration
$creadPrec :: ReadPrec GetBucketNotificationConfiguration
readList :: ReadS [GetBucketNotificationConfiguration]
$creadList :: ReadS [GetBucketNotificationConfiguration]
readsPrec :: Int -> ReadS GetBucketNotificationConfiguration
$creadsPrec :: Int -> ReadS GetBucketNotificationConfiguration
Prelude.Read, Int -> GetBucketNotificationConfiguration -> ShowS
[GetBucketNotificationConfiguration] -> ShowS
GetBucketNotificationConfiguration -> String
(Int -> GetBucketNotificationConfiguration -> ShowS)
-> (GetBucketNotificationConfiguration -> String)
-> ([GetBucketNotificationConfiguration] -> ShowS)
-> Show GetBucketNotificationConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetBucketNotificationConfiguration] -> ShowS
$cshowList :: [GetBucketNotificationConfiguration] -> ShowS
show :: GetBucketNotificationConfiguration -> String
$cshow :: GetBucketNotificationConfiguration -> String
showsPrec :: Int -> GetBucketNotificationConfiguration -> ShowS
$cshowsPrec :: Int -> GetBucketNotificationConfiguration -> ShowS
Prelude.Show, (forall x.
 GetBucketNotificationConfiguration
 -> Rep GetBucketNotificationConfiguration x)
-> (forall x.
    Rep GetBucketNotificationConfiguration x
    -> GetBucketNotificationConfiguration)
-> Generic GetBucketNotificationConfiguration
forall x.
Rep GetBucketNotificationConfiguration x
-> GetBucketNotificationConfiguration
forall x.
GetBucketNotificationConfiguration
-> Rep GetBucketNotificationConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetBucketNotificationConfiguration x
-> GetBucketNotificationConfiguration
$cfrom :: forall x.
GetBucketNotificationConfiguration
-> Rep GetBucketNotificationConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'GetBucketNotificationConfiguration' 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:
--
-- 'expectedBucketOwner', 'getBucketNotificationConfiguration_expectedBucketOwner' - The account ID of the expected bucket owner. If the bucket is owned by a
-- different account, the request will fail with an HTTP
-- @403 (Access Denied)@ error.
--
-- 'bucket', 'getBucketNotificationConfiguration_bucket' - The name of the bucket for which to get the notification configuration.
newGetBucketNotificationConfiguration ::
  -- | 'bucket'
  BucketName ->
  GetBucketNotificationConfiguration
newGetBucketNotificationConfiguration :: BucketName -> GetBucketNotificationConfiguration
newGetBucketNotificationConfiguration BucketName
pBucket_ =
  GetBucketNotificationConfiguration' :: Maybe Text -> BucketName -> GetBucketNotificationConfiguration
GetBucketNotificationConfiguration'
    { $sel:expectedBucketOwner:GetBucketNotificationConfiguration' :: Maybe Text
expectedBucketOwner =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:bucket:GetBucketNotificationConfiguration' :: BucketName
bucket = BucketName
pBucket_
    }

-- | The account ID of the expected bucket owner. If the bucket is owned by a
-- different account, the request will fail with an HTTP
-- @403 (Access Denied)@ error.
getBucketNotificationConfiguration_expectedBucketOwner :: Lens.Lens' GetBucketNotificationConfiguration (Prelude.Maybe Prelude.Text)
getBucketNotificationConfiguration_expectedBucketOwner :: (Maybe Text -> f (Maybe Text))
-> GetBucketNotificationConfiguration
-> f GetBucketNotificationConfiguration
getBucketNotificationConfiguration_expectedBucketOwner = (GetBucketNotificationConfiguration -> Maybe Text)
-> (GetBucketNotificationConfiguration
    -> Maybe Text -> GetBucketNotificationConfiguration)
-> Lens
     GetBucketNotificationConfiguration
     GetBucketNotificationConfiguration
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketNotificationConfiguration' {Maybe Text
expectedBucketOwner :: Maybe Text
$sel:expectedBucketOwner:GetBucketNotificationConfiguration' :: GetBucketNotificationConfiguration -> Maybe Text
expectedBucketOwner} -> Maybe Text
expectedBucketOwner) (\s :: GetBucketNotificationConfiguration
s@GetBucketNotificationConfiguration' {} Maybe Text
a -> GetBucketNotificationConfiguration
s {$sel:expectedBucketOwner:GetBucketNotificationConfiguration' :: Maybe Text
expectedBucketOwner = Maybe Text
a} :: GetBucketNotificationConfiguration)

-- | The name of the bucket for which to get the notification configuration.
getBucketNotificationConfiguration_bucket :: Lens.Lens' GetBucketNotificationConfiguration BucketName
getBucketNotificationConfiguration_bucket :: (BucketName -> f BucketName)
-> GetBucketNotificationConfiguration
-> f GetBucketNotificationConfiguration
getBucketNotificationConfiguration_bucket = (GetBucketNotificationConfiguration -> BucketName)
-> (GetBucketNotificationConfiguration
    -> BucketName -> GetBucketNotificationConfiguration)
-> Lens
     GetBucketNotificationConfiguration
     GetBucketNotificationConfiguration
     BucketName
     BucketName
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketNotificationConfiguration' {BucketName
bucket :: BucketName
$sel:bucket:GetBucketNotificationConfiguration' :: GetBucketNotificationConfiguration -> BucketName
bucket} -> BucketName
bucket) (\s :: GetBucketNotificationConfiguration
s@GetBucketNotificationConfiguration' {} BucketName
a -> GetBucketNotificationConfiguration
s {$sel:bucket:GetBucketNotificationConfiguration' :: BucketName
bucket = BucketName
a} :: GetBucketNotificationConfiguration)

instance
  Core.AWSRequest
    GetBucketNotificationConfiguration
  where
  type
    AWSResponse GetBucketNotificationConfiguration =
      NotificationConfiguration
  request :: GetBucketNotificationConfiguration
-> Request GetBucketNotificationConfiguration
request =
    Request GetBucketNotificationConfiguration
-> Request GetBucketNotificationConfiguration
forall a. Request a -> Request a
Request.s3vhost
      (Request GetBucketNotificationConfiguration
 -> Request GetBucketNotificationConfiguration)
-> (GetBucketNotificationConfiguration
    -> Request GetBucketNotificationConfiguration)
-> GetBucketNotificationConfiguration
-> Request GetBucketNotificationConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Service
-> GetBucketNotificationConfiguration
-> Request GetBucketNotificationConfiguration
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetBucketNotificationConfiguration
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse (AWSResponse GetBucketNotificationConfiguration)))
response =
    (Int
 -> ResponseHeaders
 -> [Node]
 -> Either String (AWSResponse GetBucketNotificationConfiguration))
-> Logger
-> Service
-> Proxy GetBucketNotificationConfiguration
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse (AWSResponse GetBucketNotificationConfiguration)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXML (\Int
s ResponseHeaders
h [Node]
x -> [Node] -> Either String NotificationConfiguration
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)

instance
  Prelude.Hashable
    GetBucketNotificationConfiguration

instance
  Prelude.NFData
    GetBucketNotificationConfiguration

instance
  Core.ToHeaders
    GetBucketNotificationConfiguration
  where
  toHeaders :: GetBucketNotificationConfiguration -> ResponseHeaders
toHeaders GetBucketNotificationConfiguration' {Maybe Text
BucketName
bucket :: BucketName
expectedBucketOwner :: Maybe Text
$sel:bucket:GetBucketNotificationConfiguration' :: GetBucketNotificationConfiguration -> BucketName
$sel:expectedBucketOwner:GetBucketNotificationConfiguration' :: GetBucketNotificationConfiguration -> Maybe Text
..} =
    [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ HeaderName
"x-amz-expected-bucket-owner"
          HeaderName -> Maybe Text -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Maybe Text
expectedBucketOwner
      ]

instance
  Core.ToPath
    GetBucketNotificationConfiguration
  where
  toPath :: GetBucketNotificationConfiguration -> ByteString
toPath GetBucketNotificationConfiguration' {Maybe Text
BucketName
bucket :: BucketName
expectedBucketOwner :: Maybe Text
$sel:bucket:GetBucketNotificationConfiguration' :: GetBucketNotificationConfiguration -> BucketName
$sel:expectedBucketOwner:GetBucketNotificationConfiguration' :: GetBucketNotificationConfiguration -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/", BucketName -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS BucketName
bucket]

instance
  Core.ToQuery
    GetBucketNotificationConfiguration
  where
  toQuery :: GetBucketNotificationConfiguration -> QueryString
toQuery =
    QueryString -> GetBucketNotificationConfiguration -> QueryString
forall a b. a -> b -> a
Prelude.const ([QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [QueryString
"notification"])