[go: up one dir, main page]

Skip to content

Commit

Permalink
Merge pull request #8330 from tangledbytes/utkarsh/backport/5.16.x/8255
Browse files Browse the repository at this point in the history
[Backport 5.16] add support for "Server" and "x-noobaa-available-storage-classes" headers
  • Loading branch information
nimrod-becker authored Sep 5, 2024
2 parents a15bf2d + ea7379e commit 1c40d7b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/endpoint/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ function create_endpoint_handler(init_request_sdk, virtual_hosts, sts) {

/** @type {EndpointHandler} */
const endpoint_request_handler = (req, res) => {
endpoint_utils.set_noobaa_server_header(res);
endpoint_utils.prepare_rest_request(req);
req.virtual_hosts = virtual_hosts;
init_request_sdk(req, res);
Expand All @@ -251,6 +252,7 @@ function create_endpoint_handler(init_request_sdk, virtual_hosts, sts) {
};
/** @type {EndpointHandler} */
const endpoint_sts_request_handler = (req, res) => {
endpoint_utils.set_noobaa_server_header(res);
endpoint_utils.prepare_rest_request(req);
init_request_sdk(req, res);
return sts_rest(req, res);
Expand Down
5 changes: 5 additions & 0 deletions src/endpoint/endpoint_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

const querystring = require('querystring');
const http_utils = require('../util/http_utils');
const pkg = require('../../package.json');

function prepare_rest_request(req) {
// generate request id, this is lighter than uuid
Expand Down Expand Up @@ -38,6 +39,10 @@ function parse_source_url(source_url) {
return { query, bucket, key };
}

function set_noobaa_server_header(res) {
res.setHeader('Server', `NooBaa/${pkg.version}`);
}

exports.prepare_rest_request = prepare_rest_request;
exports.parse_source_url = parse_source_url;
exports.set_noobaa_server_header = set_noobaa_server_header;
9 changes: 5 additions & 4 deletions src/endpoint/s3/ops/s3_head_bucket.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* Copyright (C) 2016 NooBaa */
'use strict';

const s3_utils = require("../s3_utils");

/**
* http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketHEAD.html
*/
async function head_bucket(req) {
await req.object_sdk.read_bucket({ name: req.params.bucket });
// only called to check for existence
// no headers or reply needed
async function head_bucket(req, res) {
const bucket_info = await req.object_sdk.read_bucket({ name: req.params.bucket });
s3_utils.set_response_supported_storage_classes(res, bucket_info.supported_storage_classes);
}

module.exports = {
Expand Down
11 changes: 11 additions & 0 deletions src/endpoint/s3/s3_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const DEFAULT_OBJECT_ACL = Object.freeze({
const XATTR_SORT_SYMBOL = Symbol('XATTR_SORT_SYMBOL');
const base64_regex = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;

const X_NOOBAA_AVAILABLE_STORAGE_CLASSES = 'x-noobaa-available-storage-classes';

function decode_chunked_upload(source_stream) {
const decoder = new ChunkedContentDecoder();
// pipeline will back-propagate errors from the decoder to stop streaming from the source,
Expand Down Expand Up @@ -283,6 +285,14 @@ function set_response_object_md(res, object_md) {
}
}

/**
* @param {nb.S3Response} res
* @param {Array<string>} [supported_storage_classes]
*/
function set_response_supported_storage_classes(res, supported_storage_classes = []) {
res.setHeader(X_NOOBAA_AVAILABLE_STORAGE_CLASSES, supported_storage_classes);
}

/**
* @param {nb.S3Request} req
* @returns {nb.StorageClass}
Expand Down Expand Up @@ -694,3 +704,4 @@ exports.get_response_field_encoder = get_response_field_encoder;
exports.parse_decimal_int = parse_decimal_int;
exports.parse_restore_request_days = parse_restore_request_days;
exports.parse_version_id = parse_version_id;
exports.set_response_supported_storage_classes = set_response_supported_storage_classes;
18 changes: 18 additions & 0 deletions src/sdk/bucketspace_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const { CONFIG_SUBDIRS } = require('../manage_nsfs/manage_nsfs_constants');
const KeysSemaphore = require('../util/keys_semaphore');
const native_fs_utils = require('../util/native_fs_utils');
const NoobaaEvent = require('../manage_nsfs/manage_nsfs_events_utils').NoobaaEvent;
const s3_utils = require('../endpoint/s3/s3_utils');

const dbg = require('../util/debug_module')(__filename);
const bucket_semaphore = new KeysSemaphore(1);
Expand Down Expand Up @@ -158,6 +159,7 @@ class BucketSpaceFS extends BucketSpaceSimpleFS {
id: bucket.owner_account,
email: bucket.bucket_owner
};
bucket.supported_storage_classes = this._supported_storage_class();
if (bucket.s3_policy) {
for (const [s_index, statement] of bucket.s3_policy.Statement.entries()) {
const statement_principal = statement.Principal || statement.NotPrincipal;
Expand Down Expand Up @@ -710,6 +712,22 @@ class BucketSpaceFS extends BucketSpaceSimpleFS {
throw err;
}
}

/**
* returns a list of storage class supported by this bucketspace
* @returns {Array<string>}
*/
_supported_storage_class() {
const storage_classes = [];
if (!config.DENY_UPLOAD_TO_STORAGE_CLASS_STANDARD) {
storage_classes.push(s3_utils.STORAGE_CLASS_STANDARD);
}
if (config.NSFS_GLACIER_ENABLED) {
storage_classes.push(s3_utils.STORAGE_CLASS_GLACIER);
}

return storage_classes;
}
}

module.exports = BucketSpaceFS;

0 comments on commit 1c40d7b

Please sign in to comment.