Compare commits

...

3 Commits

Author SHA1 Message Date
Dora Korpar 380f3a2f0f [squash] async map 2018-12-20 10:36:01 -08:00
Dora Korpar 0bebb0e8c6 [squash] add bucketname to xml 2018-12-20 10:34:42 -08:00
Dora Korpar 82e132967b feature: ZENKO-431 global mdsearch 2018-12-20 10:34:42 -08:00
2 changed files with 84 additions and 46 deletions

View File

@ -140,6 +140,7 @@ const constants = {
productName: 'APN/1.0 Scality/1.0 Scality CloudServer for Zenko',
// location constraint delimiter
zenkoSeparator: ':',
mdSearchVirtualBucket: '_all',
};
module.exports = constants;

View File

@ -1,3 +1,5 @@
const async = require('async');
const querystring = require('querystring');
const { errors, versioning, s3middleware } = require('arsenal');
const constants = require('../../constants');
@ -224,6 +226,11 @@ function processMasterVersions(bucketName, listParams, list) {
`<ETag>&quot;${v.ETag}&quot;</ETag>`,
`<Size>${v.Size}</Size>`
);
if (listParams.globalSearch) {
xml.push(
`<Bucket>${escapeXmlFn(bucketName)}</Bucket>`
);
}
if (!listParams.v2 || listParams.fetchOwner) {
xml.push(
'<Owner>',
@ -329,59 +336,89 @@ function bucketGet(authInfo, request, log, callback) {
listParams.marker = params.marker;
}
metadataValidateBucket(metadataValParams, log, (err, bucket) => {
const corsHeaders = collectCorsHeaders(request.headers.origin,
request.method, bucket);
if (err) {
log.debug('error processing request', { error: err });
monitoring.promMetrics(
'GET', bucketName, err.code, 'listBucket');
return callback(err, null, corsHeaders);
}
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,
};
return handleResult(listParams, requestMaxKeys, encoding, authInfo,
bucketName, emptyList, corsHeaders, log, callback);
}
if (params.search !== undefined) {
log.info('performing search listing', { search: params.search });
try {
listParams.mongifiedSearch = parseWhere(validatedAst);
} catch (err) {
log.debug(err.message, {
stack: err.stack,
});
monitoring.promMetrics(
'GET', bucketName, 400, 'listBucket');
return callback(errors.InvalidArgument
.customizeDescription('Invalid sql where clause ' +
'sent as search query'));
}
}
return services.getObjectListing(bucketName, listParams, log,
(err, list) => {
function validateAndSearch(metadataValParams, log, callback) {
metadataValidateBucket(metadataValParams, log, (err, bucket) => {
const corsHeaders = collectCorsHeaders(request.headers.origin,
request.method, bucket);
if (err) {
log.debug('error processing request', { error: err });
monitoring.promMetrics(
'GET', bucketName, err.code, 'listBucket');
return callback(err, null, corsHeaders);
}
return handleResult(listParams, requestMaxKeys, encoding, authInfo,
bucketName, list, corsHeaders, log, callback);
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,
};
return handleResult(listParams, requestMaxKeys, encoding,
authInfo, bucketName, emptyList, corsHeaders, log,
callback);
}
if (params.search !== undefined) {
if (metadataValParams.globalSearch) {
listParams.globalSearch = true;
}
log.info('performing search listing',
{ search: params.search });
try {
listParams.mongifiedSearch = parseWhere(validatedAst);
} catch (err) {
log.debug(err.message, {
stack: err.stack,
});
monitoring.promMetrics(
'GET', bucketName, 400, 'listBucket');
return callback(errors.InvalidArgument
.customizeDescription('Invalid sql where clause ' +
'sent as search query'));
}
}
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);
}
return handleResult(listParams, requestMaxKeys, encoding,
authInfo, bucketName, list, corsHeaders, log, callback);
});
});
});
}
if (bucketName === constants.mdSearchVirtualBucket) {
services.getService(authInfo, request, log, constants.splitter,
(err, bucketList, splitter) => {
const splitterLen = splitter.length;
async.map(bucketList, (bucket, cb) => {
const index = bucket.key.indexOf(splitter);
const bucketNameVal = bucket.key.substring(index + splitterLen);
metadataValParams.bucketName = bucketNameVal;
metadataValParams.globalSearch = true;
validateAndSearch(metadataValParams, log, cb);
}, (err, res, corsHeaders) => {
if (err) {
return callback(err, null, corsHeaders);
}
return callback(null, res, corsHeaders);
});
});
} else {
validateAndSearch(metadataValParams, log, callback);
}
return undefined;
}