(apiMethod, apiHandler, request, response, log, callback)
| 244 | } |
| 245 | |
| 246 | function 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); |
nothing calls this directly
no test coverage detected