Skip to content

Commit

Permalink
ListBuckets API implementation. The Response object for the API. (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
BigUstad authored Sep 15, 2020
1 parent d49910c commit dd1342c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
16 changes: 4 additions & 12 deletions Minio/ApiEndpoints/BucketOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,28 +142,20 @@ public partial class MinioClient : IBucketOperations
await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
}


/// <summary>
/// List all objects in a bucket
/// List all the buckets for the current Endpoint URL
/// </summary>
/// <param name="cancellationToken">Optional cancellation token to cancel the operation</param>
/// <returns>Task with an iterator lazily populated with objects</returns>
public async Task<ListAllMyBucketsResult> ListBucketsAsync(CancellationToken cancellationToken = default(CancellationToken))
{
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;
}


/// <summary>
/// Create a private bucket with the given name.
/// </summary>
Expand Down
30 changes: 23 additions & 7 deletions Minio/DataModel/BucketOperationsReponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit dd1342c

Please sign in to comment.