{-# 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.GetBucketTagging
-- 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 tag set associated with the bucket.
--
-- To use this operation, you must have permission to perform the
-- @s3:GetBucketTagging@ action. By default, the bucket owner has this
-- permission and can grant this permission to others.
--
-- @GetBucketTagging@ has the following special error:
--
-- -   Error code: @NoSuchTagSetError@
--
--     -   Description: There is no tag set associated with the bucket.
--
-- The following operations are related to @GetBucketTagging@:
--
-- -   <https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketTagging.html PutBucketTagging>
--
-- -   <https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteBucketTagging.html DeleteBucketTagging>
module Amazonka.S3.GetBucketTagging
  ( -- * Creating a Request
    GetBucketTagging (..),
    newGetBucketTagging,

    -- * Request Lenses
    getBucketTagging_expectedBucketOwner,
    getBucketTagging_bucket,

    -- * Destructuring the Response
    GetBucketTaggingResponse (..),
    newGetBucketTaggingResponse,

    -- * Response Lenses
    getBucketTaggingResponse_httpStatus,
    getBucketTaggingResponse_tagSet,
  )
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:/ 'newGetBucketTagging' smart constructor.
data GetBucketTagging = GetBucketTagging'
  { -- | 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.
    GetBucketTagging -> Maybe Text
expectedBucketOwner :: Prelude.Maybe Prelude.Text,
    -- | The name of the bucket for which to get the tagging information.
    GetBucketTagging -> BucketName
bucket :: BucketName
  }
  deriving (GetBucketTagging -> GetBucketTagging -> Bool
(GetBucketTagging -> GetBucketTagging -> Bool)
-> (GetBucketTagging -> GetBucketTagging -> Bool)
-> Eq GetBucketTagging
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetBucketTagging -> GetBucketTagging -> Bool
$c/= :: GetBucketTagging -> GetBucketTagging -> Bool
== :: GetBucketTagging -> GetBucketTagging -> Bool
$c== :: GetBucketTagging -> GetBucketTagging -> Bool
Prelude.Eq, ReadPrec [GetBucketTagging]
ReadPrec GetBucketTagging
Int -> ReadS GetBucketTagging
ReadS [GetBucketTagging]
(Int -> ReadS GetBucketTagging)
-> ReadS [GetBucketTagging]
-> ReadPrec GetBucketTagging
-> ReadPrec [GetBucketTagging]
-> Read GetBucketTagging
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetBucketTagging]
$creadListPrec :: ReadPrec [GetBucketTagging]
readPrec :: ReadPrec GetBucketTagging
$creadPrec :: ReadPrec GetBucketTagging
readList :: ReadS [GetBucketTagging]
$creadList :: ReadS [GetBucketTagging]
readsPrec :: Int -> ReadS GetBucketTagging
$creadsPrec :: Int -> ReadS GetBucketTagging
Prelude.Read, Int -> GetBucketTagging -> ShowS
[GetBucketTagging] -> ShowS
GetBucketTagging -> String
(Int -> GetBucketTagging -> ShowS)
-> (GetBucketTagging -> String)
-> ([GetBucketTagging] -> ShowS)
-> Show GetBucketTagging
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetBucketTagging] -> ShowS
$cshowList :: [GetBucketTagging] -> ShowS
show :: GetBucketTagging -> String
$cshow :: GetBucketTagging -> String
showsPrec :: Int -> GetBucketTagging -> ShowS
$cshowsPrec :: Int -> GetBucketTagging -> ShowS
Prelude.Show, (forall x. GetBucketTagging -> Rep GetBucketTagging x)
-> (forall x. Rep GetBucketTagging x -> GetBucketTagging)
-> Generic GetBucketTagging
forall x. Rep GetBucketTagging x -> GetBucketTagging
forall x. GetBucketTagging -> Rep GetBucketTagging x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetBucketTagging x -> GetBucketTagging
$cfrom :: forall x. GetBucketTagging -> Rep GetBucketTagging x
Prelude.Generic)

-- |
-- Create a value of 'GetBucketTagging' 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', 'getBucketTagging_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', 'getBucketTagging_bucket' - The name of the bucket for which to get the tagging information.
newGetBucketTagging ::
  -- | 'bucket'
  BucketName ->
  GetBucketTagging
newGetBucketTagging :: BucketName -> GetBucketTagging
newGetBucketTagging BucketName
pBucket_ =
  GetBucketTagging' :: Maybe Text -> BucketName -> GetBucketTagging
GetBucketTagging'
    { $sel:expectedBucketOwner:GetBucketTagging' :: Maybe Text
expectedBucketOwner =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:bucket:GetBucketTagging' :: 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.
getBucketTagging_expectedBucketOwner :: Lens.Lens' GetBucketTagging (Prelude.Maybe Prelude.Text)
getBucketTagging_expectedBucketOwner :: (Maybe Text -> f (Maybe Text))
-> GetBucketTagging -> f GetBucketTagging
getBucketTagging_expectedBucketOwner = (GetBucketTagging -> Maybe Text)
-> (GetBucketTagging -> Maybe Text -> GetBucketTagging)
-> Lens GetBucketTagging GetBucketTagging (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketTagging' {Maybe Text
expectedBucketOwner :: Maybe Text
$sel:expectedBucketOwner:GetBucketTagging' :: GetBucketTagging -> Maybe Text
expectedBucketOwner} -> Maybe Text
expectedBucketOwner) (\s :: GetBucketTagging
s@GetBucketTagging' {} Maybe Text
a -> GetBucketTagging
s {$sel:expectedBucketOwner:GetBucketTagging' :: Maybe Text
expectedBucketOwner = Maybe Text
a} :: GetBucketTagging)

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

instance Core.AWSRequest GetBucketTagging where
  type
    AWSResponse GetBucketTagging =
      GetBucketTaggingResponse
  request :: GetBucketTagging -> Request GetBucketTagging
request =
    Request GetBucketTagging -> Request GetBucketTagging
forall a. Request a -> Request a
Request.s3vhost
      (Request GetBucketTagging -> Request GetBucketTagging)
-> (GetBucketTagging -> Request GetBucketTagging)
-> GetBucketTagging
-> Request GetBucketTagging
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Service -> GetBucketTagging -> Request GetBucketTagging
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetBucketTagging
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetBucketTagging)))
response =
    (Int
 -> ResponseHeaders
 -> [Node]
 -> Either String (AWSResponse GetBucketTagging))
-> Logger
-> Service
-> Proxy GetBucketTagging
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetBucketTagging)))
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 ->
          Int -> [Tag] -> GetBucketTaggingResponse
GetBucketTaggingResponse'
            (Int -> [Tag] -> GetBucketTaggingResponse)
-> Either String Int
-> Either String ([Tag] -> GetBucketTaggingResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            Either String ([Tag] -> GetBucketTaggingResponse)
-> Either String [Tag] -> Either String GetBucketTaggingResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"TagSet" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                            Either String [Node]
-> ([Node] -> Either String [Tag]) -> Either String [Tag]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= Text -> [Node] -> Either String [Tag]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"Tag"
                        )
      )

instance Prelude.Hashable GetBucketTagging

instance Prelude.NFData GetBucketTagging

instance Core.ToHeaders GetBucketTagging where
  toHeaders :: GetBucketTagging -> ResponseHeaders
toHeaders GetBucketTagging' {Maybe Text
BucketName
bucket :: BucketName
expectedBucketOwner :: Maybe Text
$sel:bucket:GetBucketTagging' :: GetBucketTagging -> BucketName
$sel:expectedBucketOwner:GetBucketTagging' :: GetBucketTagging -> 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 GetBucketTagging where
  toPath :: GetBucketTagging -> ByteString
toPath GetBucketTagging' {Maybe Text
BucketName
bucket :: BucketName
expectedBucketOwner :: Maybe Text
$sel:bucket:GetBucketTagging' :: GetBucketTagging -> BucketName
$sel:expectedBucketOwner:GetBucketTagging' :: GetBucketTagging -> 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 GetBucketTagging where
  toQuery :: GetBucketTagging -> QueryString
toQuery = QueryString -> GetBucketTagging -> QueryString
forall a b. a -> b -> a
Prelude.const ([QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [QueryString
"tagging"])

-- | /See:/ 'newGetBucketTaggingResponse' smart constructor.
data GetBucketTaggingResponse = GetBucketTaggingResponse'
  { -- | The response's http status code.
    GetBucketTaggingResponse -> Int
httpStatus :: Prelude.Int,
    -- | Contains the tag set.
    GetBucketTaggingResponse -> [Tag]
tagSet :: [Tag]
  }
  deriving (GetBucketTaggingResponse -> GetBucketTaggingResponse -> Bool
(GetBucketTaggingResponse -> GetBucketTaggingResponse -> Bool)
-> (GetBucketTaggingResponse -> GetBucketTaggingResponse -> Bool)
-> Eq GetBucketTaggingResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetBucketTaggingResponse -> GetBucketTaggingResponse -> Bool
$c/= :: GetBucketTaggingResponse -> GetBucketTaggingResponse -> Bool
== :: GetBucketTaggingResponse -> GetBucketTaggingResponse -> Bool
$c== :: GetBucketTaggingResponse -> GetBucketTaggingResponse -> Bool
Prelude.Eq, ReadPrec [GetBucketTaggingResponse]
ReadPrec GetBucketTaggingResponse
Int -> ReadS GetBucketTaggingResponse
ReadS [GetBucketTaggingResponse]
(Int -> ReadS GetBucketTaggingResponse)
-> ReadS [GetBucketTaggingResponse]
-> ReadPrec GetBucketTaggingResponse
-> ReadPrec [GetBucketTaggingResponse]
-> Read GetBucketTaggingResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetBucketTaggingResponse]
$creadListPrec :: ReadPrec [GetBucketTaggingResponse]
readPrec :: ReadPrec GetBucketTaggingResponse
$creadPrec :: ReadPrec GetBucketTaggingResponse
readList :: ReadS [GetBucketTaggingResponse]
$creadList :: ReadS [GetBucketTaggingResponse]
readsPrec :: Int -> ReadS GetBucketTaggingResponse
$creadsPrec :: Int -> ReadS GetBucketTaggingResponse
Prelude.Read, Int -> GetBucketTaggingResponse -> ShowS
[GetBucketTaggingResponse] -> ShowS
GetBucketTaggingResponse -> String
(Int -> GetBucketTaggingResponse -> ShowS)
-> (GetBucketTaggingResponse -> String)
-> ([GetBucketTaggingResponse] -> ShowS)
-> Show GetBucketTaggingResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetBucketTaggingResponse] -> ShowS
$cshowList :: [GetBucketTaggingResponse] -> ShowS
show :: GetBucketTaggingResponse -> String
$cshow :: GetBucketTaggingResponse -> String
showsPrec :: Int -> GetBucketTaggingResponse -> ShowS
$cshowsPrec :: Int -> GetBucketTaggingResponse -> ShowS
Prelude.Show, (forall x.
 GetBucketTaggingResponse -> Rep GetBucketTaggingResponse x)
-> (forall x.
    Rep GetBucketTaggingResponse x -> GetBucketTaggingResponse)
-> Generic GetBucketTaggingResponse
forall x.
Rep GetBucketTaggingResponse x -> GetBucketTaggingResponse
forall x.
GetBucketTaggingResponse -> Rep GetBucketTaggingResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetBucketTaggingResponse x -> GetBucketTaggingResponse
$cfrom :: forall x.
GetBucketTaggingResponse -> Rep GetBucketTaggingResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetBucketTaggingResponse' 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:
--
-- 'httpStatus', 'getBucketTaggingResponse_httpStatus' - The response's http status code.
--
-- 'tagSet', 'getBucketTaggingResponse_tagSet' - Contains the tag set.
newGetBucketTaggingResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetBucketTaggingResponse
newGetBucketTaggingResponse :: Int -> GetBucketTaggingResponse
newGetBucketTaggingResponse Int
pHttpStatus_ =
  GetBucketTaggingResponse' :: Int -> [Tag] -> GetBucketTaggingResponse
GetBucketTaggingResponse'
    { $sel:httpStatus:GetBucketTaggingResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:tagSet:GetBucketTaggingResponse' :: [Tag]
tagSet = [Tag]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The response's http status code.
getBucketTaggingResponse_httpStatus :: Lens.Lens' GetBucketTaggingResponse Prelude.Int
getBucketTaggingResponse_httpStatus :: (Int -> f Int)
-> GetBucketTaggingResponse -> f GetBucketTaggingResponse
getBucketTaggingResponse_httpStatus = (GetBucketTaggingResponse -> Int)
-> (GetBucketTaggingResponse -> Int -> GetBucketTaggingResponse)
-> Lens GetBucketTaggingResponse GetBucketTaggingResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketTaggingResponse' {Int
httpStatus :: Int
$sel:httpStatus:GetBucketTaggingResponse' :: GetBucketTaggingResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: GetBucketTaggingResponse
s@GetBucketTaggingResponse' {} Int
a -> GetBucketTaggingResponse
s {$sel:httpStatus:GetBucketTaggingResponse' :: Int
httpStatus = Int
a} :: GetBucketTaggingResponse)

-- | Contains the tag set.
getBucketTaggingResponse_tagSet :: Lens.Lens' GetBucketTaggingResponse [Tag]
getBucketTaggingResponse_tagSet :: ([Tag] -> f [Tag])
-> GetBucketTaggingResponse -> f GetBucketTaggingResponse
getBucketTaggingResponse_tagSet = (GetBucketTaggingResponse -> [Tag])
-> (GetBucketTaggingResponse -> [Tag] -> GetBucketTaggingResponse)
-> Lens
     GetBucketTaggingResponse GetBucketTaggingResponse [Tag] [Tag]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketTaggingResponse' {[Tag]
tagSet :: [Tag]
$sel:tagSet:GetBucketTaggingResponse' :: GetBucketTaggingResponse -> [Tag]
tagSet} -> [Tag]
tagSet) (\s :: GetBucketTaggingResponse
s@GetBucketTaggingResponse' {} [Tag]
a -> GetBucketTaggingResponse
s {$sel:tagSet:GetBucketTaggingResponse' :: [Tag]
tagSet = [Tag]
a} :: GetBucketTaggingResponse) (([Tag] -> f [Tag])
 -> GetBucketTaggingResponse -> f GetBucketTaggingResponse)
-> (([Tag] -> f [Tag]) -> [Tag] -> f [Tag])
-> ([Tag] -> f [Tag])
-> GetBucketTaggingResponse
-> f GetBucketTaggingResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Tag] -> f [Tag]) -> [Tag] -> f [Tag]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.NFData GetBucketTaggingResponse