Skip to content

Commit

Permalink
Updating API docs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
novama committed Sep 4, 2024
1 parent 5a8968c commit ace6777
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 35 deletions.
42 changes: 42 additions & 0 deletions Docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2762,6 +2762,48 @@ catch(MinioException e)
}
```

<a name="getPresignedUrl"></a>
### GetPresignedUrlAsync(GetPresignedUrlArgs args)

`Task<string> GetPresignedUrlAsync(GetPresignedUrlArgs args)`

Generates a presigned URL for HTTP operation using the giving HTTP method (GET, PUT, DELETE). Browsers/Mobile clients may point to this URL to upload objects directly to a bucket even if it 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.

__Parameters__


| Param | Type | Description |
|:---------|:------------------------|:-------------------------------------------------------------------------------------|
| ``args`` | _GetPresignedUrlArgs_ | GetPresignedUrlArgs arguments object with HTTP method, bucket, object names & expiry |

| Return Type | Exceptions |
|:------------------------------------------------------------|:-------------------------------------------------------------------|
| ``Task<string>`` : string contains URL to upload the object | Listed Exceptions: |
| | ``InvalidBucketNameException`` : upon invalid bucket name |
| | ``InvalidKeyException`` : upon an invalid access key or secret key |
| | ``ConnectionException`` : upon connection error |
| | ``InvalidExpiryRangeException`` : upon invalid expiry range. |


__Example__

```cs
try
{
var httpMethod = GetPresignedUrlArgs.PresignedUrlHttpMethod.Put;
GetPresignedUrlArgs args = GetPresignedUrlArgs(httpMethod)
.WithBucket("mybucket")
.WithObject("myobject")
.WithExpiry(60 * 60 * 24);
String url = await minioClient.GetPresignedUrlAsync(args);
Console.WriteLine(url);
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
```

<a name="presignedPostPolicy"></a>
### PresignedPostPolicy(PresignedPostPolicyArgs args)

Expand Down
32 changes: 20 additions & 12 deletions Minio.Functional.Tests/FunctionalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5737,13 +5737,13 @@ internal static async Task GetPresignedUrl_Get_Test1(IMinioClient minio)
// Compare the size of the file downloaded using the generated
// presigned_url (expected value) and the actual object size on the server
Assert.AreEqual(file_read_size, stats.Size);
new MintLogger("GetPresignedUrl_Get_Test1", presignedGetObjectSignature,
new MintLogger("GetPresignedUrl_Get_Test1", getPresignedUrlSignature,
"Tests whether GetPresignedUrl url retrieves object from bucket", TestStatus.PASS,
DateTime.Now - startTime, args: args).Log();
}
catch (Exception ex)
{
new MintLogger("GetPresignedUrl_Get_Test1", presignedGetObjectSignature,
new MintLogger("GetPresignedUrl_Get_Test1", getPresignedUrlSignature,
"Tests whether GetPresignedUrl url retrieves object from bucket", TestStatus.FAIL,
DateTime.Now - startTime, ex.Message, ex.ToString(), args: args).Log();
throw;
Expand Down Expand Up @@ -5797,20 +5797,20 @@ internal static async Task GetPresignedUrl_Get_Test2(IMinioClient minio)
}
catch (InvalidExpiryRangeException)
{
new MintLogger("GetPresignedUrl_Get_Test2", presignedGetObjectSignature,
new MintLogger("GetPresignedUrl_Get_Test2", getPresignedUrlSignature,
"Tests whether GetPresignedUrl url retrieves object from bucket when invalid expiry is set.",
TestStatus.PASS, DateTime.Now - startTime, args: args).Log();
}
catch (InvalidOperationException ex)
{
new MintLogger("GetPresignedUrl_Get_Test2", presignedGetObjectSignature,
new MintLogger("GetPresignedUrl_Get_Test2", getPresignedUrlSignature,
"Tests whether GetPresignedUrl url retrieves object from bucket when invalid expiry is set.",
TestStatus.FAIL, DateTime.Now - startTime, ex.Message, ex.ToString(), args: args).Log();
throw;
}
catch (Exception ex)
{
new MintLogger("GetPresignedUrl_Get_Test2", presignedGetObjectSignature,
new MintLogger("GetPresignedUrl_Get_Test2", getPresignedUrlSignature,
"Tests whether GetPresignedUrl url retrieves object from bucket when invalid expiry is set.",
TestStatus.FAIL, DateTime.Now - startTime, ex.Message, ex.ToString(), args: args).Log();
throw;
Expand Down Expand Up @@ -5897,13 +5897,13 @@ internal static async Task GetPresignedUrl_Get_Test3(IMinioClient minio)
// Compare the size of the file downloaded with the generated
// presigned_url (expected) and the actual object size on the server
Assert.AreEqual(file_read_size, stats.Size);
new MintLogger("GetPresignedUrl_Get_Test3", presignedGetObjectSignature,
new MintLogger("GetPresignedUrl_Get_Test3", getPresignedUrlSignature,
"Tests whether GetPresignedUrl url retrieves object from bucket when override response headers sent",
TestStatus.PASS, DateTime.Now - startTime, args: args).Log();
}
catch (Exception ex)
{
new MintLogger("GetPresignedUrl_Get_Test3", presignedGetObjectSignature,
new MintLogger("GetPresignedUrl_Get_Test3", getPresignedUrlSignature,
"Tests whether GetPresignedUrl url retrieves object from bucket when override response headers sent",
TestStatus.FAIL, DateTime.Now - startTime, ex.Message, ex.ToString(), args: args).Log();
throw;
Expand Down Expand Up @@ -5950,7 +5950,7 @@ internal static async Task GetPresignedUrl_Put_Delete_Test1(IMinioClient minio)
var writtenInfo = new FileInfo(fileName);
var file_written_size = writtenInfo.Length;
Assert.AreEqual(file_written_size, stats.Size);
new MintLogger("GetPresignedUrl_Put_Delete_Test1", presignedPutObjectSignature,
new MintLogger("GetPresignedUrl_Put_Delete_Test1", getPresignedUrlSignature,
"Tests whether GetPresignedUrl url uploads object to bucket", TestStatus.PASS,
DateTime.Now - startTime, args: args).Log();

Expand All @@ -5962,10 +5962,14 @@ internal static async Task GetPresignedUrl_Put_Delete_Test1(IMinioClient minio)
.WithExpiry(1000);
presigned_url = await minio.GetPresignedUrlAsync(presignedPutObjectArgs).ConfigureAwait(false);
await DeleteObjectAsync(minio, presigned_url).ConfigureAwait(false);

new MintLogger("GetPresignedUrl_Put_Delete_Test1", getPresignedUrlSignature,
"Tests whether GetPresignedUrl url deletes object from bucket", TestStatus.PASS,
DateTime.Now - startTime, args: args).Log();
}
catch (Exception ex)
{
new MintLogger("GetPresignedUrl_Put_Delete_Test1", presignedPutObjectSignature,
new MintLogger("GetPresignedUrl_Put_Delete_Test1", getPresignedUrlSignature,
"Tests whether GetPresignedUrl url uploads object to bucket", TestStatus.FAIL,
DateTime.Now - startTime, ex.Message, ex.ToString(), args: args).Log();
throw;
Expand Down Expand Up @@ -6015,7 +6019,7 @@ internal static async Task GetPresignedUrl_Put_Delete_Test2(IMinioClient minio)
.WithObject(objectName)
.WithExpiry(0);
var presigned_url = await minio.GetPresignedUrlAsync(presignedPutObjectArgs).ConfigureAwait(false);
new MintLogger("GetPresignedUrl_Put_Delete_Test2", presignedPutObjectSignature,
new MintLogger("GetPresignedUrl_Put_Delete_Test2", getPresignedUrlSignature,
"Tests whether GetPresignedUrl url retrieves object from bucket when invalid expiry is set.",
TestStatus.PASS, DateTime.Now - startTime, args: args).Log();

Expand All @@ -6027,16 +6031,20 @@ internal static async Task GetPresignedUrl_Put_Delete_Test2(IMinioClient minio)
.WithExpiry(1000);
presigned_url = await minio.GetPresignedUrlAsync(presignedPutObjectArgs).ConfigureAwait(false);
await DeleteObjectAsync(minio, presigned_url).ConfigureAwait(false);

new MintLogger("GetPresignedUrl_Put_Delete_Test1", getPresignedUrlSignature,
"Tests whether GetPresignedUrl url deletes object from bucket", TestStatus.PASS,
DateTime.Now - startTime, args: args).Log();
}
catch (InvalidExpiryRangeException)
{
new MintLogger("GetPresignedUrl_Put_Delete_Test2", presignedPutObjectSignature,
new MintLogger("GetPresignedUrl_Put_Delete_Test2", getPresignedUrlSignature,
"Tests whether GetPresignedUrl url retrieves object from bucket when invalid expiry is set.",
TestStatus.PASS, DateTime.Now - startTime, args: args).Log();
}
catch (Exception ex)
{
new MintLogger("GetPresignedUrl_Put_Delete_Test2", presignedPutObjectSignature,
new MintLogger("GetPresignedUrl_Put_Delete_Test2", getPresignedUrlSignature,
"Tests whether GetPresignedUrl url retrieves object from bucket when invalid expiry is set.",
TestStatus.FAIL, DateTime.Now - startTime, ex.Message, ex.ToString(), args: args).Log();
throw;
Expand Down
26 changes: 3 additions & 23 deletions Minio.Functional.Tests/FunctionalTests-setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,9 @@
* limitations under the License.
*/

using System.Collections.Concurrent;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Web;
using System.Xml;
using System.Xml.Serialization;
using CommunityToolkit.HighPerformance;
using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.Zip;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Minio.DataModel;
using Minio.DataModel.Args;
using Minio.DataModel.Encryption;
using Minio.DataModel.ILM;
using Minio.DataModel.Notification;
using Minio.DataModel.ObjectLock;
using Minio.DataModel.Select;
using Minio.DataModel.Tags;
using Minio.Exceptions;
using Minio.Helper;

namespace Minio.Functional.Tests;

Expand Down Expand Up @@ -108,6 +85,9 @@ public static partial class FunctionalTest
private const string presignedGetObjectSignature =
"Task<string> PresignedGetObjectAsync(PresignedGetObjectArgs args)";

private const string getPresignedUrlSignature =
"Task<string> GetPresignedUrlAsync(GetPresignedUrlArgs args)";

private const string presignedPostPolicySignature =
"Task<Dictionary<string, string>> PresignedPostPolicyAsync(PresignedPostPolicyArgs args)";

Expand Down

0 comments on commit ace6777

Please sign in to comment.