MCPcopy
hub / github.com/scality/cloudserver / callApiHandler

Function callApiHandler

lib/api/api.js:246–431  ·  view source on GitHub ↗
(apiMethod, apiHandler, request, response, log, callback)

Source from the content-addressed store, hash-verified

244}
245
246function callApiHandler(apiMethod, apiHandler, request, response, log, callback) {
247 let returnTagCount = true;
248
249 const validationRes = validateQueryAndHeaders(request, log);
250 if (validationRes.error) {
251 log.debug('request query / header validation failed', {
252 error: validationRes.error,
253 method: 'api.callApiMethod',
254 });
255 return process.nextTick(callback, validationRes.error);
256 }
257
258 // no need to check auth on website or cors preflight requests
259 if (apiMethod === 'websiteGet' || apiMethod === 'websiteHead' ||
260 apiMethod === 'corsPreflight') {
261 request.actionImplicitDenies = false;
262 return apiHandler(request, log, callback);
263 }
264
265 const { sourceBucket, sourceObject, sourceVersionId, parsingError } =
266 parseCopySource(apiMethod, request.headers['x-amz-copy-source']);
267 if (parsingError) {
268 log.debug('error parsing copy source', {
269 error: parsingError,
270 });
271 return process.nextTick(callback, parsingError);
272 }
273
274 const { httpHeadersSizeError } = checkHttpHeadersSize(request.headers);
275 if (httpHeadersSizeError) {
276 log.debug('http header size limit exceeded', {
277 error: httpHeadersSizeError,
278 });
279 return process.nextTick(callback, httpHeadersSizeError);
280 }
281
282 const requestContexts = prepareRequestContexts(apiMethod, request,
283 sourceBucket, sourceObject, sourceVersionId);
284
285 // Extract all the _apiMethods and store them in an array
286 const apiMethods = requestContexts ? requestContexts.map(context => context._apiMethod) : [];
287 // Attach the names to the current request
288 request.apiMethods = apiMethods;
289
290 return async.waterfall([
291 next => auth.server.doAuth(
292 request, log, (err, userInfo, authorizationResults, streamingV4Params, infos) => {
293 if (request.serverAccessLog) {
294 request.serverAccessLog.authInfo = userInfo;
295 }
296 if (err) {
297 // VaultClient returns standard errors, but the route requires
298 // Arsenal errors
299 const arsenalError = err.metadata ? err : errors[err.code] || errors.InternalError;
300 log.trace('authentication error', { error: err });
301 return next(arsenalError);
302 }
303 return next(null, userInfo, authorizationResults, streamingV4Params, infos);

Callers

nothing calls this directly

Calls 14

validateQueryAndHeadersFunction · 0.85
parseCopySourceFunction · 0.85
checkHttpHeadersSizeFunction · 0.85
prepareRequestContextsFunction · 0.85
isRequesterASessionUserFunction · 0.85
setStartTurnAroundTimeFunction · 0.85
writeContinueFunction · 0.85
tagConditionKeyAuthFunction · 0.85
debugMethod · 0.80
traceMethod · 0.80

Tested by

no test coverage detected