Skip to content

Commit 1bf7a19

Browse files
committed
NC | Adding support of user bucket path
Signed-off-by: jackyalbo <[email protected]>
1 parent 0d75c6a commit 1bf7a19

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,8 @@ config.NSFS_LIST_IGNORE_ENTRY_ON_EACCES = true;
10161016
// we will for now handle the same way also EINVAL error - for gpfs stat issues on list (.snapshots)
10171017
config.NSFS_LIST_IGNORE_ENTRY_ON_EINVAL = true;
10181018

1019+
config.NSFS_USER_BUCKET_PATH_HTTP_HEADER = 'x-nsfs-bucket-path';
1020+
10191021
////////////////////////////
10201022
// NSFS NON CONTAINERIZED //
10211023
////////////////////////////

src/api/bucket_api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = {
3333
},
3434
bucket_claim: { $ref: '#/definitions/bucket_claim' },
3535
force_md5_etag: { type: 'boolean' },
36+
user_bucket_path: { type: 'string' }
3637
}
3738
},
3839
reply: {

src/endpoint/s3/ops/s3_put_bucket.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const config = require('../../../../config');
99
async function put_bucket(req, res) {
1010
const lock_enabled = config.WORM_ENABLED ? req.headers['x-amz-bucket-object-lock-enabled'] &&
1111
req.headers['x-amz-bucket-object-lock-enabled'].toUpperCase() === 'TRUE' : undefined;
12-
await req.object_sdk.create_bucket({ name: req.params.bucket, lock_enabled: lock_enabled });
12+
const user_bucket_path = req.headers[config.NSFS_USER_BUCKET_PATH_HTTP_HEADER];
13+
await req.object_sdk.create_bucket({ name: req.params.bucket, lock_enabled: lock_enabled, user_bucket_path: user_bucket_path });
1314
if (config.allow_anonymous_access_in_test && req.headers['x-amz-acl'] === 'public-read') { // For now we will enable only for tests
1415
const policy = {
1516
Version: '2012-10-17',

src/sdk/bucketspace_fs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ class BucketSpaceFS extends BucketSpaceSimpleFS {
305305

306306
const { name } = params;
307307
const bucket_config_path = this.config_fs.get_bucket_path_by_name(name);
308-
const bucket_storage_path = path.join(sdk.requesting_account.nsfs_account_config.new_buckets_path, name);
308+
const bucket_storage_path = params.user_bucket_path ||
309+
path.join(sdk.requesting_account.nsfs_account_config.new_buckets_path, name);
309310

310311
dbg.log0(`BucketSpaceFS.create_bucket
311312
requesting_account=${util.inspect(sdk.requesting_account)},

src/test/integration_tests/nsfs/test_nsfs_integration.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,49 @@ mocha.describe('bucket operations - namespace_fs', function() {
380380
console.log(inspect(res));
381381
await fs_utils.file_must_exist(path.join(s3_new_buckets_path, bucket_name + '-s3'));
382382
});
383+
mocha.it('create s3 bucket with x-nsfs-bucket-path', async function() {
384+
const new_buckets_path = get_new_buckets_path_by_test_env(tmp_fs_root, s3_new_buckets_dir);
385+
const x_nsfs_bucket_path = `${new_buckets_path}${bucket_name}-custom-path`;
386+
s3_correct_uid_default_nsr.middlewareStack.add(
387+
(next, context) => args => {
388+
args.request.headers["x-nsfs-bucket-path"] = x_nsfs_bucket_path;
389+
return next(args);
390+
},
391+
{
392+
step: "finalizeRequest",
393+
name: "addCustomHeader",
394+
}
395+
);
396+
const res = await s3_correct_uid_default_nsr.createBucket({ Bucket: bucket_name + '-s3-custom', });
397+
console.log(inspect(res));
398+
await fs_utils.file_must_exist(x_nsfs_bucket_path);
399+
s3_correct_uid_default_nsr.middlewareStack.remove("addCustomHeader");
400+
});
401+
402+
mocha.it('create s3 bucket with x-mcg-bucket-path fail as directory exist', async function() {
403+
const new_buckets_path = get_new_buckets_path_by_test_env(tmp_fs_root, s3_new_buckets_dir);
404+
const x_nsfs_bucket_path = `${new_buckets_path}${bucket_name}-custom-path`; // already created in previous test
405+
// this is the path that was created if x_nsfs_bucket_path header wasn't used
406+
const no_x_nsfs_bucket_path = `${new_buckets_path}${bucket_name}-s3-custom-fail`;
407+
s3_correct_uid_default_nsr.middlewareStack.add(
408+
(next, context) => args => {
409+
args.request.headers["x-nsfs-bucket-path"] = x_nsfs_bucket_path;
410+
return next(args);
411+
},
412+
{
413+
step: "finalizeRequest",
414+
name: "addCustomHeader",
415+
}
416+
);
417+
try {
418+
const res = await s3_correct_uid_default_nsr.createBucket({ Bucket: bucket_name + '-s3-custom-fail', });
419+
assert.fail(inspect(res));
420+
} catch (err) {
421+
assert.strictEqual(err.Code, 'BucketAlreadyExists');
422+
}
423+
await fs_utils.file_must_not_exist(no_x_nsfs_bucket_path);
424+
s3_correct_uid_default_nsr.middlewareStack.remove("addCustomHeader");
425+
});
383426

384427
mocha.it('get bucket acl - rpc bucket', async function() {
385428
const res = await s3_correct_uid_default_nsr.getBucketAcl({ Bucket: first_bucket });

0 commit comments

Comments
 (0)