Skip to content

Commit dacc22d

Browse files
committed
Use shared middleware to enforce master key on hooks API.
1 parent 92e51ab commit dacc22d

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/Routers/HooksRouter.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import { Parse } from 'parse/node';
22
import PromiseRouter from '../PromiseRouter';
33
import { HooksController } from '../Controllers/HooksController';
4-
5-
function enforceMasterKeyAccess(req) {
6-
if (!req.auth.isMaster) {
7-
throw new Parse.Error(403, "unauthorized: master key is required");
8-
}
9-
}
4+
import * as middleware from "../middlewares";
105

116
export class HooksRouter extends PromiseRouter {
12-
137
createHook(aHook, config) {
148
return config.hooksController.createHook(aHook).then( (hook) => ({response: hook}));
159
};
@@ -93,14 +87,14 @@ export class HooksRouter extends PromiseRouter {
9387
}
9488

9589
mountRoutes() {
96-
this.route('GET', '/hooks/functions', enforceMasterKeyAccess, this.handleGetFunctions.bind(this));
97-
this.route('GET', '/hooks/triggers', enforceMasterKeyAccess, this.handleGetTriggers.bind(this));
98-
this.route('GET', '/hooks/functions/:functionName', enforceMasterKeyAccess, this.handleGetFunctions.bind(this));
99-
this.route('GET', '/hooks/triggers/:className/:triggerName', enforceMasterKeyAccess, this.handleGetTriggers.bind(this));
100-
this.route('POST', '/hooks/functions', enforceMasterKeyAccess, this.handlePost.bind(this));
101-
this.route('POST', '/hooks/triggers', enforceMasterKeyAccess, this.handlePost.bind(this));
102-
this.route('PUT', '/hooks/functions/:functionName', enforceMasterKeyAccess, this.handlePut.bind(this));
103-
this.route('PUT', '/hooks/triggers/:className/:triggerName', enforceMasterKeyAccess, this.handlePut.bind(this));
90+
this.route('GET', '/hooks/functions', middleware.promiseEnforceMasterKeyAccess, this.handleGetFunctions.bind(this));
91+
this.route('GET', '/hooks/triggers', middleware.promiseEnforceMasterKeyAccess, this.handleGetTriggers.bind(this));
92+
this.route('GET', '/hooks/functions/:functionName', middleware.promiseEnforceMasterKeyAccess, this.handleGetFunctions.bind(this));
93+
this.route('GET', '/hooks/triggers/:className/:triggerName', middleware.promiseEnforceMasterKeyAccess, this.handleGetTriggers.bind(this));
94+
this.route('POST', '/hooks/functions', middleware.promiseEnforceMasterKeyAccess, this.handlePost.bind(this));
95+
this.route('POST', '/hooks/triggers', middleware.promiseEnforceMasterKeyAccess, this.handlePost.bind(this));
96+
this.route('PUT', '/hooks/functions/:functionName', middleware.promiseEnforceMasterKeyAccess, this.handlePut.bind(this));
97+
this.route('PUT', '/hooks/triggers/:className/:triggerName', middleware.promiseEnforceMasterKeyAccess, this.handlePut.bind(this));
10498
}
10599
}
106100

0 commit comments

Comments
 (0)