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,6 +336,7 @@ function bucketGet(authInfo, request, log, callback) {
listParams.marker = params.marker;
}
function validateAndSearch(metadataValParams, log, callback) {
metadataValidateBucket(metadataValParams, log, (err, bucket) => {
const corsHeaders = collectCorsHeaders(request.headers.origin,
request.method, bucket);
@ -343,7 +351,8 @@ function bucketGet(authInfo, request, log, callback) {
delete listParams.marker;
listParams.keyMarker = params['key-marker'];
listParams.versionIdMarker = params['version-id-marker'] ?
versionIdUtils.decode(params['version-id-marker']) : undefined;
versionIdUtils.decode(params['version-id-marker']) :
undefined;
}
if (!requestMaxKeys) {
const emptyList = {
@ -352,11 +361,16 @@ function bucketGet(authInfo, request, log, callback) {
Versions: [],
IsTruncated: false,
};
return handleResult(listParams, requestMaxKeys, encoding, authInfo,
bucketName, emptyList, corsHeaders, log, callback);
return handleResult(listParams, requestMaxKeys, encoding,
authInfo, bucketName, emptyList, corsHeaders, log,
callback);
}
if (params.search !== undefined) {
log.info('performing search listing', { search: params.search });
if (metadataValParams.globalSearch) {
listParams.globalSearch = true;
}
log.info('performing search listing',
{ search: params.search });
try {
listParams.mongifiedSearch = parseWhere(validatedAst);
} catch (err) {
@ -378,10 +392,33 @@ function bucketGet(authInfo, request, log, callback) {
'GET', bucketName, err.code, 'listBucket');
return callback(err, null, corsHeaders);
}
return handleResult(listParams, requestMaxKeys, encoding, authInfo,
bucketName, list, corsHeaders, log, callback);
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;
}