{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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_eventBridgeConfiguration,
    notificationConfiguration_lambdaFunctionConfigurations,
    notificationConfiguration_queueConfigurations,
    notificationConfiguration_topicConfigurations,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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 fails with the HTTP status code
    -- @403 Forbidden@ (access denied).
    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
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]
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
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.
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 fails with the HTTP status code
-- @403 Forbidden@ (access denied).
--
-- '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'
    { $sel:expectedBucketOwner:GetBucketNotificationConfiguration' :: Maybe Text
expectedBucketOwner =
        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 fails with the HTTP status code
-- @403 Forbidden@ (access denied).
getBucketNotificationConfiguration_expectedBucketOwner :: Lens.Lens' GetBucketNotificationConfiguration (Prelude.Maybe Prelude.Text)
getBucketNotificationConfiguration_expectedBucketOwner :: Lens' GetBucketNotificationConfiguration (Maybe Text)
getBucketNotificationConfiguration_expectedBucketOwner = 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 :: Lens' GetBucketNotificationConfiguration BucketName
getBucketNotificationConfiguration_bucket = 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 :: (Service -> Service)
-> GetBucketNotificationConfiguration
-> Request GetBucketNotificationConfiguration
request Service -> Service
overrides =
    forall a. Request a -> Request a
Request.s3vhost
      forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetBucketNotificationConfiguration
-> ClientResponse ClientBody
-> m (Either
        Error
        (ClientResponse (AWSResponse GetBucketNotificationConfiguration)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXML (\Int
s ResponseHeaders
h [Node]
x -> forall a. FromXML a => [Node] -> Either String a
Data.parseXML [Node]
x)

instance
  Prelude.Hashable
    GetBucketNotificationConfiguration
  where
  hashWithSalt :: Int -> GetBucketNotificationConfiguration -> Int
hashWithSalt
    Int
_salt
    GetBucketNotificationConfiguration' {Maybe Text
BucketName
bucket :: BucketName
expectedBucketOwner :: Maybe Text
$sel:bucket:GetBucketNotificationConfiguration' :: GetBucketNotificationConfiguration -> BucketName
$sel:expectedBucketOwner:GetBucketNotificationConfiguration' :: GetBucketNotificationConfiguration -> Maybe Text
..} =
      Int
_salt
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
expectedBucketOwner
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` BucketName
bucket

instance
  Prelude.NFData
    GetBucketNotificationConfiguration
  where
  rnf :: GetBucketNotificationConfiguration -> ()
rnf GetBucketNotificationConfiguration' {Maybe Text
BucketName
bucket :: BucketName
expectedBucketOwner :: Maybe Text
$sel:bucket:GetBucketNotificationConfiguration' :: GetBucketNotificationConfiguration -> BucketName
$sel:expectedBucketOwner:GetBucketNotificationConfiguration' :: GetBucketNotificationConfiguration -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
expectedBucketOwner
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf BucketName
bucket

instance
  Data.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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ HeaderName
"x-amz-expected-bucket-owner"
          forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# Maybe Text
expectedBucketOwner
      ]

instance
  Data.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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/", forall a. ToByteString a => a -> ByteString
Data.toBS BucketName
bucket]

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