diff --git a/.licenserc.yaml b/.licenserc.yaml index aca4918..de4456a 100644 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -2,6 +2,8 @@ header: license: spdx-id: Apache-2.0 copyright-owner: MONAI Consortium + copyright-year: '2021-2024' + paths: - 'src' diff --git a/src/Plugins/MinIO/StorageAdminService.cs b/src/Plugins/MinIO/StorageAdminService.cs index e6dfb58..341c38d 100644 --- a/src/Plugins/MinIO/StorageAdminService.cs +++ b/src/Plugins/MinIO/StorageAdminService.cs @@ -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. @@ -15,6 +15,7 @@ */ using System.Diagnostics; +using System.Globalization; using System.IO.Abstractions; using Amazon.SecurityToken.Model; using Ardalis.GuardClauses; @@ -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 options, ILogger logger, IFileSystem fileSystem) { @@ -56,9 +60,18 @@ public StorageAdminService(IOptions 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 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) @@ -89,7 +102,7 @@ public async Task SetPolicyAsync(IdentityType policyType, List 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}`"; @@ -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."))) { @@ -260,7 +273,7 @@ private async Task 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);