Skip to content

Commit

Permalink
Merge pull request #8713 from nadavMiz/unset_suplemental_groups
Browse files Browse the repository at this point in the history
NSFS | add option to unset supplemental groups using noobaa cli
  • Loading branch information
nadavMiz authored Jan 23, 2025
2 parents 1d52ffb + 77ee6e7 commit 97f8b75
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/NooBaaNonContainerized/NooBaaCLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ noobaa-cli account update --name <account_name> [--new_name][--uid][--gid][--use

- `supplemental_groups`
- Type: String
- Description: Specifies additional FS groups (GID) a user can be a part of. Allows access to directories/files having one or more of the provided groups. A String of GIDs separated by commas.
- Description: Specifies additional FS groups (GID) a user can be a part of. Allows access to directories/files having one or more of the provided groups. A String of GIDs separated by commas. unset with ''

- `new_buckets_path`
- Type: String
Expand Down
7 changes: 6 additions & 1 deletion src/manage_nsfs/manage_nsfs_cli_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,19 @@ function get_boolean_or_string_value(value) {
* This function assumes string format was validated before calling the function, wrong string format can
* lead to unexpected output (usually array of NaN)
* 1. if the value is a number return array with this number (3 => [3])
* 2. if the value is a string return an array of numbers ('0,212,111' => [0,212,111])
* 2. if the value is a string:
* 2.1 if value is an empty string (""). unset the value
* 2.2 else return an array of numbers ('0,212,111' => [0,212,111])
* 3. for all other types (including object and undefined) return the value itself
*/
function parse_comma_delimited_string(value) {
if (typeof value === 'number') {
return [value];
}
if (typeof value === 'string') {
if (value === '') {
return undefined;
}
return value.split(',').map(val => Number(val));
}
return value;
Expand Down
2 changes: 1 addition & 1 deletion src/manage_nsfs/manage_nsfs_help_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Flags:
--new_name <string> (optional) Update the account name
--uid <number> (optional) Update the User Identifier (UID)
--gid <number> (optional) Update the Group Identifier (GID)
--supplemental_groups <number[]> (optional) Update the list of supplemental groups (List of GID) seperated by comma(,) example: 211,202,23 - it will override existing list
--supplemental_groups <string> (optional) Update the list of supplemental groups (List of GID) seperated by comma(,) example: 211,202,23 - it will override existing list (unset with '')
--new_buckets_path <string> (optional) Update the filesystem's root path where each subdirectory is a bucket
--user <string> (optional) Update the OS user name (instead of uid and gid)
--regenerate (optional) Update automatically generated access key and secret key
Expand Down
33 changes: 33 additions & 0 deletions src/test/unit_tests/jest_tests/test_nc_nsfs_account_cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,39 @@ describe('manage nsfs cli account flow', () => {
const account = await config_fs.get_account_by_name(name, config_fs_account_options);
expect(account.nsfs_account_config.supplemental_groups).toStrictEqual(expected_groups);
});

it('cli account update - cli update account with empty supplemental groups (unset)', async function() {
const { name } = defaults;
const supplemental_groups = '303,211';
const expected_groups = [303, 211];
const empty_set = '\'\'';
const account_options = { config_root, name, supplemental_groups};
await exec_manage_cli(type, ACTIONS.UPDATE, account_options);
const account = await config_fs.get_account_by_name(name, config_fs_account_options);
expect(account.nsfs_account_config.supplemental_groups).toStrictEqual(expected_groups);

//unset the value
account_options.supplemental_groups = empty_set;
await exec_manage_cli(type, ACTIONS.UPDATE, account_options);
const updated_account = await config_fs.get_account_by_name(name, config_fs_account_options);
expect(updated_account.nsfs_account_config.supplemental_groups).toBeUndefined();
});

it('cli account update - cli update account with no supplemental groups - list remains the same', async function() {
const { name } = defaults;
const supplemental_groups = '303,211';
const expected_groups = [303, 211];
const account_options = { config_root, name, supplemental_groups};
await exec_manage_cli(type, ACTIONS.UPDATE, account_options);
const account = await config_fs.get_account_by_name(name, config_fs_account_options);
expect(account.nsfs_account_config.supplemental_groups).toStrictEqual(expected_groups);

//unset the value
const new_account_options = {config_root, name};
await exec_manage_cli(type, ACTIONS.UPDATE, new_account_options);
const updated_account = await config_fs.get_account_by_name(name, config_fs_account_options);
expect(updated_account.nsfs_account_config.supplemental_groups).toStrictEqual(expected_groups);
});
});

describe('cli update account (has distinguished name)', () => {
Expand Down

0 comments on commit 97f8b75

Please sign in to comment.