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

Function callApiMethod

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

Source from the content-addressed store, hash-verified

432
433const api = {
434 callApiMethod(apiMethod, request, response, log, callback) {
435 // Attach the apiMethod method to the request, so it can used by monitoring in the server
436 request.apiMethod = apiMethod;
437 callback = wrapCallbackWithErrorCorsHeaders(
438 callback, request, response, log);
439 // Array of end of API callbacks, used to perform some logic
440 // at the end of an API.
441 request.finalizerHooks = [];
442
443 const actionLog = monitoringMap[apiMethod];
444 if (!actionLog &&
445 apiMethod !== 'websiteGet' &&
446 apiMethod !== 'websiteHead' &&
447 apiMethod !== 'corsPreflight') {
448 log.error('callApiMethod(): No actionLog for this api method', {
449 apiMethod,
450 });
451 }
452 log.addDefaultFields({
453 service: 's3',
454 action: actionLog,
455 bucketName: request.bucketName,
456 });
457 if (request.objectKey) {
458 log.addDefaultFields({
459 objectKey: request.objectKey,
460 });
461 }
462 if (request.serverAccessLog) {
463 request.serverAccessLog.bucketName = request.bucketName;
464 request.serverAccessLog.objectKey = request.objectKey;
465 request.serverAccessLog.analyticsAction = actionLog;
466 }
467
468 // Initialize rate limit tracker flag
469 request.rateLimitBucketAlreadyChecked = false;
470 request.rateLimitAccountAlreadyChecked = false;
471
472 const apiHandler = this[apiMethod];
473
474 // Process the request with validation, authentication, and execution
475
476 if (request.bucketName === undefined || !requestNeedsRateCheck(request)) {
477 return process.nextTick(callApiHandler, apiMethod, apiHandler, request, response, log, callback);
478 }
479
480 const checks = [];
481 const rateLimitConfig = getCachedRateLimitConfig(request);
482
483 if (rateLimitConfig.bucket !== undefined) {
484 request.rateLimitBucketAlreadyChecked = true;
485 checks.push(...buildRateChecksFromConfig('bucket', request.bucketName, rateLimitConfig.bucket));
486 }
487
488 if (rateLimitConfig.account !== undefined) {
489 request.rateLimitAccountAlreadyChecked = true;
490 checks.push(...buildRateChecksFromConfig('account', rateLimitConfig.bucketOwner, rateLimitConfig.account));
491 }

Callers

nothing calls this directly

Calls 7

requestNeedsRateCheckFunction · 0.85
getCachedRateLimitConfigFunction · 0.85
errorMethod · 0.80
addDefaultFieldsMethod · 0.80

Tested by

no test coverage detected