[statusPage] Add config option to disable auth on status page

This commit is contained in:
Lukas Olson 2016-05-02 15:45:36 -07:00
parent 4c59b5e6c3
commit adaf9a0f1e
4 changed files with 62 additions and 8 deletions

View file

@ -121,6 +121,10 @@ module.exports = () => Joi.object({
)
.default(Joi.ref('$dev')),
profile: Joi.boolean().default(false)
}).default(),
statusPage: Joi.object({
disableAuth: Joi.boolean().default(false)
}).default()
}).default();

View file

@ -0,0 +1,42 @@
import expect from 'expect.js';
import wrapAuthConfig from '../wrap_auth_config';
describe('Status wrapAuthConfig', () => {
let options;
beforeEach(() => {
options = {
method: 'GET',
path: '/status',
handler: function (request, reply) {
return reply();
}
};
});
it('should return a function', () => {
expect(wrapAuthConfig()).to.be.a('function');
expect(wrapAuthConfig(true)).to.be.a('function');
expect(wrapAuthConfig(false)).to.be.a('function');
});
it('should not add auth config by default', () => {
const wrapAuth = wrapAuthConfig();
const wrapped = wrapAuth(options);
expect(wrapped).to.not.have.property('config');
});
it('should not add auth config if disableAuth is false', () => {
const wrapAuth = wrapAuthConfig(false);
const wrapped = wrapAuth(options);
expect(wrapped).to.not.have.property('config');
});
it('should add auth config if disableAuth is true', () => {
const wrapAuth = wrapAuthConfig(true);
const wrapped = wrapAuth(options);
expect(wrapped).to.have.property('config');
expect(wrapped.config).to.have.property('auth');
expect(wrapped.config.auth).to.be(false);
});
});

View file

@ -1,6 +1,8 @@
import _ from 'lodash';
import ServerStatus from './server_status';
import wrapAuthConfig from './wrap_auth_config';
import { join } from 'path';
module.exports = function (kbnServer, server, config) {
kbnServer.status = new ServerStatus(kbnServer.server);
@ -9,7 +11,9 @@ module.exports = function (kbnServer, server, config) {
kbnServer.mixin(require('./metrics'));
}
server.route({
const wrapAuth = wrapAuthConfig(config.get('statusPage.disableAuth'));
server.route(wrapAuth({
method: 'GET',
path: '/api/status',
handler: function (request, reply) {
@ -19,9 +23,8 @@ module.exports = function (kbnServer, server, config) {
status: kbnServer.status.toJSON(),
metrics: kbnServer.metrics
});
},
config: {auth: false}
});
}
}));
server.decorate('reply', 'renderStatusPage', function () {
let app = kbnServer.uiExports.getHiddenApp('status_page');
@ -30,12 +33,11 @@ module.exports = function (kbnServer, server, config) {
return resp;
});
server.route({
server.route(wrapAuth({
method: 'GET',
path: '/status',
handler: function (request, reply) {
return reply.renderStatusPage();
},
config: {auth: false}
});
}
}));
};

View file

@ -0,0 +1,6 @@
import {assign, identity} from 'lodash';
export default (disableAuth) => {
if (disableAuth) return options => assign(options, {config: {auth: false}});
return identity;
};