Skip to content

Commit decfc8f

Browse files
Unify implicit deny handling in normal and backbeat routes
- Also split backbeat routers - Better use the callback functions - Do not return twice to the client in case of error and quota evaluation (finalizer hooks) - Remove account quota from backbeat proxy route: as not used in this case. Issue: CLDSRV-591
1 parent c0bb428 commit decfc8f

File tree

3 files changed

+184
-199
lines changed

3 files changed

+184
-199
lines changed

lib/api/api.js

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,26 @@ function checkAuthResults(authResults, apiMethod, log) {
119119
}
120120

121121
/* eslint-disable no-param-reassign */
122+
function handleAuthorizationResults(request, authorizationResults, apiMethod, returnTagCount, log, callback) {
123+
if (authorizationResults) {
124+
const checkedResults = checkAuthResults(authorizationResults, apiMethod, log);
125+
if (checkedResults instanceof Error) {
126+
return callback(checkedResults);
127+
}
128+
returnTagCount = checkedResults.returnTagCount;
129+
request.actionImplicitDenies = checkedResults.isImplicitDeny;
130+
} else {
131+
// create an object of keys apiMethods with all values to false:
132+
// for backward compatibility, all apiMethods are allowed by default
133+
// thus it is explicitly allowed, so implicit deny is false
134+
request.actionImplicitDenies = request.apiMethods.reduce((acc, curr) => {
135+
acc[curr] = false;
136+
return acc;
137+
}, {});
138+
}
139+
return callback();
140+
}
141+
122142
const api = {
123143
callApiMethod(apiMethod, request, response, log, callback) {
124144
// Attach the apiMethod method to the request, so it can used by monitoring in the server
@@ -148,7 +168,7 @@ const api = {
148168
objectKey: request.objectKey,
149169
});
150170
}
151-
let returnTagCount = true;
171+
const returnTagCount = true;
152172

153173
const validationRes = validateQueryAndHeaders(request, log);
154174
if (validationRes.error) {
@@ -263,27 +283,18 @@ const api = {
263283
return next(null, userInfo, authResultsWithTags, streamingV4Params, infos);
264284
},
265285
),
286+
(userInfo, authorizationResults, streamingV4Params, infos, next) =>
287+
handleAuthorizationResults(request, authorizationResults, apiMethod, returnTagCount, log, err => {
288+
if (err) {
289+
return next(err);
290+
}
291+
return next(null, userInfo, authorizationResults, streamingV4Params, infos);
292+
}),
266293
], (err, userInfo, authorizationResults, streamingV4Params, infos) => {
267294
if (err) {
268295
return callback(err);
269296
}
270297
request.accountQuotas = infos?.accountQuota;
271-
if (authorizationResults) {
272-
const checkedResults = checkAuthResults(authorizationResults, apiMethod, log);
273-
if (checkedResults instanceof Error) {
274-
return callback(checkedResults);
275-
}
276-
returnTagCount = checkedResults.returnTagCount;
277-
request.actionImplicitDenies = checkedResults.isImplicitDeny;
278-
} else {
279-
// create an object of keys apiMethods with all values to false:
280-
// for backward compatibility, all apiMethods are allowed by default
281-
// thus it is explicitly allowed, so implicit deny is false
282-
request.actionImplicitDenies = apiMethods.reduce((acc, curr) => {
283-
acc[curr] = false;
284-
return acc;
285-
}, {});
286-
}
287298
const methodCallback = (err, ...results) => async.forEachLimit(request.finalizerHooks, 5,
288299
(hook, done) => hook(err, done),
289300
() => callback(err, ...results));
@@ -369,6 +380,7 @@ const api = {
369380
websiteGet: website,
370381
websiteHead: website,
371382
checkAuthResults,
383+
handleAuthorizationResults,
372384
};
373385

374386
module.exports = api;

0 commit comments

Comments
 (0)