@@ -40,10 +40,11 @@ public class StorageAdminService : IStorageAdminService
4040 private readonly string _get_connections_cmd ;
4141 private readonly string _get_users_cmd ;
4242
43- public StorageAdminService ( IOptions < StorageServiceConfiguration > options , ILogger < MinIoStorageService > logger , IFileSystem fileSystem )
43+ public StorageAdminService ( IOptions < StorageServiceConfiguration > options , ILogger < StorageAdminService > logger , IFileSystem fileSystem )
4444 {
45- Guard . Against . Null ( options , nameof ( options ) ) ;
46- Guard . Against . Null ( logger , nameof ( logger ) ) ;
45+ Guard . Against . Null ( options ) ;
46+ Guard . Against . Null ( logger ) ;
47+
4748 _fileSystem = fileSystem ?? throw new ArgumentNullException ( nameof ( fileSystem ) ) ;
4849
4950 var configuration = options . Value ;
@@ -62,7 +63,7 @@ public StorageAdminService(IOptions<StorageServiceConfiguration> options, ILogge
6263
6364 private static void ValidateConfiguration ( StorageServiceConfiguration configuration )
6465 {
65- Guard . Against . Null ( configuration , nameof ( configuration ) ) ;
66+ Guard . Against . Null ( configuration ) ;
6667
6768 foreach ( var key in ConfigurationKeys . McRequiredKeys )
6869 {
@@ -75,17 +76,17 @@ private static void ValidateConfiguration(StorageServiceConfiguration configurat
7576
7677 private string CreateUserCmd ( string username , string secretKey )
7778 {
78- Guard . Against . NullOrWhiteSpace ( username , nameof ( username ) ) ;
79- Guard . Against . NullOrWhiteSpace ( secretKey , nameof ( secretKey ) ) ;
79+ Guard . Against . NullOrWhiteSpace ( username ) ;
80+ Guard . Against . NullOrWhiteSpace ( secretKey ) ;
8081
8182 return $ "admin user add { _serviceName } { username } { secretKey } ";
8283 }
8384
8485 public async Task < bool > SetPolicyAsync ( IdentityType policyType , List < string > policies , string itemName )
8586 {
86- Guard . Against . Null ( policyType , nameof ( policyType ) ) ;
87- Guard . Against . Null ( policies , nameof ( policies ) ) ;
88- Guard . Against . NullOrWhiteSpace ( itemName , nameof ( itemName ) ) ;
87+ Guard . Against . Null ( policyType ) ;
88+ Guard . Against . Null ( policies ) ;
89+ Guard . Against . NullOrWhiteSpace ( itemName ) ;
8990
9091 var policiesStr = string . Join ( ',' , policies ) ;
9192 var setPolicyCmd = $ "admin policy set { _serviceName } { policiesStr } { policyType . ToString ( ) . ToLower ( ) } ={ itemName } ";
@@ -101,7 +102,7 @@ public async Task<bool> SetPolicyAsync(IdentityType policyType, List<string> pol
101102
102103 private async Task < List < string > > ExecuteAsync ( string cmd )
103104 {
104- Guard . Against . NullOrWhiteSpace ( cmd , nameof ( cmd ) ) ;
105+ Guard . Against . NullOrWhiteSpace ( cmd ) ;
105106
106107 if ( cmd . StartsWith ( "mc" ) )
107108 {
@@ -122,7 +123,7 @@ private async Task<List<string>> ExecuteAsync(string cmd)
122123
123124 private static async Task < ( List < string > Output , List < string > Errors ) > RunProcessAsync ( Process process )
124125 {
125- Guard . Against . Null ( process , nameof ( process ) ) ;
126+ Guard . Against . Null ( process ) ;
126127
127128 var output = new List < string > ( ) ;
128129 var errors = new List < string > ( ) ;
@@ -146,7 +147,7 @@ private async Task<List<string>> ExecuteAsync(string cmd)
146147
147148 private Process CreateProcess ( string cmd )
148149 {
149- Guard . Against . NullOrWhiteSpace ( cmd , nameof ( cmd ) ) ;
150+ Guard . Against . NullOrWhiteSpace ( cmd ) ;
150151
151152 ProcessStartInfo startinfo = new ( )
152153 {
@@ -186,15 +187,15 @@ public async Task<bool> SetConnectionAsync()
186187
187188 public async Task < bool > UserAlreadyExistsAsync ( string username )
188189 {
189- Guard . Against . NullOrWhiteSpace ( username , nameof ( username ) ) ;
190+ Guard . Against . NullOrWhiteSpace ( username ) ;
190191
191192 var result = await ExecuteAsync ( _get_users_cmd ) . ConfigureAwait ( false ) ;
192193 return result . Any ( r => r . Contains ( username ) ) ;
193194 }
194195
195196 public async Task RemoveUserAsync ( string username )
196197 {
197- Guard . Against . NullOrWhiteSpace ( username , nameof ( username ) ) ;
198+ Guard . Against . NullOrWhiteSpace ( username ) ;
198199
199200 var result = await ExecuteAsync ( $ "admin user remove { _serviceName } { username } ") . ConfigureAwait ( false ) ;
200201
@@ -204,26 +205,11 @@ public async Task RemoveUserAsync(string username)
204205 }
205206 }
206207
207- [ Obsolete ( "CreateUserAsync with bucketNames is deprecated, please use CreateUserAsync with an array of PolicyRequest instead." ) ]
208- public async Task < Credentials > CreateUserAsync ( string username , AccessPermissions permissions , string [ ] bucketNames )
209- {
210- Guard . Against . NullOrWhiteSpace ( username , nameof ( username ) ) ;
211- Guard . Against . Null ( bucketNames , nameof ( bucketNames ) ) ;
212-
213- var policyRequests = new List < PolicyRequest > ( ) ;
214-
215- for ( var i = 0 ; i < bucketNames . Length ; i ++ )
216- {
217- policyRequests . Add ( new PolicyRequest ( bucketNames [ i ] , "/*" ) ) ;
218- }
219-
220- return await CreateUserAsync ( username , policyRequests . ToArray ( ) ) . ConfigureAwait ( false ) ;
221- }
222208
223209 public async Task < Credentials > CreateUserAsync ( string username , PolicyRequest [ ] policyRequests )
224210 {
225- Guard . Against . NullOrWhiteSpace ( username , nameof ( username ) ) ;
226- Guard . Against . Null ( policyRequests , nameof ( policyRequests ) ) ;
211+ Guard . Against . NullOrWhiteSpace ( username ) ;
212+ Guard . Against . Null ( policyRequests ) ;
227213
228214 if ( ! await SetConnectionAsync ( ) . ConfigureAwait ( false ) )
229215 {
@@ -270,8 +256,8 @@ public async Task<Credentials> CreateUserAsync(string username, PolicyRequest[]
270256 /// <exception cref="InvalidOperationException"></exception>
271257 private async Task < string > CreatePolicyAsync ( PolicyRequest [ ] policyRequests , string username )
272258 {
273- Guard . Against . Null ( policyRequests , nameof ( policyRequests ) ) ;
274- Guard . Against . NullOrWhiteSpace ( username , nameof ( username ) ) ;
259+ Guard . Against . Null ( policyRequests ) ;
260+ Guard . Against . NullOrWhiteSpace ( username ) ;
275261
276262 var policyFileName = await CreatePolicyFile ( policyRequests , username ) . ConfigureAwait ( false ) ;
277263 var result = await ExecuteAsync ( $ "admin policy add { _serviceName } pol_{ username } { policyFileName } ") . ConfigureAwait ( false ) ;
@@ -287,8 +273,8 @@ private async Task<string> CreatePolicyAsync(PolicyRequest[] policyRequests, str
287273
288274 private async Task < string > CreatePolicyFile ( PolicyRequest [ ] policyRequests , string username )
289275 {
290- Guard . Against . NullOrEmpty ( policyRequests , nameof ( policyRequests ) ) ;
291- Guard . Against . NullOrWhiteSpace ( username , nameof ( username ) ) ;
276+ Guard . Against . NullOrEmpty ( policyRequests ) ;
277+ Guard . Against . NullOrWhiteSpace ( username ) ;
292278
293279 var policy = PolicyExtensions . ToPolicy ( policyRequests ) ;
294280 var jsonPolicy = policy . ToJson ( ) ;
0 commit comments