Skip to content

Commit

Permalink
Merge branch 'master' into minio-dotnet-tag-reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
sinhaashish authored May 17, 2021
2 parents 6aa92a6 + 285755a commit 57f7e38
Show file tree
Hide file tree
Showing 7 changed files with 652 additions and 81 deletions.
3 changes: 2 additions & 1 deletion Minio.Examples/Cases/GetObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public async static Task Run(MinioClient minio,
.WithBucket(bucketName)
.WithObject(objectName)
.WithFile(fileName);
await minio.GetObjectAsync(args);
var stat = await minio.GetObjectAsync(args);
Console.WriteLine($"Downloaded the file {fileName} in bucket {bucketName}");
Console.WriteLine($"Stat details of object {objectName} in bucket {bucketName}\n" + stat.ToString());
Console.WriteLine();
}
catch (Exception e)
Expand Down
172 changes: 136 additions & 36 deletions Minio/ApiEndpoints/BucketOperations.cs

Large diffs are not rendered by default.

108 changes: 104 additions & 4 deletions Minio/ApiEndpoints/IBucketOperations.cs

Large diffs are not rendered by default.

156 changes: 151 additions & 5 deletions Minio/ApiEndpoints/IObjectOperations.cs

Large diffs are not rendered by default.

163 changes: 134 additions & 29 deletions Minio/ApiEndpoints/ObjectOperations.cs

Large diffs are not rendered by default.

95 changes: 89 additions & 6 deletions Minio/DataModel/ObjectStat.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2017 MinIO, Inc.
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2017-2021 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;

namespace Minio.DataModel
{
Expand Down Expand Up @@ -60,12 +61,51 @@ public static ObjectStat FromResponseHeaders(string objectName, Dictionary<strin
case "x-amz-delete-marker":
objInfo.DeleteMarker = paramValue.Equals("true");
break;
case "x-amz-archive-status":
objInfo.ArchiveStatus = paramValue.ToString();
break;
case "x-amz-tagging-count":
if (Int32.TryParse(paramValue.ToString(), out int tagCount) && tagCount >= 0)
{
objInfo.TaggingCount = (uint)tagCount;
}
break;
case "x-amz-expiration":
// x-amz-expiration header includes the expiration date and the corresponding rule id.
string expirationResponse = paramValue.ToString().Trim();
string expiryDatePattern = @"(Sun|Mon|Tue|Wed|Thu|Fri|Sat), \d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} \d{2}:\d{2}:\d{2} [A-Z]+";
Match expiryMatch = Regex.Match(expirationResponse, expiryDatePattern);
if (expiryMatch.Success)
{
objInfo.Expires = DateTime.SpecifyKind(
DateTime.Parse(expiryMatch.Value),
DateTimeKind.Utc);
}
break;
case "x-amz-object-lock-mode":
Console.WriteLine(paramValue.ToString());
if (!string.IsNullOrWhiteSpace(paramValue.ToString()))
{
objInfo.ObjectLockMode = (paramValue.ToString().ToLower().Equals("governance"))?RetentionMode.GOVERNANCE:RetentionMode.COMPLIANCE;
}
break;
case "x-amz-object-lock-retain-until-date":
Console.WriteLine(paramValue.ToString());
string lockUntilDate = paramValue.ToString();
if (!string.IsNullOrWhiteSpace(lockUntilDate))
{
objInfo.ObjectLockRetainUntilDate = DateTime.SpecifyKind(
DateTime.Parse(lockUntilDate),
DateTimeKind.Utc);;
}
break;
case "x-amz-object-lock-legal-hold":
string legalHoldON = paramValue.ToString().Trim();
if (!string.IsNullOrWhiteSpace(legalHoldON))
{
objInfo.LegalHoldEnabled = legalHoldON.ToLower().Equals("on");
}
break;
default:
if (OperationsUtil.IsSupportedHeader(paramName))
{
Expand Down Expand Up @@ -95,20 +135,63 @@ public static ObjectStat FromResponseHeaders(string objectName, Dictionary<strin
public string VersionId { get; private set; }
public bool DeleteMarker { get; private set; }
public Dictionary<string, string> ExtraHeaders { get; private set; }
public uint TaggingCount { get; private set; }
public uint? TaggingCount { get; private set; }
public string ArchiveStatus { get; private set; }
public DateTime? Expires { get; private set; }
public string ReplicationStatus { get; private set; }
public RetentionMode? ObjectLockMode { get; private set; }
public DateTime? ObjectLockRetainUntilDate { get; private set; }
public bool? LegalHoldEnabled { get; private set; }

public override string ToString()
{
if (!string.IsNullOrEmpty(this.VersionId))
string versionInfo = "VersionId(None)";
string legalHold = "LegalHold(None)";
string taggingCount = "Tagging-Count(0)";
string expires = "Expiry(None)";
string objectLockInfo = "ObjectLock(None)";
string archiveStatus = "Archive Status(None)";
string replicationStatus = "Replication Status(None)";
if (!string.IsNullOrWhiteSpace(this.VersionId))
{
string versionInfo = $"Version ID({this.VersionId})";
versionInfo = $"Version ID({this.VersionId})";
if (this.DeleteMarker)
{
versionInfo = $"Version ID({this.VersionId}, deleted)";
}
return $"{this.ObjectName} : {versionInfo} Size({this.Size}) LastModified({this.LastModified}) ETag({this.ETag}) Content-Type({this.ContentType})";
}
return $"{this.ObjectName} : Size({this.Size}) LastModified({this.LastModified}) ETag({this.ETag}) Content-Type({this.ContentType})";
if (this.Expires != null)
{
expires = "Expiry(" + utils.To8601String(this.Expires.Value)+ ")";
}
if (this.ObjectLockMode != null)
{
objectLockInfo = "ObjectLock Mode(" + ((this.ObjectLockMode == RetentionMode.GOVERNANCE)?"GOVERNANCE":"COMPLIANCE") + ")";
if (this.ObjectLockRetainUntilDate != null)
{
objectLockInfo += " Retain Until Date(" + utils.To8601String(this.ObjectLockRetainUntilDate.Value) + ")";
}
}
if (this.TaggingCount != null)
{
taggingCount = "Tagging-Count(" + this.TaggingCount.Value + ")";
}
if (this.LegalHoldEnabled != null)
{
legalHold = "LegalHold(" + ((this.LegalHoldEnabled.Value)?"Enabled":"Disabled") + ")";
}
if (!string.IsNullOrWhiteSpace(this.ReplicationStatus))
{
replicationStatus = "Replication Status(" + this.ReplicationStatus + ")";
}
if (!string.IsNullOrWhiteSpace(this.ArchiveStatus))
{
archiveStatus = "Archive Status(" + this.ArchiveStatus + ")";
}
string lineTwo = $"{expires} {objectLockInfo} {legalHold} {taggingCount} {archiveStatus} {replicationStatus}";

return $"{this.ObjectName} : {versionInfo} Size({this.Size}) LastModified({this.LastModified}) ETag({this.ETag}) Content-Type({this.ContentType})" +
(string.IsNullOrWhiteSpace(lineTwo)?"":("\n" + lineTwo));
}
}
}
36 changes: 36 additions & 0 deletions Minio/Helper/OperationsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,46 @@ namespace Minio
{
public partial class MinioClient : IObjectOperations
{

/// <summary>
/// private helper method to remove list of objects from bucket
/// </summary>
/// <param name="args">GetObjectArgs Arguments Object encapsulates information like - bucket name, object name etc </param>
/// <param name="cancellationToken">Optional cancellation token to cancel the operation</param>
private async Task<ObjectStat> getObjectHelper(GetObjectArgs args, CancellationToken cancellationToken = default(CancellationToken))
{
// StatObject is called to both verify the existence of the object and return it with GetObject.
// NOTE: This avoids writing the error body to the action stream passed (Do not remove).
StatObjectArgs statArgs = new StatObjectArgs()
.WithBucket(args.BucketName)
.WithObject(args.ObjectName)
.WithVersionId(args.VersionId)
.WithMatchETag(args.MatchETag)
.WithNotMatchETag(args.NotMatchETag)
.WithModifiedSince(args.ModifiedSince)
.WithUnModifiedSince(args.UnModifiedSince)
.WithServerSideEncryption(args.SSE);
if (args.OffsetLengthSet)
{
statArgs.WithOffsetAndLength(args.ObjectOffset, args.ObjectLength);
}
ObjectStat objStat = await this.StatObjectAsync(statArgs, cancellationToken: cancellationToken).ConfigureAwait(false);
args.Validate();
if (args.FileName != null)
{
await this.getObjectFileAsync(args, objStat, cancellationToken);
}
else
{
await this.getObjectStreamAsync(args, objStat, args.CallBack, cancellationToken);
}
return objStat;

}
/// <summary>
/// private helper method return the specified object from the bucket
/// </summary>
/// <param name="args">GetObjectArgs Arguments Object encapsulates information like - bucket name, object name etc </param>
/// <param name="objectStat"> ObjectStat object encapsulates information like - object name, size, etag etc </param>
/// <param name="cancellationToken">Optional cancellation token to cancel the operation</param>
private Task getObjectFileAsync(GetObjectArgs args, ObjectStat objectStat, CancellationToken cancellationToken = default(CancellationToken))
Expand Down

0 comments on commit 57f7e38

Please sign in to comment.