@@ -106,6 +106,40 @@ class ConfigFS {
106
106
await native_fs_utils . update_config_file ( this . root_fs_context , this . config_root , this . config_json_path , data ) ;
107
107
}
108
108
109
+ /**
110
+ * get_config_data reads a config file and returns its content
111
+ * while omitting secrets if show_secrets flag was not provided
112
+ * and decrypts the account's secret_key if decrypt_secret_key is true
113
+ * @param {string } config_file_path
114
+ * @param {boolean } [show_secrets]
115
+ * @param {boolean } [decrypt_secret_key]
116
+ */
117
+ async get_config_data ( config_file_path , show_secrets = false , decrypt_secret_key = false ) {
118
+ const { data } = await nb_native ( ) . fs . readFile ( this . root_fs_context , config_file_path ) ;
119
+ const config_data = _ . omit ( JSON . parse ( data . toString ( ) ) , show_secrets ? [ ] : [ 'access_keys' ] ) ;
120
+ if ( decrypt_secret_key ) config_data . access_keys = await nc_mkm . decrypt_access_keys ( config_data ) ;
121
+ return config_data ;
122
+ }
123
+
124
+ /**
125
+ * get_config_data_if_exists will read a config file and return its content
126
+ * while omitting secrets if show_secrets flag was not provided
127
+ * and decrypts the account's secret_key if decrypt_secret_key is true
128
+ * if the config file was deleted (encounter ENOENT error) - continue (returns undefined)
129
+ * @param {string } config_file_path
130
+ * @param {boolean } [show_secrets]
131
+ * @param {boolean } [decrypt_secret_key]
132
+ */
133
+ async get_config_data_if_exists ( config_file_path , show_secrets = false , decrypt_secret_key = false ) {
134
+ try {
135
+ const config_data = await this . get_config_data ( config_file_path , show_secrets , decrypt_secret_key ) ;
136
+ return config_data ;
137
+ } catch ( err ) {
138
+ dbg . warn ( 'get_config_data_if_exists: with config_file_path' , config_file_path , 'got an error' , err ) ;
139
+ if ( err . code !== 'ENOENT' ) throw err ;
140
+ }
141
+ }
142
+
109
143
///////////////////////////////////////
110
144
////// ACCOUNT CONFIG DIR FUNCS //////
111
145
///////////////////////////////////////
@@ -133,64 +167,25 @@ class ConfigFS {
133
167
return path . join ( this . accounts_dir_path , this . json ( account_name ) ) ;
134
168
}
135
169
136
-
137
- /**
138
- * read_root_accounts returns the root accounts array exists under the config dir
139
- * @returns {Promise<Dirent[]> }
140
- */
141
- async read_root_accounts ( ) {
142
- return nb_native ( ) . fs . readdir ( this . root_fs_context , this . accounts_dir_path ) ;
143
- }
144
-
145
170
/**
146
171
* get_iam_account_path_by_name returns the full account path by name
147
172
* @param {string } account_name
148
173
* @returns {string }
149
- */
174
+ */
150
175
get_iam_account_path_by_name ( account_name , owner_root_account_name ) {
151
- // TODO - change to this.symlink(account_name) on identities/ PR;
152
- // update IAM user location identities/root_id_number/iam_account_name.symlink
153
- return path . join ( this . accounts_dir_path , this . json ( account_name ) ) ;
176
+ // TODO - change to this.symlink(account_name) on identities/ PR;
177
+ // update IAM user location identities/root_id_number/iam_account_name.symlink
178
+ return path . join ( this . accounts_dir_path , this . json ( account_name ) ) ;
154
179
}
155
180
156
181
/**
157
182
* get_account_relative_path_by_name returns the full account path by name
158
183
* @param {string } account_name
159
184
* @returns {string }
160
- */
185
+ */
161
186
get_account_relative_path_by_name ( account_name ) {
162
- // TODO - change to this.symlink(account_name) on identities/ PR;
163
- return path . join ( '../' , CONFIG_SUBDIRS . ACCOUNTS , this . json ( account_name ) ) ;
164
- }
165
-
166
- /**
167
- * is_account_exists returns true if account config path exists in config dir
168
- * it can be determined by any account identifier - name, access_key and in the future id
169
- * @param {{ name?: string, access_key?: string } } identifier_object
170
- * @returns {Promise<boolean> }
171
- */
172
- async is_account_exists ( identifier_object ) {
173
- let path_to_check ;
174
- let use_lstat = false ;
175
- if ( identifier_object . name ) {
176
- // TODO - when users/ move to be symlink we need to use_lstat by name, id is not using lstat
177
- path_to_check = this . get_account_path_by_name ( identifier_object . name ) ;
178
- } else if ( identifier_object . access_key ) {
179
- path_to_check = this . get_account_path_by_access_key ( identifier_object . access_key ) ;
180
- use_lstat = true ;
181
- }
182
- // TODO - add is_account_exists by id when idenetities/ added
183
- // else if (identifier_object.id) {}
184
- return native_fs_utils . is_path_exists ( this . root_fs_context , path_to_check , use_lstat ) ;
185
- }
186
-
187
- /**
188
- * get_old_account_path_by_name returns the full account path by name based on old config dir structure
189
- * @param {string } account_name
190
- * @returns {string }
191
- */
192
- get_old_account_path_by_name ( account_name ) {
193
- return path . join ( this . accounts_dir_path , this . json ( account_name ) ) ;
187
+ // TODO - change to this.symlink(account_name) on identities/ PR;
188
+ return path . join ( '../' , CONFIG_SUBDIRS . ACCOUNTS , this . json ( account_name ) ) ;
194
189
}
195
190
196
191
/**
@@ -203,37 +198,33 @@ class ConfigFS {
203
198
}
204
199
205
200
/**
206
- * get_config_data reads a config file and returns its content
207
- * while omitting secrets if show_secrets flag was not provided
208
- * and decrypts the account's secret_key if decrypt_secret_key is true
209
- * @param {string } config_file_path
210
- * @param {boolean } [show_secrets]
211
- * @param {boolean } [decrypt_secret_key]
212
- */
213
- async get_config_data ( config_file_path , show_secrets = false , decrypt_secret_key = false ) {
214
- const { data } = await nb_native ( ) . fs . readFile ( this . root_fs_context , config_file_path ) ;
215
- const config_data = _ . omit ( JSON . parse ( data . toString ( ) ) , show_secrets ? [ ] : [ 'access_keys' ] ) ;
216
- if ( decrypt_secret_key ) config_data . access_keys = await nc_mkm . decrypt_access_keys ( config_data ) ;
217
- return config_data ;
201
+ * get_old_account_path_by_name returns the full account path by name based on old config dir structure
202
+ * @param {string } account_name
203
+ * @returns {string }
204
+ */
205
+ get_old_account_path_by_name ( account_name ) {
206
+ return path . join ( this . accounts_dir_path , this . json ( account_name ) ) ;
218
207
}
219
208
220
209
/**
221
- * get_config_data_if_exists will read a config file and return its content
222
- * while omitting secrets if show_secrets flag was not provided
223
- * and decrypts the account's secret_key if decrypt_secret_key is true
224
- * if the config file was deleted (encounter ENOENT error) - continue (returns undefined)
225
- * @param {string } config_file_path
226
- * @param {boolean } [show_secrets]
227
- * @param {boolean } [decrypt_secret_key]
228
- */
229
- async get_config_data_if_exists ( config_file_path , show_secrets = false , decrypt_secret_key = false ) {
230
- try {
231
- const config_data = await this . get_config_data ( config_file_path , show_secrets , decrypt_secret_key ) ;
232
- return config_data ;
233
- } catch ( err ) {
234
- dbg . warn ( 'get_config_data_if_exists: with config_file_path' , config_file_path , 'got an error' , err ) ;
235
- if ( err . code !== 'ENOENT' ) throw err ;
210
+ * is_account_exists returns true if account config path exists in config dir
211
+ * it can be determined by any account identifier - name, access_key and in the future id
212
+ * @param {{ name?: string, access_key?: string } } identifier_object
213
+ * @returns {Promise<boolean> }
214
+ */
215
+ async is_account_exists ( identifier_object ) {
216
+ let path_to_check ;
217
+ let use_lstat = false ;
218
+ if ( identifier_object . name ) {
219
+ // TODO - when users/ move to be symlink we need to use_lstat by name, id is not using lstat
220
+ path_to_check = this . get_account_path_by_name ( identifier_object . name ) ;
221
+ } else if ( identifier_object . access_key ) {
222
+ path_to_check = this . get_account_path_by_access_key ( identifier_object . access_key ) ;
223
+ use_lstat = true ;
236
224
}
225
+ // TODO - add is_account_exists by id when idenetities/ added
226
+ // else if (identifier_object.id) {}
227
+ return native_fs_utils . is_path_exists ( this . root_fs_context , path_to_check , use_lstat ) ;
237
228
}
238
229
239
230
/**
@@ -262,6 +253,14 @@ class ConfigFS {
262
253
return account ;
263
254
}
264
255
256
+ /**
257
+ * read_root_accounts returns the root accounts array exists under the config dir
258
+ * @returns {Promise<Dirent[]> }
259
+ */
260
+ async read_root_accounts ( ) {
261
+ return nb_native ( ) . fs . readdir ( this . root_fs_context , this . accounts_dir_path ) ;
262
+ }
263
+
265
264
/**
266
265
* create_account_config_file creates account config file
267
266
* if account_data.access_keys is an array that contains at least 1 item -
@@ -292,34 +291,6 @@ class ConfigFS {
292
291
}
293
292
}
294
293
295
- /**
296
- * delete_account_config_file deletes account config file
297
- * if access_keys_to_delete is an array that contains at least 1 item -
298
- * unlink all item in access_keys_to_delete
299
- * @param {string } account_name
300
- * @param {Object[] } access_keys_to_delete
301
- * @returns {Promise<void> }
302
- */
303
- async delete_account_config_file ( account_name , access_keys_to_delete = [ ] ) {
304
- const account_config_path = this . get_account_path_by_name ( account_name ) ;
305
- await native_fs_utils . delete_config_file ( this . root_fs_context , this . accounts_dir_path , account_config_path ) ;
306
- for ( const access_keys of access_keys_to_delete ) {
307
- const access_key_config_path = this . get_account_path_by_access_key ( access_keys . access_key ) ;
308
- await nb_native ( ) . fs . unlink ( this . root_fs_context , access_key_config_path ) ;
309
- }
310
- }
311
-
312
- /**
313
- * delete_access_key_config_file unlinks the access key from the file system
314
- * @param {string } access_key
315
- * @returns {Promise<void> }
316
- */
317
- async delete_access_key_config_file ( access_key ) {
318
- const acces_key_path = this . get_account_path_by_access_key ( access_key ) ;
319
- await nb_native ( ) . fs . unlink ( this . root_fs_context , acces_key_path ) ;
320
- }
321
-
322
-
323
294
/**
324
295
* update_account_config_file updates account config file
325
296
* if old_access_keys is an array that contains at least 1 item -
@@ -351,6 +322,33 @@ class ConfigFS {
351
322
}
352
323
}
353
324
325
+ /**
326
+ * delete_account_config_file deletes account config file
327
+ * if access_keys_to_delete is an array that contains at least 1 item -
328
+ * unlink all item in access_keys_to_delete
329
+ * @param {string } account_name
330
+ * @param {Object[] } access_keys_to_delete
331
+ * @returns {Promise<void> }
332
+ */
333
+ async delete_account_config_file ( account_name , access_keys_to_delete = [ ] ) {
334
+ const account_config_path = this . get_account_path_by_name ( account_name ) ;
335
+ await native_fs_utils . delete_config_file ( this . root_fs_context , this . accounts_dir_path , account_config_path ) ;
336
+ for ( const access_keys of access_keys_to_delete ) {
337
+ const access_key_config_path = this . get_account_path_by_access_key ( access_keys . access_key ) ;
338
+ await nb_native ( ) . fs . unlink ( this . root_fs_context , access_key_config_path ) ;
339
+ }
340
+ }
341
+
342
+ /**
343
+ * delete_access_key_config_file unlinks the access key from the file system
344
+ * @param {string } access_key
345
+ * @returns {Promise<void> }
346
+ */
347
+ async delete_access_key_config_file ( access_key ) {
348
+ const acces_key_path = this . get_account_path_by_access_key ( access_key ) ;
349
+ await nb_native ( ) . fs . unlink ( this . root_fs_context , acces_key_path ) ;
350
+ }
351
+
354
352
//////////////////////////////////////
355
353
////// BUCKET CONFIG DIR FUNCS //////
356
354
//////////////////////////////////////
@@ -374,6 +372,16 @@ class ConfigFS {
374
372
// TODO
375
373
}
376
374
375
+ /**
376
+ * is_bucket_exists returns true if bucket config path exists in config dir
377
+ * @param {string } bucket_name
378
+ * @returns {Promise<boolean> }
379
+ */
380
+ async is_bucket_exists ( bucket_name ) {
381
+ const path_to_check = this . get_bucket_path_by_name ( bucket_name ) ;
382
+ return native_fs_utils . is_path_exists ( this . root_fs_context , path_to_check ) ;
383
+ }
384
+
377
385
/**
378
386
* get_bucket_by_name returns the full bucket info by name
379
387
* @param {string } bucket_name
@@ -385,6 +393,25 @@ class ConfigFS {
385
393
return bucket ;
386
394
}
387
395
396
+ /**
397
+ * get_bucket_by_name returns the full bucket info by name
398
+ * @param {string } bucket_name
399
+ * @returns {Promise<any> }
400
+ */
401
+ async get_bucket_if_exists ( bucket_name ) {
402
+ const bucket_path = this . get_bucket_path_by_name ( bucket_name ) ;
403
+ const bucket = await this . get_config_data_if_exists ( bucket_path ) ;
404
+ return bucket ;
405
+ }
406
+
407
+ /**
408
+ * read_buckets returns the buckets array exists under the config dir
409
+ * @returns {Promise<Dirent[]> }
410
+ */
411
+ async read_buckets ( ) {
412
+ return nb_native ( ) . fs . readdir ( this . root_fs_context , this . buckets_dir_path ) ;
413
+ }
414
+
388
415
/**
389
416
* create_bucket_config_file creates bucket config file
390
417
* @param {string } bucket_name
@@ -416,36 +443,6 @@ class ConfigFS {
416
443
const bucket_config_path = this . get_bucket_path_by_name ( bucket_name ) ;
417
444
await native_fs_utils . delete_config_file ( this . root_fs_context , this . buckets_dir_path , bucket_config_path ) ;
418
445
}
419
-
420
- /**
421
- * read_buckets returns the buckets array exists under the config dir
422
- * @returns {Promise<Dirent[]> }
423
- */
424
- async read_buckets ( ) {
425
- return nb_native ( ) . fs . readdir ( this . root_fs_context , this . buckets_dir_path ) ;
426
- }
427
-
428
- /**
429
- * get_bucket_by_name returns the full bucket info by name
430
- * @param {string } bucket_name
431
- * @returns {Promise<any> }
432
- */
433
-
434
- async get_bucket_if_exists ( bucket_name ) {
435
- const bucket_path = this . get_bucket_path_by_name ( bucket_name ) ;
436
- const bucket = await this . get_config_data_if_exists ( bucket_path ) ;
437
- return bucket ;
438
- }
439
-
440
- /**
441
- * is_bucket_exists returns true if bucket config path exists in config dir
442
- * @param {string } bucket_name
443
- * @returns {Promise<boolean> }
444
- */
445
- async is_bucket_exists ( bucket_name ) {
446
- const path_to_check = this . get_bucket_path_by_name ( bucket_name ) ;
447
- return native_fs_utils . is_path_exists ( this . root_fs_context , path_to_check ) ;
448
- }
449
446
}
450
447
451
448
// EXPORTS
0 commit comments