Skip to content

Commit

Permalink
Update mc commands
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Chang <[email protected]>
  • Loading branch information
mocsharp committed Jun 11, 2024
1 parent 2361edd commit e2ba72b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ header:
license:
spdx-id: Apache-2.0
copyright-owner: MONAI Consortium
copyright-year: '2021-2024'


paths:
- 'src'
Expand Down
27 changes: 20 additions & 7 deletions src/Plugins/MinIO/StorageAdminService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 MONAI Consortium
* Copyright 2022-2024 MONAI Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
*/

using System.Diagnostics;
using System.Globalization;
using System.IO.Abstractions;
using Amazon.SecurityToken.Model;
using Ardalis.GuardClauses;
Expand All @@ -36,9 +37,12 @@ public class StorageAdminService : IStorageAdminService
private readonly string _accessKey;
private readonly string _secretKey;
private readonly IFileSystem _fileSystem;
private readonly string _set_connection_cmd;
private readonly string _get_connections_cmd;
private readonly string _get_users_cmd;
private string _set_connection_cmd;
private string _get_connections_cmd;
private string _get_users_cmd;
private string _set_policy_cmd;
private string _create_policy_cmd;
private string _remove_user_cmd;

public StorageAdminService(IOptions<StorageServiceConfiguration> options, ILogger<StorageAdminService> logger, IFileSystem fileSystem)

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Non-nullable field '_set_connection_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Non-nullable field '_get_connections_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Non-nullable field '_get_users_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Non-nullable field '_set_policy_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Non-nullable field '_create_policy_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Non-nullable field '_remove_user_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Non-nullable field '_set_connection_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Non-nullable field '_get_connections_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Non-nullable field '_get_users_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Non-nullable field '_set_policy_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Non-nullable field '_set_connection_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Non-nullable field '_get_connections_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Non-nullable field '_get_users_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Non-nullable field '_set_policy_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Non-nullable field '_create_policy_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Non-nullable field '_remove_user_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Non-nullable field '_set_connection_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Non-nullable field '_get_connections_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Non-nullable field '_get_users_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Non-nullable field '_set_policy_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / analyze (csharp)

Non-nullable field '_set_connection_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / analyze (csharp)

Non-nullable field '_get_connections_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / analyze (csharp)

Non-nullable field '_get_users_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / analyze (csharp)

Non-nullable field '_set_policy_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / analyze (csharp)

Non-nullable field '_create_policy_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / analyze (csharp)

Non-nullable field '_remove_user_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / analyze (csharp)

Non-nullable field '_set_connection_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / analyze (csharp)

Non-nullable field '_get_connections_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / analyze (csharp)

Non-nullable field '_get_users_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / analyze (csharp)

Non-nullable field '_set_policy_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Analyze

Non-nullable field '_set_connection_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Analyze

Non-nullable field '_get_connections_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Analyze

Non-nullable field '_get_users_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Analyze

Non-nullable field '_set_policy_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Analyze

Non-nullable field '_create_policy_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Analyze

Non-nullable field '_remove_user_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Analyze

Non-nullable field '_set_connection_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Analyze

Non-nullable field '_get_connections_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Analyze

Non-nullable field '_get_users_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 47 in src/Plugins/MinIO/StorageAdminService.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Analyze

Non-nullable field '_set_policy_cmd' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
{
Expand All @@ -56,9 +60,18 @@ public StorageAdminService(IOptions<StorageServiceConfiguration> options, ILogge
_endpoint = options.Value.Settings[ConfigurationKeys.EndPoint];
_accessKey = options.Value.Settings[ConfigurationKeys.AccessKey];
_secretKey = options.Value.Settings[ConfigurationKeys.AccessToken];

SetCommandTemplates(options);
}

private void SetCommandTemplates(IOptions<StorageServiceConfiguration> options)
{
_set_connection_cmd = $"alias set {_serviceName} http://{_endpoint} {_accessKey} {_secretKey}";
_get_connections_cmd = "alias list";
_get_users_cmd = $"admin user list {_serviceName}";
_set_policy_cmd = "admin policy attach {0} {1} --{2} {3}";
_remove_user_cmd = "admin user remove {0} {1}";
_create_policy_cmd = "admin policy create {0} pol_{1} {2}";
}

private static void ValidateConfiguration(StorageServiceConfiguration configuration)
Expand Down Expand Up @@ -89,7 +102,7 @@ public async Task<bool> SetPolicyAsync(IdentityType policyType, List<string> pol
Guard.Against.NullOrWhiteSpace(itemName, nameof(itemName));

var policiesStr = string.Join(',', policies);
var setPolicyCmd = $"admin policy set {_serviceName} {policiesStr} {policyType.ToString().ToLower()}={itemName}";
var setPolicyCmd = string.Format(CultureInfo.InvariantCulture, _set_policy_cmd, _serviceName, policiesStr, policyType.ToString().ToLowerInvariant(), itemName);
var result = await ExecuteAsync(setPolicyCmd).ConfigureAwait(false);

var expectedResult = $"Policy `{policiesStr}` is set on {policyType.ToString().ToLower()} `{itemName}`";
Expand Down Expand Up @@ -197,7 +210,7 @@ public async Task RemoveUserAsync(string username)
{
Guard.Against.NullOrWhiteSpace(username, nameof(username));

var result = await ExecuteAsync($"admin user remove {_serviceName} {username}").ConfigureAwait(false);
var result = await ExecuteAsync(string.Format(CultureInfo.InvariantCulture, _remove_user_cmd, _serviceName, username)).ConfigureAwait(false);

if (!result.Any(r => r.Contains($"Removed user `{username}` successfully.")))
{
Expand Down Expand Up @@ -260,7 +273,7 @@ private async Task<string> CreatePolicyAsync(PolicyRequest[] policyRequests, str
Guard.Against.NullOrWhiteSpace(username, nameof(username));

var policyFileName = await CreatePolicyFile(policyRequests, username).ConfigureAwait(false);
var result = await ExecuteAsync($"admin policy add {_serviceName} pol_{username} {policyFileName}").ConfigureAwait(false);
var result = await ExecuteAsync(string.Format(CultureInfo.InvariantCulture, _create_policy_cmd, _serviceName, username, policyFileName)).ConfigureAwait(false);
if (result.Any(r => r.Contains($"Added policy `pol_{username}` successfully.")) is false)
{
await RemoveUserAsync(username).ConfigureAwait(false);
Expand Down

0 comments on commit e2ba72b

Please sign in to comment.