@@ -119,6 +119,26 @@ function checkAuthResults(authResults, apiMethod, log) {
119
119
}
120
120
121
121
/* 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
+
122
142
const api = {
123
143
callApiMethod ( apiMethod , request , response , log , callback ) {
124
144
// Attach the apiMethod method to the request, so it can used by monitoring in the server
@@ -148,7 +168,7 @@ const api = {
148
168
objectKey : request . objectKey ,
149
169
} ) ;
150
170
}
151
- let returnTagCount = true ;
171
+ const returnTagCount = true ;
152
172
153
173
const validationRes = validateQueryAndHeaders ( request , log ) ;
154
174
if ( validationRes . error ) {
@@ -263,27 +283,18 @@ const api = {
263
283
return next ( null , userInfo , authResultsWithTags , streamingV4Params , infos ) ;
264
284
} ,
265
285
) ,
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
+ } ) ,
266
293
] , ( err , userInfo , authorizationResults , streamingV4Params , infos ) => {
267
294
if ( err ) {
268
295
return callback ( err ) ;
269
296
}
270
297
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
- }
287
298
const methodCallback = ( err , ...results ) => async . forEachLimit ( request . finalizerHooks , 5 ,
288
299
( hook , done ) => hook ( err , done ) ,
289
300
( ) => callback ( err , ...results ) ) ;
@@ -369,6 +380,7 @@ const api = {
369
380
websiteGet : website ,
370
381
websiteHead : website ,
371
382
checkAuthResults,
383
+ handleAuthorizationResults,
372
384
} ;
373
385
374
386
module . exports = api ;
0 commit comments