Skip to content

Commit ef4b919

Browse files
committed
Refactor IMinioAdmin into base project
Signed-off-by: Victor Chang <vicchang@nvidia.com>
1 parent a0dd398 commit ef4b919

23 files changed

+24807
-222
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ jobs:
204204
run: |
205205
mkdir $PACKAGEDIR
206206
dotnet pack --no-build -c ${{ env.BUILD_CONFIG }} -o $PACKAGEDIR -p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }}
207-
rm $PACKAGEDIR/Monai.Deploy.Storage.S3Policy.*.nupkg
208207
ls -lR $PACKAGEDIR
209208
working-directory: ./src
210209

src/Plugins/AWSS3/EF.Reverse.POCO.v3.ttinclude

Lines changed: 24553 additions & 0 deletions
Large diffs are not rendered by default.

src/Plugins/AWSS3/Monai.Deploy.Storage.AWSS3.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,8 @@
4040
<ProjectReference Include="..\..\Storage\Monai.Deploy.Storage.csproj" />
4141
</ItemGroup>
4242

43+
<ItemGroup>
44+
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
45+
</ItemGroup>
46+
4347
</Project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-FileCopyrightText: © 2022 MONAI Consortium
2+
// SPDX-License-Identifier: Apache License 2.0
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using Amazon.SecurityToken.Model;
7+
using Monai.Deploy.Storage.API;
8+
9+
namespace Monai.Deploy.Storage.AWSS3
10+
{
11+
public class StorageAdminService : IStorageAdminService
12+
{
13+
public Task<Credentials> CreateUserAsync(string username, AccessPermissions permissions, string[] bucketNames) => throw new NotImplementedException();
14+
}
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-FileCopyrightText: © 2022 MONAI Consortium
2+
// SPDX-License-Identifier: Apache License 2.0
3+
4+
using Monai.Deploy.Storage.API;
5+
6+
namespace Monai.Deploy.Storage.Minio.Extensions
7+
{
8+
public static class AccessPermissionsExtensions
9+
{
10+
public static string GetString(this AccessPermissions policy) => policy switch
11+
{
12+
(AccessPermissions.Read & AccessPermissions.Write) => "readwrite",
13+
AccessPermissions.ConsoleAdmin => "consoleAdmin",
14+
AccessPermissions.Diagnostics => "diagnostics",
15+
AccessPermissions.Read => "readonly",
16+
AccessPermissions.Write => "writeonly",
17+
_ => "",
18+
};
19+
}
20+
}

src/Plugins/MinIO/Extensions/MinioPolicyExtensions.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Plugins/MinIO/LoggerMethods.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ public static partial class LoggerMethods
1212

1313
[LoggerMessage(EventId = 20001, Level = LogLevel.Error, Message = "File '{path}' could not be found in '{bucketName}'.")]
1414
public static partial void FileNotFoundError(this ILogger logger, string bucketName, string path);
15+
16+
[LoggerMessage(EventId = 20002, Level = LogLevel.Error, Message = "Error verifying objects in bucket '{bucketName}'.")]
17+
public static partial void VerifyObjectError(this ILogger logger, string bucketName, Exception ex);
1518
}
1619
}

src/Plugins/MinIO/MinIoAdmin/Interfaces/IMinioAdmin.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/Plugins/MinIO/MinIoAdmin/Models/MinioPolicy.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Plugins/MinIO/MinIoStorageService.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Microsoft.Extensions.Logging;
88
using Microsoft.Extensions.Options;
99
using Minio;
10-
using Minio.DataModel;
1110
using Monai.Deploy.Storage.API;
1211
using Monai.Deploy.Storage.Configuration;
1312
using Monai.Deploy.Storage.S3Policy;
@@ -78,7 +77,7 @@ public async Task<IList<VirtualFileInfo>> ListObjectsAsync(string bucketName, st
7877
Guard.Against.NullOrWhiteSpace(bucketName, nameof(bucketName));
7978

8079
var client = _minioClientFactory.GetClient();
81-
return await ListObjectsUsingClient(client, bucketName, prefix, recursive, cancellationToken);
80+
return await ListObjectsUsingClient(client, bucketName, prefix, recursive, cancellationToken).ConfigureAwait(false);
8281
}
8382

8483
public async Task<Dictionary<string, string>> VerifyObjectsExistAsync(string bucketName, Dictionary<string, string> objectDict)
@@ -92,8 +91,8 @@ public async Task<Dictionary<string, string>> VerifyObjectsExistAsync(string buc
9291
{
9392
try
9493
{
95-
var fileObjects = await ListObjectsAsync(bucketName, obj.Value);
96-
var folderObjects = await ListObjectsAsync(bucketName, obj.Value.EndsWith("/") ? obj.Value : $"{obj.Value}/", true);
94+
var fileObjects = await ListObjectsAsync(bucketName, obj.Value).ConfigureAwait(false);
95+
var folderObjects = await ListObjectsAsync(bucketName, obj.Value.EndsWith("/") ? obj.Value : $"{obj.Value}/", true).ConfigureAwait(false);
9796

9897
if (!folderObjects.Any() && !fileObjects.Any())
9998
{
@@ -104,7 +103,7 @@ public async Task<Dictionary<string, string>> VerifyObjectsExistAsync(string buc
104103
}
105104
catch (Exception e)
106105
{
107-
_logger.LogError(e.Message);
106+
_logger.VerifyObjectError(bucketName, e);
108107

109108
continue;
110109
}
@@ -120,8 +119,8 @@ public async Task<KeyValuePair<string, string>> VerifyObjectExistsAsync(string b
120119
Guard.Against.NullOrWhiteSpace(bucketName, nameof(bucketName));
121120
Guard.Against.Null(objectPair, nameof(objectPair));
122121

123-
var fileObjects = await ListObjectsAsync(bucketName, objectPair.Value);
124-
var folderObjects = await ListObjectsAsync(bucketName, objectPair.Value.EndsWith("/") ? objectPair.Value : $"{objectPair.Value}/", true);
122+
var fileObjects = await ListObjectsAsync(bucketName, objectPair.Value).ConfigureAwait(false);
123+
var folderObjects = await ListObjectsAsync(bucketName, objectPair.Value.EndsWith("/") ? objectPair.Value : $"{objectPair.Value}/", true).ConfigureAwait(false);
125124

126125
if (folderObjects.Any() || fileObjects.Any())
127126
{
@@ -228,7 +227,7 @@ public async Task<IList<VirtualFileInfo>> ListObjectsWithCredentialsAsync(string
228227
Guard.Against.NullOrWhiteSpace(bucketName, nameof(bucketName));
229228

230229
var client = _minioClientFactory.GetClient(credentials, _options.Settings[ConfigurationKeys.Region]);
231-
return await ListObjectsUsingClient(client, bucketName, prefix, recursive, cancellationToken);
230+
return await ListObjectsUsingClient(client, bucketName, prefix, recursive, cancellationToken).ConfigureAwait(false);
232231
}
233232

234233
public async Task PutObjectWithCredentialsAsync(string bucketName, string objectName, Stream data, long size, string contentType, Dictionary<string, string> metadata, Credentials credentials, CancellationToken cancellationToken = default)
@@ -312,7 +311,7 @@ private async Task<IList<VirtualFileInfo>> ListObjectsUsingClient(MinioClient cl
312311

313312
var objservable = client.ListObjectsAsync(listArgs, cancellationToken);
314313
var completedEvent = new ManualResetEventSlim(false);
315-
objservable.Subscribe<Item>(item =>
314+
objservable.Subscribe(item =>
316315
{
317316
if (!item.IsDir)
318317
{
@@ -330,7 +329,7 @@ private async Task<IList<VirtualFileInfo>> ListObjectsUsingClient(MinioClient cl
330329

331330
completedEvent.Wait(cancellationToken);
332331
return files;
333-
});
332+
}).ConfigureAwait(false);
334333
}
335334

336335
private static async Task RemoveObjectUsingClient(MinioClient client, string bucketName, string objectName, CancellationToken cancellationToken)
@@ -341,7 +340,7 @@ private static async Task RemoveObjectUsingClient(MinioClient client, string buc
341340
await client.RemoveObjectAsync(args, cancellationToken).ConfigureAwait(false);
342341
}
343342

344-
private async Task PutObjectUsingClient(MinioClient client, string bucketName, string objectName, Stream data, long size, string contentType, Dictionary<string, string>? metadata, CancellationToken cancellationToken)
343+
private static async Task PutObjectUsingClient(MinioClient client, string bucketName, string objectName, Stream data, long size, string contentType, Dictionary<string, string>? metadata, CancellationToken cancellationToken)
345344
{
346345
var args = new PutObjectArgs()
347346
.WithBucket(bucketName)

0 commit comments

Comments
 (0)