{-# 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.GetBucketAcl
-- 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)
--
-- This implementation of the @GET@ action uses the @acl@ subresource to
-- return the access control list (ACL) of a bucket. To use @GET@ to return
-- the ACL of the bucket, you must have @READ_ACP@ access to the bucket. If
-- @READ_ACP@ permission is granted to the anonymous user, you can return
-- the ACL of the bucket without using an authorization header.
--
-- __Related Resources__
--
-- -   <https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjects.html ListObjects>
module Amazonka.S3.GetBucketAcl
  ( -- * Creating a Request
    GetBucketAcl (..),
    newGetBucketAcl,

    -- * Request Lenses
    getBucketAcl_expectedBucketOwner,
    getBucketAcl_bucket,

    -- * Destructuring the Response
    GetBucketAclResponse (..),
    newGetBucketAclResponse,

    -- * Response Lenses
    getBucketAclResponse_grants,
    getBucketAclResponse_owner,
    getBucketAclResponse_httpStatus,
  )
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:/ 'newGetBucketAcl' smart constructor.
data GetBucketAcl = GetBucketAcl'
  { -- | 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.
    GetBucketAcl -> Maybe Text
expectedBucketOwner :: Prelude.Maybe Prelude.Text,
    -- | Specifies the S3 bucket whose ACL is being requested.
    GetBucketAcl -> BucketName
bucket :: BucketName
  }
  deriving (GetBucketAcl -> GetBucketAcl -> Bool
(GetBucketAcl -> GetBucketAcl -> Bool)
-> (GetBucketAcl -> GetBucketAcl -> Bool) -> Eq GetBucketAcl
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetBucketAcl -> GetBucketAcl -> Bool
$c/= :: GetBucketAcl -> GetBucketAcl -> Bool
== :: GetBucketAcl -> GetBucketAcl -> Bool
$c== :: GetBucketAcl -> GetBucketAcl -> Bool
Prelude.Eq, ReadPrec [GetBucketAcl]
ReadPrec GetBucketAcl
Int -> ReadS GetBucketAcl
ReadS [GetBucketAcl]
(Int -> ReadS GetBucketAcl)
-> ReadS [GetBucketAcl]
-> ReadPrec GetBucketAcl
-> ReadPrec [GetBucketAcl]
-> Read GetBucketAcl
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetBucketAcl]
$creadListPrec :: ReadPrec [GetBucketAcl]
readPrec :: ReadPrec GetBucketAcl
$creadPrec :: ReadPrec GetBucketAcl
readList :: ReadS [GetBucketAcl]
$creadList :: ReadS [GetBucketAcl]
readsPrec :: Int -> ReadS GetBucketAcl
$creadsPrec :: Int -> ReadS GetBucketAcl
Prelude.Read, Int -> GetBucketAcl -> ShowS
[GetBucketAcl] -> ShowS
GetBucketAcl -> String
(Int -> GetBucketAcl -> ShowS)
-> (GetBucketAcl -> String)
-> ([GetBucketAcl] -> ShowS)
-> Show GetBucketAcl
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetBucketAcl] -> ShowS
$cshowList :: [GetBucketAcl] -> ShowS
show :: GetBucketAcl -> String
$cshow :: GetBucketAcl -> String
showsPrec :: Int -> GetBucketAcl -> ShowS
$cshowsPrec :: Int -> GetBucketAcl -> ShowS
Prelude.Show, (forall x. GetBucketAcl -> Rep GetBucketAcl x)
-> (forall x. Rep GetBucketAcl x -> GetBucketAcl)
-> Generic GetBucketAcl
forall x. Rep GetBucketAcl x -> GetBucketAcl
forall x. GetBucketAcl -> Rep GetBucketAcl x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetBucketAcl x -> GetBucketAcl
$cfrom :: forall x. GetBucketAcl -> Rep GetBucketAcl x
Prelude.Generic)

-- |
-- Create a value of 'GetBucketAcl' 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', 'getBucketAcl_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', 'getBucketAcl_bucket' - Specifies the S3 bucket whose ACL is being requested.
newGetBucketAcl ::
  -- | 'bucket'
  BucketName ->
  GetBucketAcl
newGetBucketAcl :: BucketName -> GetBucketAcl
newGetBucketAcl BucketName
pBucket_ =
  GetBucketAcl' :: Maybe Text -> BucketName -> GetBucketAcl
GetBucketAcl'
    { $sel:expectedBucketOwner:GetBucketAcl' :: Maybe Text
expectedBucketOwner =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:bucket:GetBucketAcl' :: 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.
getBucketAcl_expectedBucketOwner :: Lens.Lens' GetBucketAcl (Prelude.Maybe Prelude.Text)
getBucketAcl_expectedBucketOwner :: (Maybe Text -> f (Maybe Text)) -> GetBucketAcl -> f GetBucketAcl
getBucketAcl_expectedBucketOwner = (GetBucketAcl -> Maybe Text)
-> (GetBucketAcl -> Maybe Text -> GetBucketAcl)
-> Lens GetBucketAcl GetBucketAcl (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketAcl' {Maybe Text
expectedBucketOwner :: Maybe Text
$sel:expectedBucketOwner:GetBucketAcl' :: GetBucketAcl -> Maybe Text
expectedBucketOwner} -> Maybe Text
expectedBucketOwner) (\s :: GetBucketAcl
s@GetBucketAcl' {} Maybe Text
a -> GetBucketAcl
s {$sel:expectedBucketOwner:GetBucketAcl' :: Maybe Text
expectedBucketOwner = Maybe Text
a} :: GetBucketAcl)

-- | Specifies the S3 bucket whose ACL is being requested.
getBucketAcl_bucket :: Lens.Lens' GetBucketAcl BucketName
getBucketAcl_bucket :: (BucketName -> f BucketName) -> GetBucketAcl -> f GetBucketAcl
getBucketAcl_bucket = (GetBucketAcl -> BucketName)
-> (GetBucketAcl -> BucketName -> GetBucketAcl)
-> Lens GetBucketAcl GetBucketAcl BucketName BucketName
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketAcl' {BucketName
bucket :: BucketName
$sel:bucket:GetBucketAcl' :: GetBucketAcl -> BucketName
bucket} -> BucketName
bucket) (\s :: GetBucketAcl
s@GetBucketAcl' {} BucketName
a -> GetBucketAcl
s {$sel:bucket:GetBucketAcl' :: BucketName
bucket = BucketName
a} :: GetBucketAcl)

instance Core.AWSRequest GetBucketAcl where
  type AWSResponse GetBucketAcl = GetBucketAclResponse
  request :: GetBucketAcl -> Request GetBucketAcl
request =
    Request GetBucketAcl -> Request GetBucketAcl
forall a. Request a -> Request a
Request.s3vhost
      (Request GetBucketAcl -> Request GetBucketAcl)
-> (GetBucketAcl -> Request GetBucketAcl)
-> GetBucketAcl
-> Request GetBucketAcl
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Service -> GetBucketAcl -> Request GetBucketAcl
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetBucketAcl
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetBucketAcl)))
response =
    (Int
 -> ResponseHeaders
 -> [Node]
 -> Either String (AWSResponse GetBucketAcl))
-> Logger
-> Service
-> Proxy GetBucketAcl
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetBucketAcl)))
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 ->
          Maybe [Grant] -> Maybe Owner -> Int -> GetBucketAclResponse
GetBucketAclResponse'
            (Maybe [Grant] -> Maybe Owner -> Int -> GetBucketAclResponse)
-> Either String (Maybe [Grant])
-> Either String (Maybe Owner -> Int -> GetBucketAclResponse)
forall (f :: * -> *) a b. Functor 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
"AccessControlList"
                            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 (Maybe [Grant]))
-> Either String (Maybe [Grant])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [Grant])
-> [Node] -> Either String (Maybe [Grant])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [Grant]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"Grant")
                        )
            Either String (Maybe Owner -> Int -> GetBucketAclResponse)
-> Either String (Maybe Owner)
-> Either String (Int -> GetBucketAclResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Owner)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Owner")
            Either String (Int -> GetBucketAclResponse)
-> Either String Int -> Either String GetBucketAclResponse
forall (f :: * -> *) a b. Applicative f => 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))
      )

instance Prelude.Hashable GetBucketAcl

instance Prelude.NFData GetBucketAcl

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

-- | /See:/ 'newGetBucketAclResponse' smart constructor.
data GetBucketAclResponse = GetBucketAclResponse'
  { -- | A list of grants.
    GetBucketAclResponse -> Maybe [Grant]
grants :: Prelude.Maybe [Grant],
    -- | Container for the bucket owner\'s display name and ID.
    GetBucketAclResponse -> Maybe Owner
owner :: Prelude.Maybe Owner,
    -- | The response's http status code.
    GetBucketAclResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetBucketAclResponse -> GetBucketAclResponse -> Bool
(GetBucketAclResponse -> GetBucketAclResponse -> Bool)
-> (GetBucketAclResponse -> GetBucketAclResponse -> Bool)
-> Eq GetBucketAclResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetBucketAclResponse -> GetBucketAclResponse -> Bool
$c/= :: GetBucketAclResponse -> GetBucketAclResponse -> Bool
== :: GetBucketAclResponse -> GetBucketAclResponse -> Bool
$c== :: GetBucketAclResponse -> GetBucketAclResponse -> Bool
Prelude.Eq, ReadPrec [GetBucketAclResponse]
ReadPrec GetBucketAclResponse
Int -> ReadS GetBucketAclResponse
ReadS [GetBucketAclResponse]
(Int -> ReadS GetBucketAclResponse)
-> ReadS [GetBucketAclResponse]
-> ReadPrec GetBucketAclResponse
-> ReadPrec [GetBucketAclResponse]
-> Read GetBucketAclResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetBucketAclResponse]
$creadListPrec :: ReadPrec [GetBucketAclResponse]
readPrec :: ReadPrec GetBucketAclResponse
$creadPrec :: ReadPrec GetBucketAclResponse
readList :: ReadS [GetBucketAclResponse]
$creadList :: ReadS [GetBucketAclResponse]
readsPrec :: Int -> ReadS GetBucketAclResponse
$creadsPrec :: Int -> ReadS GetBucketAclResponse
Prelude.Read, Int -> GetBucketAclResponse -> ShowS
[GetBucketAclResponse] -> ShowS
GetBucketAclResponse -> String
(Int -> GetBucketAclResponse -> ShowS)
-> (GetBucketAclResponse -> String)
-> ([GetBucketAclResponse] -> ShowS)
-> Show GetBucketAclResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetBucketAclResponse] -> ShowS
$cshowList :: [GetBucketAclResponse] -> ShowS
show :: GetBucketAclResponse -> String
$cshow :: GetBucketAclResponse -> String
showsPrec :: Int -> GetBucketAclResponse -> ShowS
$cshowsPrec :: Int -> GetBucketAclResponse -> ShowS
Prelude.Show, (forall x. GetBucketAclResponse -> Rep GetBucketAclResponse x)
-> (forall x. Rep GetBucketAclResponse x -> GetBucketAclResponse)
-> Generic GetBucketAclResponse
forall x. Rep GetBucketAclResponse x -> GetBucketAclResponse
forall x. GetBucketAclResponse -> Rep GetBucketAclResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetBucketAclResponse x -> GetBucketAclResponse
$cfrom :: forall x. GetBucketAclResponse -> Rep GetBucketAclResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetBucketAclResponse' 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:
--
-- 'grants', 'getBucketAclResponse_grants' - A list of grants.
--
-- 'owner', 'getBucketAclResponse_owner' - Container for the bucket owner\'s display name and ID.
--
-- 'httpStatus', 'getBucketAclResponse_httpStatus' - The response's http status code.
newGetBucketAclResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetBucketAclResponse
newGetBucketAclResponse :: Int -> GetBucketAclResponse
newGetBucketAclResponse Int
pHttpStatus_ =
  GetBucketAclResponse' :: Maybe [Grant] -> Maybe Owner -> Int -> GetBucketAclResponse
GetBucketAclResponse'
    { $sel:grants:GetBucketAclResponse' :: Maybe [Grant]
grants = Maybe [Grant]
forall a. Maybe a
Prelude.Nothing,
      $sel:owner:GetBucketAclResponse' :: Maybe Owner
owner = Maybe Owner
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetBucketAclResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of grants.
getBucketAclResponse_grants :: Lens.Lens' GetBucketAclResponse (Prelude.Maybe [Grant])
getBucketAclResponse_grants :: (Maybe [Grant] -> f (Maybe [Grant]))
-> GetBucketAclResponse -> f GetBucketAclResponse
getBucketAclResponse_grants = (GetBucketAclResponse -> Maybe [Grant])
-> (GetBucketAclResponse -> Maybe [Grant] -> GetBucketAclResponse)
-> Lens
     GetBucketAclResponse
     GetBucketAclResponse
     (Maybe [Grant])
     (Maybe [Grant])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketAclResponse' {Maybe [Grant]
grants :: Maybe [Grant]
$sel:grants:GetBucketAclResponse' :: GetBucketAclResponse -> Maybe [Grant]
grants} -> Maybe [Grant]
grants) (\s :: GetBucketAclResponse
s@GetBucketAclResponse' {} Maybe [Grant]
a -> GetBucketAclResponse
s {$sel:grants:GetBucketAclResponse' :: Maybe [Grant]
grants = Maybe [Grant]
a} :: GetBucketAclResponse) ((Maybe [Grant] -> f (Maybe [Grant]))
 -> GetBucketAclResponse -> f GetBucketAclResponse)
-> ((Maybe [Grant] -> f (Maybe [Grant]))
    -> Maybe [Grant] -> f (Maybe [Grant]))
-> (Maybe [Grant] -> f (Maybe [Grant]))
-> GetBucketAclResponse
-> f GetBucketAclResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Grant] [Grant] [Grant] [Grant]
-> Iso
     (Maybe [Grant]) (Maybe [Grant]) (Maybe [Grant]) (Maybe [Grant])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Grant] [Grant] [Grant] [Grant]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Container for the bucket owner\'s display name and ID.
getBucketAclResponse_owner :: Lens.Lens' GetBucketAclResponse (Prelude.Maybe Owner)
getBucketAclResponse_owner :: (Maybe Owner -> f (Maybe Owner))
-> GetBucketAclResponse -> f GetBucketAclResponse
getBucketAclResponse_owner = (GetBucketAclResponse -> Maybe Owner)
-> (GetBucketAclResponse -> Maybe Owner -> GetBucketAclResponse)
-> Lens
     GetBucketAclResponse
     GetBucketAclResponse
     (Maybe Owner)
     (Maybe Owner)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetBucketAclResponse' {Maybe Owner
owner :: Maybe Owner
$sel:owner:GetBucketAclResponse' :: GetBucketAclResponse -> Maybe Owner
owner} -> Maybe Owner
owner) (\s :: GetBucketAclResponse
s@GetBucketAclResponse' {} Maybe Owner
a -> GetBucketAclResponse
s {$sel:owner:GetBucketAclResponse' :: Maybe Owner
owner = Maybe Owner
a} :: GetBucketAclResponse)

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

instance Prelude.NFData GetBucketAclResponse