Skip to content

Commit

Permalink
Updated enum, added comments and JSDoc
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Chouhan <[email protected]>
  • Loading branch information
achouhan09 committed Jan 13, 2025
1 parent eea1f24 commit ebe42c9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/endpoint/s3/ops/s3_put_bucket_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ async function put_bucket_lifecycle(req) {
}
id_set.add(current_rule.id);

if (rule.Status?.length !== 1) {
if (!rule.Status || rule.Status.length !== 1) {
dbg.error('Rule should have status', rule);
throw new S3Error(S3Error.InvalidArgument);
} else if (rule.Status?.length === 1) {
if (!s3_const.STATUS_VAL.ENUM.includes(rule.Status[0])) {
dbg.error('Rule should not have status value other than "Enabled" and "Disabled" ', rule);
throw new S3Error(S3Error.MalformedXML);
}
}
current_rule.status = rule.Status[0];
const status = rule.Status[0];
if (status !== s3_const.LIFECYCLE_STATUS.STAT_ENABLED && status !== s3_const.LIFECYCLE_STATUS.STAT_DISABLED) {
dbg.error(`Rule should not have status value other than "${s3_const.LIFECYCLE_STATUS.STAT_ENABLED}" and "${s3_const.LIFECYCLE_STATUS.STAT_DISABLED}" `, rule);
throw new S3Error(S3Error.MalformedXML);
}
current_rule.status = status;

if (rule.Prefix) {
if (rule.Filter?.length === 1) {
Expand Down
6 changes: 3 additions & 3 deletions src/endpoint/s3/s3_constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const s3_const = exports;
///////////////

s3_const.MAX_RULE_ID_LENGTH = 255;
s3_const.STATUS_VAL = Object.freeze({
ENUM: Object.freeze(['Enabled', 'Disabled']),
TYPE: 'string'
s3_const.LIFECYCLE_STATUS = Object.freeze({
STAT_ENABLED: 'Enabled',
STAT_DISABLED: 'Disabled'
});
3 changes: 2 additions & 1 deletion src/endpoint/s3/s3_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ S3Error.MalformedPOSTRequest = Object.freeze({
});
S3Error.MalformedXML = Object.freeze({
code: 'MalformedXML',
// This happens when the user sends malformed xml (xml that doesn\'t conform to the published xsd) for the configuration.
message: 'The XML you provided was not well-formed or did not validate against our published schema.',
http_code: 400,
});
Expand Down Expand Up @@ -512,7 +513,7 @@ S3Error.XAmzContentSHA256Mismatch = Object.freeze({
});
S3Error.MalformedPolicy = Object.freeze({
code: 'MalformedPolicy',
message: 'Invalid principal in policy',
message: 'Policy was not well-formed or did not validate against the published schema.',
http_code: 400,
detail: '...', // will be overridden from rpc_data, see handle_error in s3_rest.js
});
Expand Down
11 changes: 8 additions & 3 deletions src/endpoint/s3/s3_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,11 +785,16 @@ function key_marker_to_cont_tok(key_marker, objects_arr, is_truncated) {
return Buffer.from(j).toString('base64');
}

/**
* invalid_schema_to_aws_error handles specific AWS error responses related to invalid schema or parameters
* If the error's `rpc_code` is either `INVALID_SCHEMA` or `INVALID_SCHEMA_PARAMS`,
* the function throws a `MalformedPolicy` error. Otherwise, it throws the original error.
*
* @param {Object} error - The error object to handle
*/
function invalid_schema_to_aws_error(error) {
if (["INVALID_SCHEMA", "INVALID_SCHEMA_PARAMS"].includes(error.rpc_code)) {
const err = new S3Error(S3Error.MalformedPolicy);
err.message = "Policy was not well-formed or did not validate against the published schema";
throw err;
throw new S3Error(S3Error.MalformedPolicy);
}
throw error;
}
Expand Down

0 comments on commit ebe42c9

Please sign in to comment.