Skip to content

Commit

Permalink
Replacing function calls with Args, MinioClient constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
BigUstad committed Dec 24, 2020
2 parents ebb00be + 96df781 commit 7df482a
Show file tree
Hide file tree
Showing 23 changed files with 847 additions and 99 deletions.
157 changes: 154 additions & 3 deletions Docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ var s3Client = new MinioClient("s3.amazonaws.com",
| [`setBucketEncryption`](#setBucketEncryption) | [`setObjectTags`](#setObjectTags) | | |
| [`getBucketEncryption`](#getBucketEncryption) | [`getObjectTags`](#getObjectTags) | | |
| [`removeBucketEncryption`](#removeBucketEncryption) | [`removeObjectTags`](#removeObjectTags) | | |
| [`setBucketTags`](#setBucketTags) | | | |
| [`getBucketTags`](#getBucketTags) | | | |
| [`removeBucketTags`](#removeBucketTags) | | | |
| [`setBucketTags`](#setBucketTags) | [`setObjectRetention`](#setObjectRetention) | | |
| [`getBucketTags`](#getBucketTags) | [`getObjectRetention`](#getObjectRetention) | | |
| [`removeBucketTags`](#removeBucketTags) | [`clearObjectRetention`](#clearObjectRetention) | | |
| [`setObjectLock`](#setObjectLock) | | | |
| [`getObjectLock`](#getObjectLock) | | | |
| [`removeObjectLock`](#removeObjectLock) | | | |
Expand Down Expand Up @@ -2307,6 +2307,157 @@ catch(MinioException e)
```


<a name="setObjectRetention"></a>
### SetObjectRetentionAsync(SetObjectRetentionArgs args)

`Task SetObjectRetentionAsync(SetObjectRetentionArgs args, CancellationToken cancellationToken = default(CancellationToken))`

Sets retention configuration to an object.


__Parameters__


|Param | Type | Description |
|:--- |:--- |:--- |
| ``args`` | _SetObjectRetentionArgs_ | SetObjectRetentionArgs Argument Object with bucket, object names, version id(optional) |
| ``cancellationToken``| _System.Threading.CancellationToken_ | Optional parameter. Defaults to default(CancellationToken) |


| Return Type | Exceptions |
|:--- |:--- |
| ``Task`` | Listed Exceptions: |
| | ``AuthorizationException`` : upon access or secret key wrong or not found |
| | ``InvalidBucketNameException`` : upon invalid bucket name |
| | ``InvalidObjectNameException`` : upon invalid object name |
| | ``BucketNotFoundException`` : upon bucket with name not found |
| | ``ObjectNotFoundException`` : upon object with name not found |
| | ``MissingObjectLockConfiguration`` : upon bucket created with object lock not enabled |
| | ``MalFormedXMLException`` : upon configuration XML in http request validation failure |



__Example__


```cs
try
{
// Setting Retention Configuration of the object.
SetObjectRetentionArgs args = new SetObjectRetentionArgs()
.WithBucket(bucketName)
.WithObject(objectName)
.WithRetentionValidDays(numOfDays);
await minio.SetObjectRetentionAsync(args);
Console.WriteLine($"Assigned retention configuration to object {bucketName}/{objectName}");
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
```


<a name="getObjectRetention"></a>
### GetObjectRetentionAsync(GetObjectRetentionArgs args)

`Task<ObjectRetentionConfiguration> GetObjectRetentionAsync(GetObjectRetentionArgs args, CancellationToken cancellationToken = default(CancellationToken))`

Gets retention configuration of an object.



__Parameters__


|Param | Type | Description |
|:--- |:--- |:--- |
| ``args`` | _GetObjectRetentionArgs_ | GetObjectRetentionArgs Argument Object with bucket, object names, version id(optional) |
| ``cancellationToken``| _System.Threading.CancellationToken_ | Optional parameter. Defaults to default(CancellationToken) |


| Return Type | Exceptions |
|:--- |:--- |
| ``Task<ObjectRetentionConfiguration>``: ObjectRetentionConfiguration object with configuration data. | Listed Exceptions: |
| | ``AuthorizationException`` : upon access or secret key wrong or not found |
| | ``InvalidBucketNameException`` : upon invalid bucket name |
| | ``InvalidObjectNameException`` : upon invalid object name |
| | ``BucketNotFoundException`` : upon bucket with name not found |
| | ``ObjectNotFoundException`` : upon object with name not found |
| | ``MissingObjectLockConfiguration`` : upon bucket created with object lock not enabled |
| | ``MalFormedXMLException`` : upon configuration XML in http request validation failure |


__Example__


```cs
try
{
// Get Retention configuration of an object
var args = new GetObjectRetentionArgs()
.WithBucket(bucketName)
.WithObject(objectName);
ObjectRetentionConfiguration config = await minio.GetObjectRetentionAsync(args);
Console.WriteLine($"Got retention configuration for object {bucketName}/{objectName}");
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
```


<a name="clearObjectRetention"></a>
### ClearObjectRetentionAsync(ClearObjectRetentionArgs args)

`Task ClearObjectRetentionAsync(ClearObjectRetentionArgs args, CancellationToken cancellationToken = default(CancellationToken))`

Clears retention configuration to an object.


__Parameters__


|Param | Type | Description |
|:--- |:--- |:--- |
| ``args`` | _ClearObjectRetentionArgs_ | ClearObjectRetentionArgs Argument Object with bucket, object names, version id(optional) |
| ``cancellationToken``| _System.Threading.CancellationToken_ | Optional parameter. Defaults to default(CancellationToken) |


| Return Type | Exceptions |
|:--- |:--- |
| ``Task`` | Listed Exceptions: |
| | ``AuthorizationException`` : upon access or secret key wrong or not found |
| | ``InvalidBucketNameException`` : upon invalid bucket name |
| | ``InvalidObjectNameException`` : upon invalid object name |
| | ``BucketNotFoundException`` : upon bucket with name not found |
| | ``ObjectNotFoundException`` : upon object with name not found |
| | ``MissingObjectLockConfiguration`` : upon bucket created with object lock not enabled |
| | ``MalFormedXMLException`` : upon configuration XML in http request validation failure |



__Example__


```cs
try
{
// Clearing the Retention Configuration of the object.
ClearObjectRetentionArgs args = new ClearObjectRetentionArgs()
.WithBucket(bucketName)
.WithObject(objectName);
await minio.ClearObjectRetentionAsync(args);
Console.WriteLine($"Clears retention configuration to object {bucketName}/{objectName}");
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
```



## 4. Presigned operations
<a name="presignedGetObject"></a>
Expand Down
14 changes: 11 additions & 3 deletions FileUploader/FileUpload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ static void Main(string[] args)
var secretKey = "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG";
try
{
var minio = new MinioClient(endpoint, accessKey, secretKey).WithSSL();
var minio = new MinioClient()
.WithEndpoint(endpoint)
.WithCredentials(accessKey, secretKey)
.WithSSL();
Run(minio).Wait();
}
catch (Exception ex)
Expand All @@ -64,10 +67,15 @@ private static async Task Run(MinioClient minio)

try
{
bool found = await minio.BucketExistsAsync(bucketName);
var bktExistArgs = new BucketExistsArgs()
.WithBucket(bucketName);
bool found = await minio.BucketExistsAsync(bktExistArgs);
if (!found)
{
await minio.MakeBucketAsync(bucketName, location);
var mkBktArgs = new MakeBucketArgs()
.WithBucket(bucketName)
.WithLocation(location);
await minio.MakeBucketAsync(mkBktArgs);
}
await minio.PutObjectAsync(bucketName, objectName, filePath, contentType);
Console.WriteLine("Successfully uploaded " + objectName);
Expand Down
49 changes: 49 additions & 0 deletions Minio.Examples/Cases/ClearObjectRetention.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Threading.Tasks;

namespace Minio.Examples.Cases
{
public class ClearObjectRetention
{
// Put Empty Retention Configuration for the bucket
public async static Task Run(MinioClient minio,
string bucketName = "my-bucket-name",
string objectName = "my-object-name",
string versionId = null)
{
try
{
Console.WriteLine("Running example for API: ClearObjectRetention");
await minio.ClearObjectRetentionAsync(
new ClearObjectRetentionArgs()
.WithBucket(bucketName)
.WithObject(objectName)
.WithVersionId(versionId)
);
string versionInfo = (string.IsNullOrEmpty(versionId))?"":(" Version ID: " + versionId);
Console.WriteLine($"Cleared retention configuration to object {bucketName}/{objectName} " +
versionInfo);
Console.WriteLine();
}
catch (Exception e)
{
Console.WriteLine($"[Object] Exception: {e}");
}
}
}
}
52 changes: 52 additions & 0 deletions Minio.Examples/Cases/GetObjectRetention.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Threading.Tasks;

namespace Minio.Examples.Cases
{
public class GetObjectRetention
{
// Get Object Retention Configuration for the bucket
public async static Task Run(MinioClient minio,
string bucketName = "my-bucket-name",
string objectName = "my-object-name",
string versionId = null)
{
try
{
Console.WriteLine("Running example for API: GetObjectRetentionAsync");
ObjectRetentionConfiguration config = await minio.GetObjectRetentionAsync(
new GetObjectRetentionArgs()
.WithBucket(bucketName)
.WithObject(objectName)
.WithVersionId(versionId)
);
string versionInfo = (string.IsNullOrEmpty(versionId))?"":(" Version ID: " + versionId);
string retentionModeStr = (config.Mode == RetentionMode.GOVERNANCE)?"GOVERNANCE":"COMPLIANCE";
Console.WriteLine($"Retention configuration to object {bucketName}/{objectName} " +
versionInfo +
" Retention Mode: " + retentionModeStr +
" Retention Date: " + config.RetainUntilDate);
Console.WriteLine();
}
catch (Exception e)
{
Console.WriteLine($"[Object] Exception: {e}");
}
}
}
}
5 changes: 4 additions & 1 deletion Minio.Examples/Cases/GetPartialObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public async static Task Run(MinioClient minio,
Console.WriteLine("Running example for API: GetObjectAsync");
// Check whether the object exists using StatObjectAsync(). If the object is not found,
// StatObjectAsync() will throw an exception.
await minio.StatObjectAsync(bucketName, objectName);
var statObjectArgs = new StatObjectArgs()
.WithBucket(bucketName)
.WithObject(objectName);
await minio.StatObjectAsync(statObjectArgs);

// Get object content starting at byte position 1024 and length of 4096
await minio.GetObjectAsync(bucketName, objectName, 1024L, 4096L,
Expand Down
7 changes: 6 additions & 1 deletion Minio.Examples/Cases/PresignedGetObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ public async static Task Run(MinioClient client,
try
{
var reqParams = new Dictionary<string, string> { {"response-content-type", "application/json" } };
string presignedUrl = await client.PresignedGetObjectAsync(bucketName, objectName, 1000, reqParams);
PresignedGetObjectArgs args = new PresignedGetObjectArgs()
.WithBucket(bucketName)
.WithObject(objectName)
.WithExpiry(1000)
.WithHeaders(reqParams);
string presignedUrl = await client.PresignedGetObjectAsync(args);
Console.WriteLine(presignedUrl);
}
catch (Exception e)
Expand Down
6 changes: 5 additions & 1 deletion Minio.Examples/Cases/PresignedPutObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public async static Task Run(MinioClient client,
{
try
{
string presignedUrl = await client.PresignedPutObjectAsync(bucketName, objectName, 1000);
PresignedPutObjectArgs args = new PresignedPutObjectArgs()
.WithBucket(bucketName)
.WithObject(objectName)
.WithExpiry(1000);
string presignedUrl = await client.PresignedPutObjectAsync(args);
Console.WriteLine(presignedUrl);
}
catch (Exception e)
Expand Down
2 changes: 1 addition & 1 deletion Minio.Examples/Cases/RemoveObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Minio.Examples.Cases
class RemoveObjects
{
// Remove a list of objects from a bucket
public async static Task Run(MinioClient minio,
public static void Run(MinioClient minio,
string bucketName = "my-bucket-name",
List<string> objectsList = null)
{
Expand Down
Loading

0 comments on commit 7df482a

Please sign in to comment.