Skip to content

Commit

Permalink
Adds settings endpoint to configure loglevel
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Apr 7, 2016
1 parent bc96f0b commit bf97abb
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 3 deletions.
57 changes: 57 additions & 0 deletions spec/SettingsRouter.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
var request = require('request');

var headers = {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'test'
};


describe('SettingsRouter', () => {

it('should set the loglevel', (done) => {
request.post({
headers: headers,
json: {
'logLevel': 'silly'
},
url: 'http://localhost:8378/1/settings'
}, (err, res, body) => {
request.get({
url: 'http://localhost:8378/1/settings',
headers: headers
}, (err, res, body)=> {
body = JSON.parse(body);
expect(body.logLevel).toBe('silly');
done();
});
});
});

it('should not access without masterKey', (done) => {
request.post({
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'invalid'
},
json: {
'logLevel': 'silly'
},
url: 'http://localhost:8378/1/settings'
}, (err, res, body) => {
expect(body.error).not.toBeUndefined();
expect(body.error).toBe('unauthorized');
request.get({
url: 'http://localhost:8378/1/settings',
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-Master-Key': 'invalid'
}
}, (err, res, body)=> {
body = JSON.parse(body);
expect(body.error).toBe('unauthorized');
done();
});
});
})

})
2 changes: 2 additions & 0 deletions src/ParseServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { SchemasRouter } from './Routers/SchemasRouter';
import { SessionsRouter } from './Routers/SessionsRouter';
import { UserController } from './Controllers/UserController';
import { UsersRouter } from './Routers/UsersRouter';
import { SettingsRouter } from './Routers/SettingsRouter';

import ParsePushAdapter from 'parse-server-push-adapter';
// Mutate the Parse object to add the Cloud Code handlers
Expand Down Expand Up @@ -246,6 +247,7 @@ class ParseServer {
new IAPValidationRouter(),
new FeaturesRouter(),
new GlobalConfigRouter(),
new SettingsRouter(),
];

if (process.env.PARSE_EXPERIMENTAL_HOOKS_ENABLED || process.env.TESTING) {
Expand Down
8 changes: 5 additions & 3 deletions src/Routers/LogsRouter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Parse } from 'parse/node';
import PromiseRouter from '../PromiseRouter';
import * as middleware from "../middlewares";
import winston from 'winston';
import { logger, configureLogger } from '../logger';

export class LogsRouter extends PromiseRouter {

mountRoutes() {
this.route('GET','/scriptlog', middleware.promiseEnforceMasterKeyAccess, this.validateRequest, (req) => {
return this.handleGET(req);
Expand All @@ -30,9 +32,9 @@ export class LogsRouter extends PromiseRouter {
const until = req.query.until;
let size = req.query.size;
if (req.query.n) {
size = req.query.n;
size = req.query.n;
}

const order = req.query.order
const level = req.query.level;
const options = {
Expand Down
26 changes: 26 additions & 0 deletions src/Routers/SettingsRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import PromiseRouter from '../PromiseRouter';
import * as middleware from "../middlewares";
import { logger, configureLogger } from '../logger';
import winston from 'winston';

export class SettingsRouter extends PromiseRouter {
mountRoutes() {
this.route('GET', '/settings', middleware.promiseEnforceMasterKeyAccess, (req) => {
return Promise.resolve({
response: {
logLevel: winston.level
}
})
});
this.route('POST','/settings', middleware.promiseEnforceMasterKeyAccess, (req) => {
let body = req.body;
let logLevel = body.logLevel;
if (logLevel) {
configureLogger({level: logLevel});
}
return Promise.resolve({
response: body
})
});
}
}

0 comments on commit bf97abb

Please sign in to comment.