{-# 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.ListBuckets
-- 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 a list of all buckets owned by the authenticated sender of the
-- request.
module Amazonka.S3.ListBuckets
  ( -- * Creating a Request
    ListBuckets (..),
    newListBuckets,

    -- * Destructuring the Response
    ListBucketsResponse (..),
    newListBucketsResponse,

    -- * Response Lenses
    listBucketsResponse_buckets,
    listBucketsResponse_owner,
    listBucketsResponse_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:/ 'newListBuckets' smart constructor.
data ListBuckets = ListBuckets'
  {
  }
  deriving (ListBuckets -> ListBuckets -> Bool
(ListBuckets -> ListBuckets -> Bool)
-> (ListBuckets -> ListBuckets -> Bool) -> Eq ListBuckets
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListBuckets -> ListBuckets -> Bool
$c/= :: ListBuckets -> ListBuckets -> Bool
== :: ListBuckets -> ListBuckets -> Bool
$c== :: ListBuckets -> ListBuckets -> Bool
Prelude.Eq, ReadPrec [ListBuckets]
ReadPrec ListBuckets
Int -> ReadS ListBuckets
ReadS [ListBuckets]
(Int -> ReadS ListBuckets)
-> ReadS [ListBuckets]
-> ReadPrec ListBuckets
-> ReadPrec [ListBuckets]
-> Read ListBuckets
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListBuckets]
$creadListPrec :: ReadPrec [ListBuckets]
readPrec :: ReadPrec ListBuckets
$creadPrec :: ReadPrec ListBuckets
readList :: ReadS [ListBuckets]
$creadList :: ReadS [ListBuckets]
readsPrec :: Int -> ReadS ListBuckets
$creadsPrec :: Int -> ReadS ListBuckets
Prelude.Read, Int -> ListBuckets -> ShowS
[ListBuckets] -> ShowS
ListBuckets -> String
(Int -> ListBuckets -> ShowS)
-> (ListBuckets -> String)
-> ([ListBuckets] -> ShowS)
-> Show ListBuckets
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListBuckets] -> ShowS
$cshowList :: [ListBuckets] -> ShowS
show :: ListBuckets -> String
$cshow :: ListBuckets -> String
showsPrec :: Int -> ListBuckets -> ShowS
$cshowsPrec :: Int -> ListBuckets -> ShowS
Prelude.Show, (forall x. ListBuckets -> Rep ListBuckets x)
-> (forall x. Rep ListBuckets x -> ListBuckets)
-> Generic ListBuckets
forall x. Rep ListBuckets x -> ListBuckets
forall x. ListBuckets -> Rep ListBuckets x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListBuckets x -> ListBuckets
$cfrom :: forall x. ListBuckets -> Rep ListBuckets x
Prelude.Generic)

-- |
-- Create a value of 'ListBuckets' 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.
newListBuckets ::
  ListBuckets
newListBuckets :: ListBuckets
newListBuckets = ListBuckets
ListBuckets'

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

instance Prelude.NFData ListBuckets

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

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

instance Core.ToQuery ListBuckets where
  toQuery :: ListBuckets -> QueryString
toQuery = QueryString -> ListBuckets -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newListBucketsResponse' smart constructor.
data ListBucketsResponse = ListBucketsResponse'
  { -- | The list of buckets owned by the requestor.
    ListBucketsResponse -> Maybe [Bucket]
buckets :: Prelude.Maybe [Bucket],
    -- | The owner of the buckets listed.
    ListBucketsResponse -> Maybe Owner
owner :: Prelude.Maybe Owner,
    -- | The response's http status code.
    ListBucketsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListBucketsResponse -> ListBucketsResponse -> Bool
(ListBucketsResponse -> ListBucketsResponse -> Bool)
-> (ListBucketsResponse -> ListBucketsResponse -> Bool)
-> Eq ListBucketsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListBucketsResponse -> ListBucketsResponse -> Bool
$c/= :: ListBucketsResponse -> ListBucketsResponse -> Bool
== :: ListBucketsResponse -> ListBucketsResponse -> Bool
$c== :: ListBucketsResponse -> ListBucketsResponse -> Bool
Prelude.Eq, ReadPrec [ListBucketsResponse]
ReadPrec ListBucketsResponse
Int -> ReadS ListBucketsResponse
ReadS [ListBucketsResponse]
(Int -> ReadS ListBucketsResponse)
-> ReadS [ListBucketsResponse]
-> ReadPrec ListBucketsResponse
-> ReadPrec [ListBucketsResponse]
-> Read ListBucketsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListBucketsResponse]
$creadListPrec :: ReadPrec [ListBucketsResponse]
readPrec :: ReadPrec ListBucketsResponse
$creadPrec :: ReadPrec ListBucketsResponse
readList :: ReadS [ListBucketsResponse]
$creadList :: ReadS [ListBucketsResponse]
readsPrec :: Int -> ReadS ListBucketsResponse
$creadsPrec :: Int -> ReadS ListBucketsResponse
Prelude.Read, Int -> ListBucketsResponse -> ShowS
[ListBucketsResponse] -> ShowS
ListBucketsResponse -> String
(Int -> ListBucketsResponse -> ShowS)
-> (ListBucketsResponse -> String)
-> ([ListBucketsResponse] -> ShowS)
-> Show ListBucketsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListBucketsResponse] -> ShowS
$cshowList :: [ListBucketsResponse] -> ShowS
show :: ListBucketsResponse -> String
$cshow :: ListBucketsResponse -> String
showsPrec :: Int -> ListBucketsResponse -> ShowS
$cshowsPrec :: Int -> ListBucketsResponse -> ShowS
Prelude.Show, (forall x. ListBucketsResponse -> Rep ListBucketsResponse x)
-> (forall x. Rep ListBucketsResponse x -> ListBucketsResponse)
-> Generic ListBucketsResponse
forall x. Rep ListBucketsResponse x -> ListBucketsResponse
forall x. ListBucketsResponse -> Rep ListBucketsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListBucketsResponse x -> ListBucketsResponse
$cfrom :: forall x. ListBucketsResponse -> Rep ListBucketsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListBucketsResponse' 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:
--
-- 'buckets', 'listBucketsResponse_buckets' - The list of buckets owned by the requestor.
--
-- 'owner', 'listBucketsResponse_owner' - The owner of the buckets listed.
--
-- 'httpStatus', 'listBucketsResponse_httpStatus' - The response's http status code.
newListBucketsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListBucketsResponse
newListBucketsResponse :: Int -> ListBucketsResponse
newListBucketsResponse Int
pHttpStatus_ =
  ListBucketsResponse' :: Maybe [Bucket] -> Maybe Owner -> Int -> ListBucketsResponse
ListBucketsResponse'
    { $sel:buckets:ListBucketsResponse' :: Maybe [Bucket]
buckets = Maybe [Bucket]
forall a. Maybe a
Prelude.Nothing,
      $sel:owner:ListBucketsResponse' :: Maybe Owner
owner = Maybe Owner
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListBucketsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The list of buckets owned by the requestor.
listBucketsResponse_buckets :: Lens.Lens' ListBucketsResponse (Prelude.Maybe [Bucket])
listBucketsResponse_buckets :: (Maybe [Bucket] -> f (Maybe [Bucket]))
-> ListBucketsResponse -> f ListBucketsResponse
listBucketsResponse_buckets = (ListBucketsResponse -> Maybe [Bucket])
-> (ListBucketsResponse -> Maybe [Bucket] -> ListBucketsResponse)
-> Lens
     ListBucketsResponse
     ListBucketsResponse
     (Maybe [Bucket])
     (Maybe [Bucket])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListBucketsResponse' {Maybe [Bucket]
buckets :: Maybe [Bucket]
$sel:buckets:ListBucketsResponse' :: ListBucketsResponse -> Maybe [Bucket]
buckets} -> Maybe [Bucket]
buckets) (\s :: ListBucketsResponse
s@ListBucketsResponse' {} Maybe [Bucket]
a -> ListBucketsResponse
s {$sel:buckets:ListBucketsResponse' :: Maybe [Bucket]
buckets = Maybe [Bucket]
a} :: ListBucketsResponse) ((Maybe [Bucket] -> f (Maybe [Bucket]))
 -> ListBucketsResponse -> f ListBucketsResponse)
-> ((Maybe [Bucket] -> f (Maybe [Bucket]))
    -> Maybe [Bucket] -> f (Maybe [Bucket]))
-> (Maybe [Bucket] -> f (Maybe [Bucket]))
-> ListBucketsResponse
-> f ListBucketsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Bucket] [Bucket] [Bucket] [Bucket]
-> Iso
     (Maybe [Bucket]) (Maybe [Bucket]) (Maybe [Bucket]) (Maybe [Bucket])
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 [Bucket] [Bucket] [Bucket] [Bucket]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The owner of the buckets listed.
listBucketsResponse_owner :: Lens.Lens' ListBucketsResponse (Prelude.Maybe Owner)
listBucketsResponse_owner :: (Maybe Owner -> f (Maybe Owner))
-> ListBucketsResponse -> f ListBucketsResponse
listBucketsResponse_owner = (ListBucketsResponse -> Maybe Owner)
-> (ListBucketsResponse -> Maybe Owner -> ListBucketsResponse)
-> Lens
     ListBucketsResponse ListBucketsResponse (Maybe Owner) (Maybe Owner)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListBucketsResponse' {Maybe Owner
owner :: Maybe Owner
$sel:owner:ListBucketsResponse' :: ListBucketsResponse -> Maybe Owner
owner} -> Maybe Owner
owner) (\s :: ListBucketsResponse
s@ListBucketsResponse' {} Maybe Owner
a -> ListBucketsResponse
s {$sel:owner:ListBucketsResponse' :: Maybe Owner
owner = Maybe Owner
a} :: ListBucketsResponse)

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

instance Prelude.NFData ListBucketsResponse