Skip to content

Commit 8906f86

Browse files
committed
Lifecycle configuration support in bucketspace_fs
* added set\get\delete for lifecycle configuration * refactored bucket_lifecycle_configuration in common_api * added lifecycle_configuration_rules in nsfs_bucket_schema.js Signed-off-by: Danny Zaken <dannyzaken@gmail.com>
1 parent ff0ae59 commit 8906f86

File tree

7 files changed

+94
-51
lines changed

7 files changed

+94
-51
lines changed

docs/NooBaaNonContainerized/S3Ops.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ The following lists describe the bucket and object operations available in NooBa
2525
- S3 DeleteBucketPolicy
2626
- S3 GetBucketPolicy
2727
- S3 GetBucketPolicyStatus
28+
- S3 PutBucketLifecycleConfiguration
29+
- S3 GetBucketLifecycleConfiguration
30+
- S3 DeleteBucketLifecycle
31+
2832

2933
### Supported S3 Object Operations
3034

src/api/bucket_api.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,7 @@ module.exports = {
599599
type: 'object',
600600
properties: {
601601
name: { $ref: 'common_api#/definitions/bucket_name' },
602-
rules: {
603-
type: 'array',
604-
items: {
605-
$ref: 'common_api#/definitions/bucket_lifecycle_rule'
606-
},
607-
}
602+
rules: { $ref: 'common_api#/definitions/bucket_lifecycle_configuration' }
608603
}
609604
},
610605
auth: {
@@ -620,12 +615,7 @@ module.exports = {
620615
name: { $ref: 'common_api#/definitions/bucket_name' },
621616
}
622617
},
623-
reply: {
624-
type: 'array',
625-
items: {
626-
$ref: 'common_api#/definitions/bucket_lifecycle_rule'
627-
}
628-
},
618+
reply: { $ref: 'common_api#/definitions/bucket_lifecycle_configuration' },
629619
auth: {
630620
system: 'admin'
631621
}
@@ -1385,7 +1375,7 @@ module.exports = {
13851375
type: 'object',
13861376
properties: {
13871377
prefix: { type: 'string' },
1388-
// s3 support also tag or and operator of 2 tags/ tag and prefix
1378+
// s3 support also tag or and operator of 2 tags/ tag and prefix
13891379
}
13901380
},
13911381
sync_deletions: { type: 'boolean' },

src/api/common_api.js

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ module.exports = {
195195
}
196196
}
197197
},
198+
bucket_lifecycle_configuration: {
199+
type: 'array',
200+
items: {
201+
$ref: '#/definitions/bucket_lifecycle_rule'
202+
}
203+
},
198204
bucket_lifecycle_rule: {
199205
type: 'object',
200206
required: ['id', 'filter', 'expiration', 'status'],
@@ -259,27 +265,26 @@ module.exports = {
259265

260266
bucket_policy_principal: {
261267
anyOf: [{
262-
wrapper: SensitiveString
263-
}, {
264-
type: 'object',
265-
required: ['AWS'],
266-
properties: {
267-
AWS: {
268-
anyOf: [{
269-
wrapper: SensitiveString
270-
}, {
271-
type: 'array',
272-
items: {
273-
wrapper: SensitiveString
274-
}
275-
}]
276-
}
268+
wrapper: SensitiveString
269+
}, {
270+
type: 'object',
271+
required: ['AWS'],
272+
properties: {
273+
AWS: {
274+
anyOf: [{
275+
wrapper: SensitiveString
276+
}, {
277+
type: 'array',
278+
items: {
279+
wrapper: SensitiveString
280+
}
281+
}]
277282
}
278283
}
279-
]},
284+
}]
285+
},
280286
string_or_string_array: {
281-
anyOf: [
282-
{
287+
anyOf: [{
283288
type: 'string'
284289
},
285290
{
@@ -288,7 +293,7 @@ module.exports = {
288293
type: 'string'
289294
}
290295
}
291-
]
296+
]
292297
},
293298

294299
bucket_policy_string_condition: {
@@ -314,8 +319,7 @@ module.exports = {
314319
Statement: {
315320
type: 'array',
316321
items: {
317-
allOf: [
318-
{
322+
allOf: [{
319323
type: 'object',
320324
required: ['Effect'],
321325
properties: {
@@ -378,8 +382,7 @@ module.exports = {
378382
// the schema above. these schemas are only here to validate the mutually exclusive required fields
379383
// they should be replaced once we support allOf for individual fields
380384
{
381-
oneOf: [
382-
{
385+
oneOf: [{
383386
type: 'object',
384387
required: ["Principal"],
385388
additionalProperties: true,
@@ -394,8 +397,7 @@ module.exports = {
394397
],
395398
},
396399
{
397-
oneOf: [
398-
{
400+
oneOf: [{
399401
type: 'object',
400402
required: ["Action"],
401403
additionalProperties: true,
@@ -407,11 +409,10 @@ module.exports = {
407409
additionalProperties: true,
408410
properties: {}
409411
}
410-
],
412+
],
411413
},
412414
{
413-
oneOf: [
414-
{
415+
oneOf: [{
415416
type: 'object',
416417
required: ["Resource"],
417418
additionalProperties: true,
@@ -1270,7 +1271,7 @@ module.exports = {
12701271
}
12711272
},
12721273

1273-
// nsfs
1274+
// nsfs
12741275

12751276
fs_backend: {
12761277
type: 'string',
@@ -1301,7 +1302,7 @@ module.exports = {
13011302
}
13021303
}, {
13031304
type: 'object',
1304-
required: [ 'distinguished_name', 'new_buckets_path', 'nsfs_only'],
1305+
required: ['distinguished_name', 'new_buckets_path', 'nsfs_only'],
13051306
properties: {
13061307
distinguished_name: { wrapper: SensitiveString },
13071308
new_buckets_path: { type: 'string' },

src/sdk/bucketspace_fs.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,41 @@ class BucketSpaceFS extends BucketSpaceSimpleFS {
378378
//////////////////////
379379

380380
async get_bucket_lifecycle_configuration_rules(params) {
381-
// TODO
381+
try {
382+
const { name } = params;
383+
dbg.log0('BucketSpaceFS.get_bucket_lifecycle_configuration_rules: Bucket name', name);
384+
const bucket = await this.config_fs.get_bucket_by_name(name);
385+
return bucket.lifecycle_configuration_rules || [];
386+
} catch (error) {
387+
throw translate_error_codes(error, entity_enum.BUCKET);
388+
}
382389
}
383390

384391
async set_bucket_lifecycle_configuration_rules(params) {
385-
// TODO
392+
try {
393+
const { name, rules } = params;
394+
dbg.log0('BucketSpaceFS.set_bucket_lifecycle_configuration_rules: Bucket name, rules', name, rules);
395+
const bucket = await this.config_fs.get_bucket_by_name(name);
396+
bucket.lifecycle_configuration_rules = rules;
397+
nsfs_schema_utils.validate_bucket_schema(bucket);
398+
const update_bucket = JSON.stringify(bucket);
399+
await this.config_fs.update_bucket_config_file(name, update_bucket);
400+
} catch (err) {
401+
throw translate_error_codes(err, entity_enum.BUCKET);
402+
}
386403
}
387404

388405
async delete_bucket_lifecycle(params) {
389-
// TODO
406+
try {
407+
const { name } = params;
408+
dbg.log0('BucketSpaceFS.delete_bucket_lifecycle: Bucket name', name);
409+
const bucket = await this.config_fs.get_bucket_by_name(name);
410+
delete bucket.lifecycle_configuration_rules;
411+
nsfs_schema_utils.validate_bucket_schema(bucket);
412+
await this.config_fs.update_bucket_config_file(name, JSON.stringify(bucket));
413+
} catch (error) {
414+
throw translate_error_codes(error, entity_enum.BUCKET);
415+
}
390416
}
391417

392418
///////////////////////

src/server/system_services/schemas/bucket_schema.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,7 @@ module.exports = {
201201

202202
//lifecycle rules if exist
203203
lifecycle_configuration_rules: {
204-
type: 'array',
205-
items: {
206-
$ref: 'common_api#/definitions/bucket_lifecycle_rule'
207-
}
204+
$ref: 'common_api#/definitions/bucket_lifecycle_configuration'
208205
},
209206
tagging: {
210207
$ref: 'common_api#/definitions/tagging',

src/server/system_services/schemas/nsfs_bucket_schema.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = {
2828
name: {
2929
type: 'string',
3030
},
31-
/**
31+
/**
3232
* @deprecated system_owner is kept for backward compatibility,
3333
* but will no longer be included in new / updated bucket json.
3434
*/
@@ -75,5 +75,8 @@ module.exports = {
7575
logging: {
7676
$ref: 'common_api#/definitions/bucket_logging',
7777
},
78+
lifecycle_configuration_rules: {
79+
$ref: 'common_api#/definitions/bucket_lifecycle_configuration',
80+
},
7881
}
7982
};

src/test/unit_tests/test_bucketspace_fs.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,28 @@ mocha.describe('bucketspace_fs', function() {
800800
assert.deepEqual(tag, { tagging: [] });
801801
});
802802
});
803+
804+
mocha.describe('bucket lifecycle operations', function() {
805+
mocha.it('set_bucket_lifecycle_configuration_rules', async function() {
806+
const lifecycle_rules = [{
807+
id: 'rule1',
808+
status: 'Enabled',
809+
filter: { prefix: 'test/' },
810+
expiration: { days: 30 }
811+
}];
812+
const param = { name: test_bucket, rules: lifecycle_rules };
813+
await bucketspace_fs.set_bucket_lifecycle_configuration_rules(param);
814+
const output_lifecycle = await bucketspace_fs.get_bucket_lifecycle_configuration_rules(param);
815+
assert.deepEqual(output_lifecycle, lifecycle_rules);
816+
});
817+
818+
mocha.it('delete_bucket_lifecycle', async function() {
819+
const param = { name: test_bucket };
820+
await bucketspace_fs.delete_bucket_lifecycle(param);
821+
const output_lifecycle = await bucketspace_fs.get_bucket_lifecycle_configuration_rules(param);
822+
assert.deepEqual(output_lifecycle, []);
823+
});
824+
});
803825
});
804826

805827
async function create_bucket(bucket_name) {

0 commit comments

Comments
 (0)