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', productName: 'APN/1.0 Scality/1.0 Scality CloudServer for Zenko',
// location constraint delimiter // location constraint delimiter
zenkoSeparator: ':', zenkoSeparator: ':',
mdSearchVirtualBucket: '_all',
}; };
module.exports = constants; module.exports = constants;

View File

@ -1,3 +1,5 @@
const async = require('async');
const querystring = require('querystring'); const querystring = require('querystring');
const { errors, versioning, s3middleware } = require('arsenal'); const { errors, versioning, s3middleware } = require('arsenal');
const constants = require('../../constants'); const constants = require('../../constants');
@ -224,6 +226,11 @@ function processMasterVersions(bucketName, listParams, list) {
`<ETag>&quot;${v.ETag}&quot;</ETag>`, `<ETag>&quot;${v.ETag}&quot;</ETag>`,
`<Size>${v.Size}</Size>` `<Size>${v.Size}</Size>`
); );
if (listParams.globalSearch) {
xml.push(
`<Bucket>${escapeXmlFn(bucketName)}</Bucket>`
);
}
if (!listParams.v2 || listParams.fetchOwner) { if (!listParams.v2 || listParams.fetchOwner) {
xml.push( xml.push(
'<Owner>', '<Owner>',
@ -329,6 +336,7 @@ function bucketGet(authInfo, request, log, callback) {
listParams.marker = params.marker; listParams.marker = params.marker;
} }
function validateAndSearch(metadataValParams, log, callback) {
metadataValidateBucket(metadataValParams, log, (err, bucket) => { metadataValidateBucket(metadataValParams, log, (err, bucket) => {
const corsHeaders = collectCorsHeaders(request.headers.origin, const corsHeaders = collectCorsHeaders(request.headers.origin,
request.method, bucket); request.method, bucket);
@ -343,7 +351,8 @@ function bucketGet(authInfo, request, log, callback) {
delete listParams.marker; delete listParams.marker;
listParams.keyMarker = params['key-marker']; listParams.keyMarker = params['key-marker'];
listParams.versionIdMarker = params['version-id-marker'] ? listParams.versionIdMarker = params['version-id-marker'] ?
versionIdUtils.decode(params['version-id-marker']) : undefined; versionIdUtils.decode(params['version-id-marker']) :
undefined;
} }
if (!requestMaxKeys) { if (!requestMaxKeys) {
const emptyList = { const emptyList = {
@ -352,11 +361,16 @@ function bucketGet(authInfo, request, log, callback) {
Versions: [], Versions: [],
IsTruncated: false, IsTruncated: false,
}; };
return handleResult(listParams, requestMaxKeys, encoding, authInfo, return handleResult(listParams, requestMaxKeys, encoding,
bucketName, emptyList, corsHeaders, log, callback); authInfo, bucketName, emptyList, corsHeaders, log,
callback);
} }
if (params.search !== undefined) { 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 { try {
listParams.mongifiedSearch = parseWhere(validatedAst); listParams.mongifiedSearch = parseWhere(validatedAst);
} catch (err) { } catch (err) {
@ -378,10 +392,33 @@ function bucketGet(authInfo, request, log, callback) {
'GET', bucketName, err.code, 'listBucket'); 'GET', bucketName, err.code, 'listBucket');
return callback(err, null, corsHeaders); return callback(err, null, corsHeaders);
} }
return handleResult(listParams, requestMaxKeys, encoding, authInfo, return handleResult(listParams, requestMaxKeys, encoding,
bucketName, list, corsHeaders, log, callback); 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; return undefined;
} }