mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
* refactoring license management server routes * addressing PR feedback
This commit is contained in:
parent
9b9aaba6d8
commit
09c58758d0
5 changed files with 19 additions and 62 deletions
|
@ -7,6 +7,8 @@
|
|||
import { resolve } from 'path';
|
||||
import { PLUGIN } from './common/constants';
|
||||
import { registerLicenseRoute, registerStartTrialRoutes, registerStartBasicRoute } from "./server/routes/api/license/";
|
||||
import { createRouter } from '../../server/lib/create_router';
|
||||
import { registerLicenseChecker } from '../../server/lib/register_license_checker';
|
||||
|
||||
export function licenseManagement(kibana) {
|
||||
return new kibana.Plugin({
|
||||
|
@ -21,9 +23,12 @@ export function licenseManagement(kibana) {
|
|||
]
|
||||
},
|
||||
init: (server) => {
|
||||
registerLicenseRoute(server);
|
||||
registerStartTrialRoutes(server);
|
||||
registerStartBasicRoute(server);
|
||||
registerLicenseChecker(server, PLUGIN.ID);
|
||||
const xpackInfo = server.plugins.xpack_main.info;
|
||||
const router = createRouter(server, PLUGIN.ID, '/api/license');
|
||||
registerLicenseRoute(router, xpackInfo);
|
||||
registerStartTrialRoutes(router, xpackInfo);
|
||||
registerStartBasicRoute(router, xpackInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import Boom from 'boom';
|
||||
|
||||
/**
|
||||
* Wraps ES errors into a Boom error response and returns it
|
||||
* This also handles the permissions issue gracefully
|
||||
*
|
||||
* @param err Object ES error
|
||||
* @return Object Boom error response
|
||||
*/
|
||||
export function wrapEsError(err) {
|
||||
const statusCode = err.statusCode;
|
||||
if (statusCode === 403) {
|
||||
throw Boom.forbidden('Insufficient user permissions for adding a license.');
|
||||
}
|
||||
throw Boom.boomify(err, err.statusCode);
|
||||
}
|
|
@ -5,16 +5,9 @@
|
|||
*/
|
||||
|
||||
import { putLicense } from '../../../lib/license';
|
||||
import { wrapEsError } from '../../../lib/wrap_es_error';
|
||||
|
||||
export function registerLicenseRoute(server) {
|
||||
const xpackInfo = server.plugins.xpack_main.info;
|
||||
server.route({
|
||||
path: '/api/license',
|
||||
method: 'PUT',
|
||||
handler: (request) => {
|
||||
return putLicense(request, xpackInfo)
|
||||
.catch(e => wrapEsError(e));
|
||||
}
|
||||
export function registerLicenseRoute(router, xpackInfo) {
|
||||
router.put('', (request) => {
|
||||
return putLicense(request, xpackInfo);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5,16 +5,9 @@
|
|||
*/
|
||||
|
||||
import { startBasic } from '../../../lib/start_basic';
|
||||
import { wrapEsError } from '../../../lib/wrap_es_error';
|
||||
|
||||
export function registerStartBasicRoute(server) {
|
||||
const xpackInfo = server.plugins.xpack_main.info;
|
||||
server.route({
|
||||
path: '/api/license/start_basic',
|
||||
method: 'POST',
|
||||
handler: (request) => {
|
||||
return startBasic(request, xpackInfo)
|
||||
.catch(e => wrapEsError(e));
|
||||
}
|
||||
export function registerStartBasicRoute(router, xpackInfo) {
|
||||
router.post('/start_basic', (request) => {
|
||||
return startBasic(request, xpackInfo);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5,24 +5,12 @@
|
|||
*/
|
||||
|
||||
import { canStartTrial, startTrial } from '../../../lib/start_trial';
|
||||
import { wrapEsError } from '../../../lib/wrap_es_error';
|
||||
|
||||
export function registerStartTrialRoutes(server) {
|
||||
const xpackInfo = server.plugins.xpack_main.info;
|
||||
server.route({
|
||||
path: '/api/license/start_trial',
|
||||
method: 'GET',
|
||||
handler: (request) => {
|
||||
return canStartTrial(request)
|
||||
.catch(e => wrapEsError(e));
|
||||
}
|
||||
export function registerStartTrialRoutes(router, xpackInfo) {
|
||||
router.get('/start_trial', (request) => {
|
||||
return canStartTrial(request);
|
||||
});
|
||||
server.route({
|
||||
path: '/api/license/start_trial',
|
||||
method: 'POST',
|
||||
handler: (request) => {
|
||||
return startTrial(request, xpackInfo)
|
||||
.catch(e => wrapEsError(e));
|
||||
}
|
||||
router.post('/start_trial', (request) => {
|
||||
return startTrial(request, xpackInfo);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue