Skip to content

Commit eaf259a

Browse files
used config.js for declaration of max length and updated the error msg
Signed-off-by: Aayush Chouhan <[email protected]>
1 parent 90cde4c commit eaf259a

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ config.LIFECYCLE_INTERVAL = 8 * 60 * 60 * 1000; // 8h
466466
config.LIFECYCLE_BATCH_SIZE = 1000;
467467
config.LIFECYCLE_SCHEDULE_MIN = 5 * 1000 * 60; // run every 5 minutes
468468
config.LIFECYCLE_ENABLED = true;
469+
config.MAX_RULE_ID_LENGTH = 255;
469470

470471
//////////////////////////
471472
// STATISTICS_COLLECTOR //

src/endpoint/s3/ops/s3_put_bucket_lifecycle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
'use strict';
33

44
const _ = require('lodash');
5+
const config = require('../../../../config');
56
const { v4: uuid } = require('uuid');
67
const dbg = require('../../../util/debug_module')(__filename);
78
const S3Error = require('../s3_errors').S3Error;
89

910
const true_regex = /true/i;
10-
const max_length_rule_id = 255;
1111

1212
// parse lifecycle rule filter
1313
function parse_filter(filter) {
@@ -89,8 +89,8 @@ async function put_bucket_lifecycle(req) {
8989
};
9090

9191
if (rule.ID?.length === 1) {
92-
if (rule.ID[0].length > max_length_rule_id) {
93-
dbg.error('Rule should not have ID length exceeding', max_length_rule_id, 'characters', rule);
92+
if (rule.ID[0].length > config.MAX_RULE_ID_LENGTH) {
93+
dbg.error('Rule should not have ID length exceed allowed limit of ', config.MAX_RULE_ID_LENGTH, ' characters', rule);
9494
throw new S3Error(S3Error.InvalidArgument);
9595
} else {
9696
current_rule.id = rule.ID[0];

src/test/lifecycle/common.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
'use strict';
33

44
const assert = require('assert');
5+
const config = require('../../../config');
56

6-
const max_length_rule_id = 255;
77
/*
88
* https://docs.aws.amazon.com/AmazonS3/latest/userguide/intro-lifecycle-rules.html
99
*/
@@ -517,14 +517,14 @@ exports.test_and_prefix_size = async function(Bucket, Key, s3) {
517517
exports.test_rule_id_length = async function(Bucket, Key, s3) {
518518
const putLifecycleParams = id_lifecycle_configuration(Bucket, Key);
519519

520-
// set the ID to a value with more than 'max_length_rule_id' characters
521-
const ID = 'A'.repeat(max_length_rule_id);
520+
// set the ID to a value with more than 'MAX_RULE_ID_LENGTH' characters
521+
const ID = 'A'.repeat(config.MAX_RULE_ID_LENGTH + 5);
522522
putLifecycleParams.LifecycleConfiguration.Rules[0].ID = ID;
523523

524524
try {
525525
await s3.putBucketLifecycleConfiguration(putLifecycleParams);
526526
} catch (error) {
527527
assert(error.code === 'InvalidArgument', 'Expected InvalidArgument: id length exceeding 255 characters');
528-
console.log('Expected error received, id length exceeding 255 characters');
528+
console.log('Expected error received, id length exceeding', config.MAX_RULE_ID_LENGTH, 'characters');
529529
}
530530
};

0 commit comments

Comments
 (0)