Skip to content

Commit bc8b718

Browse files
committed
NC | Adding support of user bucket path
Signed-off-by: jackyalbo <jacky.albo@gmail.com>
1 parent 0d75c6a commit bc8b718

File tree

5 files changed

+54
-2
lines changed

5 files changed

+54
-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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,53 @@ 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+
// only NC supports creating buckets on custom paths
385+
if (!is_nc_coretest) this.skip(); // eslint-disable-line no-invalid-this
386+
const new_buckets_path = get_new_buckets_path_by_test_env(tmp_fs_root, s3_new_buckets_dir);
387+
const x_nsfs_bucket_path = `${new_buckets_path}${bucket_name}-custom-path`;
388+
s3_correct_uid_default_nsr.middlewareStack.add(
389+
(next, context) => args => {
390+
args.request.headers[config.NSFS_USER_BUCKET_PATH_HTTP_HEADER] = x_nsfs_bucket_path;
391+
return next(args);
392+
},
393+
{
394+
step: "finalizeRequest",
395+
name: "addCustomHeader",
396+
}
397+
);
398+
const res = await s3_correct_uid_default_nsr.createBucket({ Bucket: bucket_name + '-s3-custom', });
399+
console.log(inspect(res));
400+
await fs_utils.file_must_exist(x_nsfs_bucket_path);
401+
s3_correct_uid_default_nsr.middlewareStack.remove("addCustomHeader");
402+
});
403+
404+
mocha.it('create s3 bucket with x-nsfs-bucket-path fail as directory exists', async function() {
405+
// only NC supports creating buckets on custom paths
406+
if (!is_nc_coretest) this.skip(); // eslint-disable-line no-invalid-this
407+
const new_buckets_path = get_new_buckets_path_by_test_env(tmp_fs_root, s3_new_buckets_dir);
408+
const x_nsfs_bucket_path = `${new_buckets_path}${bucket_name}-custom-path`; // already created in previous test
409+
// this is the path that was created if x_nsfs_bucket_path header wasn't used
410+
const no_x_nsfs_bucket_path = `${new_buckets_path}${bucket_name}-s3-custom-fail`;
411+
s3_correct_uid_default_nsr.middlewareStack.add(
412+
(next, context) => args => {
413+
args.request.headers[config.NSFS_USER_BUCKET_PATH_HTTP_HEADER] = x_nsfs_bucket_path;
414+
return next(args);
415+
},
416+
{
417+
step: "finalizeRequest",
418+
name: "addCustomHeader",
419+
}
420+
);
421+
try {
422+
const res = await s3_correct_uid_default_nsr.createBucket({ Bucket: bucket_name + '-s3-custom-fail', });
423+
assert.fail(inspect(res));
424+
} catch (err) {
425+
assert.strictEqual(err.Code, 'BucketAlreadyExists');
426+
}
427+
await fs_utils.file_must_not_exist(no_x_nsfs_bucket_path);
428+
s3_correct_uid_default_nsr.middlewareStack.remove("addCustomHeader");
429+
});
383430

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

0 commit comments

Comments
 (0)