From dd1342c7310cce1502944b9a49e7b5d1071c02e6 Mon Sep 17 00:00:00 2001
From: P R <25353498+BigUstad@users.noreply.github.com>
Date: Tue, 15 Sep 2020 15:10:48 -0700
Subject: [PATCH] ListBuckets API implementation. The Response object for the
API. (#457)
---
Minio/ApiEndpoints/BucketOperations.cs | 16 +++---------
Minio/DataModel/BucketOperationsReponse.cs | 30 +++++++++++++++++-----
2 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/Minio/ApiEndpoints/BucketOperations.cs b/Minio/ApiEndpoints/BucketOperations.cs
index 4b0cce362..32a1d657f 100644
--- a/Minio/ApiEndpoints/BucketOperations.cs
+++ b/Minio/ApiEndpoints/BucketOperations.cs
@@ -142,9 +142,8 @@ public partial class MinioClient : IBucketOperations
await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
}
-
///
- /// List all objects in a bucket
+ /// List all the buckets for the current Endpoint URL
///
/// Optional cancellation token to cancel the operation
/// Task with an iterator lazily populated with objects
@@ -152,18 +151,11 @@ public partial class MinioClient : IBucketOperations
{
var request = await this.CreateRequest(Method.GET, resourcePath: "/").ConfigureAwait(false);
var response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
-
- ListAllMyBucketsResult bucketList = new ListAllMyBucketsResult();
- if (HttpStatusCode.OK.Equals(response.StatusCode))
- {
- var contentBytes = System.Text.Encoding.UTF8.GetBytes(response.Content);
- using (var stream = new MemoryStream(contentBytes))
- bucketList = (ListAllMyBucketsResult)new XmlSerializer(typeof(ListAllMyBucketsResult)).Deserialize(stream);
- return bucketList;
- }
- return bucketList;
+ ListBucketsResponse listBucketsResponse = new ListBucketsResponse(response.StatusCode, response.Content);
+ return listBucketsResponse.BucketsResult;
}
+
///
/// Create a private bucket with the given name.
///
diff --git a/Minio/DataModel/BucketOperationsReponse.cs b/Minio/DataModel/BucketOperationsReponse.cs
index 96535eef7..e856692cf 100644
--- a/Minio/DataModel/BucketOperationsReponse.cs
+++ b/Minio/DataModel/BucketOperationsReponse.cs
@@ -25,18 +25,34 @@ internal class GetVersioningResponse : GenericResponse
{
internal VersioningConfiguration VersioningConfig { get; set; }
internal GetVersioningResponse(HttpStatusCode statusCode, string responseContent)
- : base(statusCode, responseContent)
+ : base(statusCode, responseContent)
{
- if ( string.IsNullOrEmpty(responseContent) )
+ if (string.IsNullOrEmpty(responseContent) ||
+ !HttpStatusCode.OK.Equals(statusCode))
{
return;
}
- if (HttpStatusCode.OK.Equals(statusCode))
+ using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(responseContent)))
{
- using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(responseContent)))
- {
- this.VersioningConfig = (VersioningConfiguration)new XmlSerializer(typeof(VersioningConfiguration)).Deserialize(stream);
- }
+ this.VersioningConfig = (VersioningConfiguration)new XmlSerializer(typeof(VersioningConfiguration)).Deserialize(stream);
+ }
+ }
+ }
+
+ internal class ListBucketsResponse : GenericResponse
+ {
+ internal ListAllMyBucketsResult BucketsResult;
+ internal ListBucketsResponse(HttpStatusCode statusCode, string responseContent)
+ : base(statusCode, responseContent)
+ {
+ if (string.IsNullOrEmpty(responseContent) ||
+ !HttpStatusCode.OK.Equals(statusCode))
+ {
+ return;
+ }
+ using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(responseContent)))
+ {
+ this.BucketsResult = (ListAllMyBucketsResult)new XmlSerializer(typeof(ListAllMyBucketsResult)).Deserialize(stream);
}
}
}