Skip to content

Commit

Permalink
Builder implemented for MinioClient, Arguments (#446)
Browse files Browse the repository at this point in the history
Also added Versioning API support
  • Loading branch information
BigUstad authored Aug 28, 2020
1 parent 0e1cd4a commit b780b0d
Show file tree
Hide file tree
Showing 31 changed files with 1,805 additions and 151 deletions.
340 changes: 336 additions & 4 deletions Docs/API.md

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Docs/zh_CN/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ var s3Client = new MinioClient("s3.amazonaws.com",
| [`removeBucket`](#removeBucket) | [`statObject`](#statObject) | | [`getBucketNotification`](#getBucketNotification) |
| [`listObjects`](#listObjects) | [`removeObject`](#removeObject) | | [`removeAllBucketNotification`](#removeAllBucketNotification) |
| [`listIncompleteUploads`](#listIncompleteUploads) | [`removeObjects`](#removeObjects) | | |
| | [`removeIncompleteUpload`](#removeIncompleteUpload) | | |
| [`listenBucketNotifications`](#listenBucketNotifications) | [`removeIncompleteUpload`](#removeIncompleteUpload) | | |
| [`setVersioning`](#setVersioning) | [`selectObjectContent`](#selectObjectContent) | | |
| [`getVersioning`](#getVersioning) | | | |



## 1. 构造函数
Expand Down
5 changes: 3 additions & 2 deletions Minio.Examples/Cases/BucketExists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public async static Task Run(MinioClient minio,
try
{
Console.WriteLine("Running example for API: BucketExistsAsync");
bool found = await minio.BucketExistsAsync(bucketName);
BucketExistsArgs args = new BucketExistsArgs(bucketName);
bool found = await minio.BucketExistsAsync(args);
Console.WriteLine((found ? "Found" : "Couldn't find ") + "bucket " + bucketName);
Console.WriteLine();
}
Expand All @@ -38,4 +39,4 @@ public async static Task Run(MinioClient minio,
}
}
}
}
}
48 changes: 48 additions & 0 deletions Minio.Examples/Cases/EnableSuspendVersioning.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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;
using Minio.DataModel;

namespace Minio.Examples.Cases
{
class EnableSuspendVersioning
{
// Enable Versioning on a bucket
public async static Task Run(MinioClient minio,
string bucketName = "my-bucket-name")
{
try
{
Console.WriteLine("Running example for API: EnableSuspendVersioning, ");
// First Enable the Versioning.
var setArgs = new SetVersioningArgs(bucketName)
.WithVersioningEnabled();
await minio.SetVersioningAsync(setArgs);
Console.WriteLine("Versioning Enable operation called for bucket " + bucketName);
// Next Suspend the Versioning.
setArgs = setArgs.WithVersioningSuspended();
await minio.SetVersioningAsync(setArgs);
Console.WriteLine("Versioning Suspend operation called for bucket " + bucketName);
}
catch (Exception e)
{
Console.WriteLine($"[Bucket] Exception: {e}");
}
}
}
}
51 changes: 51 additions & 0 deletions Minio.Examples/Cases/GetVersioning.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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;
using Minio.DataModel;

namespace Minio.Examples.Cases
{
class GetVersioning
{
// Check if Versioning is Enabled on a bucket
public async static Task Run(MinioClient minio,
string bucketName = "my-bucket-name")
{
var args = new GetVersioningArgs(bucketName);

try
{
Console.WriteLine("Running example for API: GetVersioning, ");
VersioningConfiguration config = await minio.GetVersioningAsync(args);
if ( config == null )
{
Console.WriteLine("Versioning Configuration not available for bucket " + bucketName);
Console.WriteLine();
return;
}
Console.WriteLine("Versioning Configuration Status " + config.Status + " for bucket " + bucketName);
Console.WriteLine();

}
catch (Exception e)
{
Console.WriteLine($"[Bucket] Exception: {e}");
}
}
}
}
9 changes: 6 additions & 3 deletions Minio.Examples/Cases/MakeBucket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ public class MakeBucket
{
// Make a bucket
public async static Task Run(MinioClient minio,
string bucketName = "my-bucket-name")
string bucketName = "my-bucket-name", string loc = "us-east-1")
{
try
{
Console.WriteLine("Running example for API: MakeBucketAsync");
await minio.MakeBucketAsync(bucketName);
await minio.MakeBucketAsync(
new MakeBucketArgs(bucketName)
.WithLocation(loc)
);
Console.WriteLine($"Created bucket {bucketName}");
Console.WriteLine();
}
Expand All @@ -38,4 +41,4 @@ public async static Task Run(MinioClient minio,
}
}
}
}
}
6 changes: 4 additions & 2 deletions Minio.Examples/Cases/RemoveBucket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public async static Task Run(MinioClient minio,
{
try
{
await minio.RemoveBucketAsync(bucketName);
await minio.RemoveBucketAsync(
new RemoveBucketArgs(bucketName)
);
Console.WriteLine($"Removed the bucket {bucketName} successfully");
}
catch (Exception e)
Expand All @@ -36,4 +38,4 @@ public async static Task Run(MinioClient minio,
}
}
}
}
}
10 changes: 5 additions & 5 deletions Minio.Examples/Minio.Examples.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>False</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Polly" Version="7.2.0" />
<PackageReference Include="Polly" Version="7.2.0"/>
<PackageReference Include="System.Net.Http" Version="4.3.0"/>
<PackageReference Include="System.Net.Primitives" Version="4.3.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Minio\Minio.csproj" />
<ProjectReference Include="..\Minio\Minio.csproj"/>
</ItemGroup>
</Project>
33 changes: 28 additions & 5 deletions Minio.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,26 @@ public static void Main(string[] args)
string accessKey = null;
string secretKey = null;
bool enableHTTPS = false;
int port = 80;

if (Environment.GetEnvironmentVariable("SERVER_ENDPOINT") != null)
{
endPoint = Environment.GetEnvironmentVariable("SERVER_ENDPOINT");
int posColon = endPoint.LastIndexOf(':');
if ( posColon != -1 )
{
port = Int32.Parse(endPoint.Substring(posColon+1, (endPoint.Length - posColon - 1)));
endPoint = endPoint.Substring(0, posColon);
}
accessKey = Environment.GetEnvironmentVariable("ACCESS_KEY");
secretKey = Environment.GetEnvironmentVariable("SECRET_KEY");
if (Environment.GetEnvironmentVariable("ENABLE_HTTPS") != null)
{
enableHTTPS = Environment.GetEnvironmentVariable("ENABLE_HTTPS").Equals("1");
if ( enableHTTPS && port == 80 )
{
port = 443;
}
}
}
else
Expand All @@ -77,22 +88,29 @@ public static void Main(string[] args)
accessKey = "Q3AM3UQ867SPQQA43P2F";
secretKey = "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG";
enableHTTPS = true;
port = 443;
}

ServicePointManager.ServerCertificateValidationCallback +=
(sender, certificate, chain, sslPolicyErrors) => true;

// WithSSL() enables SSL support in MinIO client
MinioClient minioClient = null;
if (enableHTTPS)
if ( enableHTTPS )
{
minioClient = new MinioClient(endPoint, accessKey, secretKey).WithSSL();
minioClient = new MinioClient()
.WithEndpoint(endPoint, port)
.WithCredentials(accessKey, secretKey)
.WithSSL()
.Build();
}
else
{
minioClient = new MinioClient(endPoint, accessKey, secretKey);
minioClient = new MinioClient()
.WithEndpoint(endPoint, port)
.WithCredentials(accessKey, secretKey)
.Build();
}

try
{
// Assign parameters before starting the test
Expand Down Expand Up @@ -123,6 +141,10 @@ public static void Main(string[] args)

Cases.MakeBucket.Run(minioClient, destBucketName).Wait();

//Versioning tests
Cases.GetVersioning.Run(minioClient, bucketName).Wait();
Cases.EnableSuspendVersioning.Run(minioClient, bucketName).Wait();
Cases.GetVersioning.Run(minioClient, bucketName).Wait();
// List all the buckets on the server
Cases.ListBuckets.Run(minioClient).Wait();

Expand Down Expand Up @@ -227,6 +249,7 @@ public static void Main(string[] args)
Cases.CustomRequestLogger.Run(minioClient).Wait();

// Remove the buckets
Console.WriteLine();
Cases.RemoveBucket.Run(minioClient, bucketName).Wait();
Cases.RemoveBucket.Run(minioClient, destBucketName).Wait();

Expand All @@ -242,4 +265,4 @@ public static void Main(string[] args)
}
}
}
}
}
Loading

0 comments on commit b780b0d

Please sign in to comment.