Skip to content

Commit

Permalink
Add request date to PresignedGetObjectAsync as an optional parameter (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
poornas authored and kannappanr committed Mar 8, 2019
1 parent 4e62ea4 commit c7857cc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
5 changes: 3 additions & 2 deletions Docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1130,8 +1130,8 @@ catch(MinioException e)
## 4. Presigned operations
<a name="presignedGetObject"></a>

### PresignedGetObjectAsync(string bucketName, string objectName, int expiresInt, Dictionary<string,string> reqParams = null);
`Task<string> PresignedGetObjectAsync(string bucketName, string objectName, int expiresInt, Dictionary<string,string> reqParams = null)`
### PresignedGetObjectAsync(string bucketName, string objectName, int expiresInt, Dictionary<string,string> reqParams = null, DateTime? reqDate = null);
`Task<string> PresignedGetObjectAsync(string bucketName, string objectName, int expiresInt, Dictionary<string,string> reqParams = null, DateTime? reqDate = null)`

Generates a presigned URL for HTTP GET operations. Browsers/Mobile clients may point to this URL to directly download objects even if the bucket is private. This presigned URL can have an associated expiration time in seconds after which it is no longer operational. The default expiry is set to 7 days.

Expand All @@ -1144,6 +1144,7 @@ __Parameters__
| ``objectName`` | _String_ | Object name in the bucket |
| ``expiresInt`` | _Integer_ | Expiry in seconds. Default expiry is set to 7 days. |
| ``reqParams`` | _Dictionary<string,string>_ | Additional response header overrides supports response-expires, response-content-type, response-cache-control, response-content-disposition.|
| ``reqDate`` | _DateTime?_ | Optional request date and time. Defaults to DateTime.UtcNow if unset.|

| Return Type | Exceptions |
|:--- |:--- |
Expand Down
6 changes: 4 additions & 2 deletions Minio.Functional.Tests/FunctionalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2243,12 +2243,14 @@ private async static Task PresignedGetObject_Test3(MinioClient minio)
string bucketName = GetRandomName(15);
string objectName = GetRandomName(10);
int expiresInt = 1000;
DateTime reqDate = DateTime.UtcNow.AddSeconds(-50);
Dictionary<string,string> args = new Dictionary<string,string>
{
{"bucketName", bucketName},
{"objectName", objectName},
{"expiresInt", expiresInt.ToString()},
{"reqParams", "response-content-type:application/json,response-content-disposition:attachment;filename=MyDocument.json;"}
{"reqParams", "response-content-type:application/json,response-content-disposition:attachment;filename=MyDocument.json;"},
{"reqDate", reqDate.ToString()},
};
try
{
Expand All @@ -2262,7 +2264,7 @@ await minio.PutObjectAsync(bucketName,
Dictionary<string, string> reqParams = new Dictionary<string,string>();
reqParams["response-content-type"] = "application/json";
reqParams["response-content-disposition"] = "attachment;filename=MyDocument.json;";
string presigned_url = await minio.PresignedGetObjectAsync(bucketName, objectName, 1000, reqParams);
string presigned_url = await minio.PresignedGetObjectAsync(bucketName, objectName, 1000, reqParams, reqDate);
WebRequest httpRequest = WebRequest.Create(presigned_url);
var response = (HttpWebResponse)(await Task<WebResponse>.Factory.FromAsync(httpRequest.BeginGetResponse, httpRequest.EndGetResponse, null));
Assert.AreEqual(response.ContentType,reqParams["response-content-type"]);
Expand Down
3 changes: 2 additions & 1 deletion Minio/ApiEndpoints/IObjectOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ public interface IObjectOperations
/// <param name="objectName">Key of object to retrieve</param>
/// <param name="expiresInt">Expiration time in seconds.</param>
/// <param name="reqParams">optional override response headers</param>
Task<string> PresignedGetObjectAsync(string bucketName, string objectName, int expiresInt, Dictionary<string,string> reqParams = null);
/// <param name="reqDate">optional request date and time in UTC</param>
Task<string> PresignedGetObjectAsync(string bucketName, string objectName, int expiresInt, Dictionary<string,string> reqParams = null, DateTime? reqDate = null);

/// <summary>
/// Presigned Put url - returns a presigned url to upload an object without credentials.URL can have a maximum expiry of
Expand Down
5 changes: 3 additions & 2 deletions Minio/ApiEndpoints/ObjectOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,8 +1089,9 @@ private async Task MultipartCopyUploadAsync(string bucketName, string objectName
/// <param name="objectName">Key of object to retrieve</param>
/// <param name="expiresInt">Expiration time in seconds</param>
/// <param name="reqParams">optional override response headers</param>
/// <param name="reqDate">optional request date and time in UTC</param>
/// <returns></returns>
public async Task<string> PresignedGetObjectAsync(string bucketName, string objectName, int expiresInt, Dictionary<string,string> reqParams = null)
public async Task<string> PresignedGetObjectAsync(string bucketName, string objectName, int expiresInt, Dictionary<string,string> reqParams = null, DateTime? reqDate = null)
{
if (!utils.IsValidExpiry(expiresInt))
{
Expand All @@ -1101,7 +1102,7 @@ public async Task<string> PresignedGetObjectAsync(string bucketName, string obje
headerMap: reqParams)
.ConfigureAwait(false);

return this.authenticator.PresignURL(this.restClient, request, expiresInt, Region, this.SessionToken);
return this.authenticator.PresignURL(this.restClient, request, expiresInt, Region, this.SessionToken, reqDate);
}

/// <summary>
Expand Down
8 changes: 6 additions & 2 deletions Minio/V4Authenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,15 @@ public string PresignPostSignature(string region, DateTime signingDate, string p
/// <param name="expires">Expiration in seconds</param>
/// <param name="region">Region of storage</param>
/// <param name="sessionToken">Region of storage</param>

/// <param name="reqDate"> Optional request date and time in UTC</param>
/// <returns>Presigned url</returns>
internal string PresignURL(IRestClient client, IRestRequest request, int expires, string region = "",string sessionToken="")
internal string PresignURL(IRestClient client, IRestRequest request, int expires, string region = "",string sessionToken="", DateTime? reqDate = null)
{
DateTime signingDate = DateTime.UtcNow;

if (reqDate.HasValue){
signingDate = reqDate.Value;
}
string requestQuery = "";
string path = request.Resource;

Expand Down

0 comments on commit c7857cc

Please sign in to comment.