Skip to content

Commit

Permalink
Created new function to check for whitespace
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Chouhan <[email protected]>
  • Loading branch information
achouhan09 committed Jan 29, 2025
1 parent c2836b4 commit e3f52c4
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/manage_nsfs/manage_nsfs_validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,6 @@ function validate_options_type_by_value(input_options_with_data) {
const details = `type of flag ${option} should be ${type_of_option} (and the received value is ${value})`;
throw_cli_error(ManageCLIError.InvalidArgumentType, details);
}
// ensure access_keys values are not empty or whitespace only strings
if (['access_key', 'secret_key'].includes(option) && value.trim() === '') {
const details = `flag ${option} cannot have an empty value or contain only whitespace. Please provide a valid value for ${option}`;
throw_cli_error(ManageCLIError.InvalidArgument, details);
}
}
}

Expand All @@ -216,6 +211,20 @@ function validate_boolean_string_value(value) {
return false;
}

/**
* validate_no_leading_whitespace validates that a given value is not empty or whitespace-only
* @param {string} option
* @param {string} value
* @throws {ManageCLIError}
*/
function validate_no_leading_whitespace(option, value) {
// ensure values are not empty or whitespace only strings
if (value.trim() === '') {
const details = `flag ${option} cannot have an empty value or contain only whitespace. Please provide a valid value for ${option}`;
throw_cli_error(ManageCLIError.InvalidArgument, details);
}
}

/**
* validates supplemental groups array.
* string type: is comma seperated positive numbers. should not begin or end with a comma.
Expand Down Expand Up @@ -579,6 +588,10 @@ function _validate_access_keys(access_key, secret_key) {
throw_cli_error(ManageCLIError.MissingAccountAccessKeyFlag);
}

// checking access_key and secret_key do not contain only whitespace
validate_no_leading_whitespace('access_key', access_key);
validate_no_leading_whitespace('secret_key', secret_key);

// checking access_key length=20 and contains only alphanumeric chars
if (access_key && !string_utils.access_key_regexp.test(access_key)) {
throw_cli_error(ManageCLIError.InvalidAccountAccessKeyFlag);
Expand Down

0 comments on commit e3f52c4

Please sign in to comment.