Skip to content

Commit

Permalink
updated api.js
Browse files Browse the repository at this point in the history
  • Loading branch information
anurag4DSB committed Jul 4, 2024
1 parent 4e6a2ea commit 368283c
Showing 1 changed file with 47 additions and 47 deletions.
94 changes: 47 additions & 47 deletions lib/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ const api = {
// no need to check auth on website or cors preflight requests
if (apiMethod === 'websiteGet' || apiMethod === 'websiteHead' ||
apiMethod === 'corsPreflight') {
request.actionImplicitDenies = false;
callApiMethod.end();
activeSpan.addEvent(`Forwarding Request to ${apiMethod} Handler`);
// TODO: inject tracing context into the request object
request.actionImplicitDenies = false;
return this[apiMethod](request, log, callback);
}

Expand Down Expand Up @@ -234,33 +233,38 @@ const api = {
'code.lineno': 220,
'rpc.method': 'AuthV4',
});
return next(null, iamAuthSpan, iamAuthSpanContext);
}),
(iamAuthSpan, iamAuthSpanContext, next) => auth.server.doAuth(
request, log, (err, userInfo, authorizationResults, streamingV4Params) => {
activeSpan.addEvent('Received Response from Vault');
if (err) {
activeSpan.recordException(err);
return auth.server.doAuth(
request, log, (err, userInfo, authorizationResults, streamingV4Params) => {
activeSpan.addEvent('Received Response from Vault');
iamAuthSpan.end();
log.trace('authentication error', { error: err });
return next(err);
}
return next(null, userInfo, authorizationResults, streamingV4Params, iamAuthSpan);
}, 's3', requestContexts, { activeSpan, iamAuthSpanContext, tracer }),
(userInfo, authorizationResults, streamingV4Params, iamAuthSpan, next) => {
if (err) {
activeSpan.recordException(err);
log.trace('authentication error', { error: err });
return next(err);
}
return next(null, userInfo, authorizationResults, streamingV4Params);
}, 's3', requestContexts, { activeSpan, activeTracerContext: iamAuthSpanContext, tracer });
}),
(userInfo, authorizationResults, streamingV4Params, next) => tracer.startActiveSpan('Process Vault Response', undefined, cloudserverApiSpanContext, currentSpan => {

Check failure on line 248 in lib/api/api.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Line 248 exceeds the maximum line length of 120
currentSpan.setAttributes({
'code.function': 'callApiMethod()',
'code.filename': 'lib/api/api.js',
'code.lineno': 220,
});
activeSpan.addEvent('Processing Vault Response');
const authNames = { accountName: userInfo.getAccountDisplayName() };
if (userInfo.isRequesterAnIAMUser()) {
authNames.userName = userInfo.getIAMdisplayName();
}
log.addDefaultFields(authNames);
if (apiMethod === 'objectPut' || apiMethod === 'objectPutPart') {
return next(null, userInfo, authorizationResults, streamingV4Params, iamAuthSpan);
currentSpan.end();
return next(null, userInfo, authorizationResults, streamingV4Params);
}
// issue 100 Continue to the client
writeContinue(request, response);
const MAX_POST_LENGTH = request.method === 'POST' ?
1024 * 1024 : 1024 * 1024 / 2; // 1 MB or 512 KB
1024 * 1024 : 1024 * 1024 / 2; // 1 MB or 512 KB
const post = [];
let postLength = 0;
request.on('data', chunk => {
Expand All @@ -273,7 +277,7 @@ const api = {

request.on('error', err => {
activeSpan.recordException(err);
iamAuthSpan.end();
currentSpan.end();
log.trace('error receiving request', {
error: err,
});
Expand All @@ -283,43 +287,39 @@ const api = {
request.on('end', () => {
if (postLength > MAX_POST_LENGTH) {
activeSpan.recordException(errors.InvalidRequest);
iamAuthSpan.end();
currentSpan.end();
log.error('body length is too long for request type',
{ postLength });
{ postLength });
return next(errors.InvalidRequest);
}
// Convert array of post buffers into one string
request.post = Buffer.concat(post, postLength).toString();
return next(null, userInfo, authorizationResults, streamingV4Params, iamAuthSpan);
activeSpan.addEvent('Vault Response Processed');
return next(null, userInfo, authorizationResults, streamingV4Params);
});
return undefined;
},
(userInfo, authorizationResults, streamingV4Params, iamAuthSpan, next) => {
activeSpan.addEvent('Vault Response Processed');
activeSpan.addEvent('Validating Tag Conditions in Authorization');
return next(null, userInfo, authorizationResults, streamingV4Params, iamAuthSpan);
},
}),
// Tag condition keys require information from CloudServer for evaluation
(userInfo, authorizationResults, streamingV4Params, iamAuthSpan, next) => tagConditionKeyAuth(
authorizationResults,
request,
requestContexts,
apiMethod,
log,
(err, authResultsWithTags) => {
if (err) {
activeSpan.recordException(err);
iamAuthSpan.end();
log.trace('tag authentication error', { error: err });
return next(err);
}
return next(null, userInfo, authResultsWithTags, streamingV4Params, iamAuthSpan);
},
),
], (err, userInfo, authorizationResults, streamingV4Params, iamAuthSpan) => {
if (iamAuthSpan) {
iamAuthSpan.end();
}
(userInfo, authorizationResults, streamingV4Params, next) => tracer.startActiveSpan('Validate Tag condition keys for Authorization', undefined, cloudserverApiSpanContext, currentSpan => {

Check failure on line 303 in lib/api/api.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Line 303 exceeds the maximum line length of 120
activeSpan.addEvent('Validating Tag Conditions in Authorization');
return tagConditionKeyAuth(
authorizationResults,
request,
requestContexts,
apiMethod,
log,
(err, authResultsWithTags) => {
currentSpan.end();
if (err) {
activeSpan.recordException(err);
log.trace('tag authentication error', { error: err });
return next(err);
}
return next(null, userInfo, authResultsWithTags, streamingV4Params);
},
);
}),
], (err, userInfo, authorizationResults, streamingV4Params) => {
activeSpan.addEvent('Vault Authentication and Authorization Completed');
if (err) {
activeSpan.recordException(err);
Expand Down

0 comments on commit 368283c

Please sign in to comment.