-
Notifications
You must be signed in to change notification settings - Fork 255
🎨 Async/Await migration on bucketGet and objectGetLegalHold #6045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/CLDSRV-823/formatting-only
Are you sure you want to change the base?
Changes from all commits
757f7e6
a24d60c
d6af6e2
7bed447
7b03be0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| const { promisify } = require('util'); | ||
| const querystring = require('querystring'); | ||
| const { errors, errorInstances, versioning, s3middleware } = require('arsenal'); | ||
| const constants = require('../../constants'); | ||
|
|
@@ -236,8 +237,7 @@ function processMasterVersions(bucketName, listParams, list) { | |
| return xml.join(''); | ||
| } | ||
|
|
||
| function handleResult(listParams, requestMaxKeys, encoding, authInfo, | ||
| bucketName, list, corsHeaders, log, callback) { | ||
| function handleResult(listParams, requestMaxKeys, encoding, authInfo, bucketName, list, log) { | ||
| // eslint-disable-next-line no-param-reassign | ||
| listParams.maxKeys = requestMaxKeys; | ||
| // eslint-disable-next-line no-param-reassign | ||
|
|
@@ -250,7 +250,7 @@ function handleResult(listParams, requestMaxKeys, encoding, authInfo, | |
| } | ||
| pushMetric('listBucket', log, { authInfo, bucket: bucketName }); | ||
| monitoring.promMetrics('GET', bucketName, '200', 'listBucket'); | ||
| return callback(null, res, corsHeaders); | ||
| return res; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -259,27 +259,31 @@ function handleResult(listParams, requestMaxKeys, encoding, authInfo, | |
| * requester's info | ||
| * @param {object} request - http request object | ||
| * @param {function} log - Werelogs request logger | ||
| * @param {function} callback - callback to respond to http request | ||
| * with either error code or xml response body | ||
| * @return {undefined} | ||
| * @param {function} callback - callback optional to keep backward compatibility | ||
| * @return {Promise<object>} - object containing xml and additionalResHeaders | ||
| * @throws {Error} | ||
| */ | ||
| function bucketGet(authInfo, request, log, callback) { | ||
| async function bucketGet(authInfo, request, log, callback) { | ||
| if (callback) { | ||
| return bucketGet(authInfo, request, log) | ||
| .then(result => callback(null, ...result)) | ||
| .catch(err => callback(err, null, err.additionalResHeaders)); | ||
| } | ||
|
|
||
| const params = request.query; | ||
| const bucketName = request.bucketName; | ||
| const v2 = params['list-type']; | ||
|
|
||
| const optionalAttributes = | ||
| request.headers['x-amz-optional-object-attributes']?.split(',').map(attr => attr.trim()) ?? []; | ||
| if (optionalAttributes.some(attr => !attr.startsWith('x-amz-meta-') && attr != 'RestoreStatus')) { | ||
| return callback( | ||
| errorInstances.InvalidArgument.customizeDescription('Invalid attribute name specified') | ||
| ); | ||
| throw errorInstances.InvalidArgument.customizeDescription('Invalid attribute name specified'); | ||
| } | ||
|
|
||
| if (v2 !== undefined && Number.parseInt(v2, 10) !== 2) { | ||
| return callback(errorInstances.InvalidArgument.customizeDescription('Invalid ' + | ||
| 'List Type specified in Request')); | ||
| throw errorInstances.InvalidArgument.customizeDescription('Invalid List Type specified in Request'); | ||
| } | ||
|
|
||
| if (v2) { | ||
| log.addDefaultFields({ action: 'ListObjectsV2', }); | ||
| if (request.serverAccessLog) { | ||
|
|
@@ -297,18 +301,14 @@ function bucketGet(authInfo, request, log, callback) { | |
| const encoding = params['encoding-type']; | ||
| if (encoding !== undefined && encoding !== 'url') { | ||
| monitoring.promMetrics('GET', bucketName, 400, 'listBucket'); | ||
| return callback(errorInstances.InvalidArgument.customizeDescription('Invalid ' + | ||
| 'Encoding Method specified in Request')); | ||
| throw errorInstances.InvalidArgument.customizeDescription('Invalid Encoding Method specified in Request'); | ||
| } | ||
|
|
||
| const requestMaxKeys = params['max-keys'] ? Number.parseInt(params['max-keys'], 10) : 1000; | ||
| if (Number.isNaN(requestMaxKeys) || requestMaxKeys < 0) { | ||
| monitoring.promMetrics('GET', bucketName, 400, 'listBucket'); | ||
| return callback(errors.InvalidArgument); | ||
| throw errors.InvalidArgument; | ||
| } | ||
| // AWS only returns 1000 keys even if max keys are greater. | ||
| // Max keys stated in response xml can be greater than actual | ||
| // keys returned. | ||
| const actualMaxKeys = Math.min(constants.listingHardLimit, requestMaxKeys); | ||
|
|
||
| const metadataValParams = { | ||
|
|
@@ -336,47 +336,56 @@ function bucketGet(authInfo, request, log, callback) { | |
| listParams.marker = params.marker; | ||
| } | ||
|
|
||
| standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log, (err, bucket) => { | ||
| const corsHeaders = collectCorsHeaders(request.headers.origin, request.method, bucket); | ||
| let error; | ||
| let bucket; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good question. I remember encounter an issue with that some weeks (not for this PR). The answer can be found inside the So the answer is yes, |
||
|
|
||
| if (err) { | ||
| log.debug('error processing request', { error: err }); | ||
| monitoring.promMetrics('GET', bucketName, err.code, 'listBucket'); | ||
| return callback(err, null, corsHeaders); | ||
| } | ||
| try { | ||
| const standardMetadataValidateBucketPromised = promisify(standardMetadataValidateBucket); | ||
DarkIsDude marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| bucket = await standardMetadataValidateBucketPromised(metadataValParams, request.actionImplicitDenies, log); | ||
| } catch (err) { | ||
| error = err; | ||
DarkIsDude marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if (params.versions !== undefined) { | ||
| listParams.listingType = 'DelimiterVersions'; | ||
| delete listParams.marker; | ||
| listParams.keyMarker = params['key-marker']; | ||
| listParams.versionIdMarker = params['version-id-marker'] ? | ||
| versionIdUtils.decode(params['version-id-marker']) : | ||
| undefined; | ||
| } | ||
| const corsHeaders = collectCorsHeaders(request.headers.origin, request.method, bucket); | ||
|
|
||
| if (!requestMaxKeys) { | ||
| const emptyList = { | ||
| CommonPrefixes: [], | ||
| Contents: [], | ||
| Versions: [], | ||
| IsTruncated: false, | ||
| }; | ||
| return handleResult(listParams, requestMaxKeys, encoding, authInfo, | ||
| bucketName, emptyList, corsHeaders, log, callback); | ||
| } | ||
| if (error) { | ||
| log.debug('error processing request', { error }); | ||
| monitoring.promMetrics('GET', bucketName, error.code, 'listBucket'); | ||
| error.additionalResHeaders = corsHeaders; | ||
DarkIsDude marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| throw error; | ||
| } | ||
| if (params.versions !== undefined) { | ||
| listParams.listingType = 'DelimiterVersions'; | ||
| delete listParams.marker; | ||
| listParams.keyMarker = params['key-marker']; | ||
| listParams.versionIdMarker = params['version-id-marker'] ? | ||
| versionIdUtils.decode(params['version-id-marker']) : | ||
| undefined; | ||
| } | ||
| if (!requestMaxKeys) { | ||
| const emptyList = { | ||
| CommonPrefixes: [], | ||
| Contents: [], | ||
| Versions: [], | ||
| IsTruncated: false, | ||
| }; | ||
| const res = handleResult(listParams, requestMaxKeys, encoding, authInfo, bucketName, emptyList, log); | ||
| return [res, corsHeaders]; | ||
| } | ||
|
|
||
| return services.getObjectListing(bucketName, listParams, log, (err, list) => { | ||
| if (err) { | ||
| log.debug('error processing request', { error: err }); | ||
| monitoring.promMetrics('GET', bucketName, err.code, 'listBucket'); | ||
| return callback(err, null, corsHeaders); | ||
| } | ||
| let list; | ||
| try { | ||
DarkIsDude marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| list = await promisify(services.getObjectListing)(bucketName, listParams, log); | ||
| } catch (err) { | ||
| log.debug('error processing request', { error: err }); | ||
| monitoring.promMetrics('GET', bucketName, err.code, 'listBucket'); | ||
|
|
||
| return handleResult(listParams, requestMaxKeys, encoding, authInfo, | ||
| bucketName, list, corsHeaders, log, callback); | ||
| }); | ||
| }); | ||
| return undefined; | ||
| err.additionalResHeaders = corsHeaders; | ||
| throw err; | ||
| } | ||
|
|
||
| const res = handleResult(listParams, requestMaxKeys, encoding, authInfo, bucketName, list, log); | ||
| return [res, corsHeaders]; | ||
| } | ||
|
|
||
| module.exports = { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.