Merge pull request #8097 from ycombinator/fwd-port-8043
Adding system API module
This commit is contained in:
commit
9bff06769f
6 changed files with 106 additions and 0 deletions
|
@ -3,6 +3,7 @@ import ingest from './server/routes/api/ingest';
|
|||
import search from './server/routes/api/search';
|
||||
import settings from './server/routes/api/settings';
|
||||
import scripts from './server/routes/api/scripts';
|
||||
import * as systemApi from './server/lib/system_api';
|
||||
|
||||
module.exports = function (kibana) {
|
||||
const kbnBaseUrl = '/app/kibana';
|
||||
|
@ -92,6 +93,8 @@ module.exports = function (kibana) {
|
|||
search(server);
|
||||
settings(server);
|
||||
scripts(server);
|
||||
|
||||
server.expose('systemApi', systemApi);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
22
src/core_plugins/kibana/server/lib/__tests__/system_api.js
Normal file
22
src/core_plugins/kibana/server/lib/__tests__/system_api.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
import expect from 'expect.js';
|
||||
import { isSystemApiRequest } from '../system_api';
|
||||
|
||||
describe('system_api', () => {
|
||||
describe('#isSystemApiRequest', () => {
|
||||
it ('returns true for a system API HTTP request', () => {
|
||||
const mockHapiRequest = {
|
||||
headers: {
|
||||
'kbn-system-api': true
|
||||
}
|
||||
};
|
||||
expect(isSystemApiRequest(mockHapiRequest)).to.be(true);
|
||||
});
|
||||
|
||||
it ('returns false for a non-system API HTTP request', () => {
|
||||
const mockHapiRequest = {
|
||||
headers: {}
|
||||
};
|
||||
expect(isSystemApiRequest(mockHapiRequest)).to.be(false);
|
||||
});
|
||||
});
|
||||
});
|
11
src/core_plugins/kibana/server/lib/system_api.js
Normal file
11
src/core_plugins/kibana/server/lib/system_api.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
const SYSTEM_API_HEADER_NAME = 'kbn-system-api';
|
||||
|
||||
/**
|
||||
* Checks on the *server-side*, if an HTTP request is a system API request
|
||||
*
|
||||
* @param request HAPI request object
|
||||
* @return true if request is a system API request; false, otherwise
|
||||
*/
|
||||
export function isSystemApiRequest(request) {
|
||||
return !!request.headers[SYSTEM_API_HEADER_NAME];
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
import $ from 'jquery';
|
||||
import { remove } from 'lodash';
|
||||
|
||||
import './kbn_chrome.less';
|
||||
import UiModules from 'ui/modules';
|
||||
import { isSystemApiRequest } from 'ui/system_api';
|
||||
|
||||
export default function (chrome, internals) {
|
||||
|
||||
|
@ -41,6 +43,10 @@ export default function (chrome, internals) {
|
|||
$rootScope.$on('$routeUpdate', onRouteChange);
|
||||
onRouteChange();
|
||||
|
||||
const allPendingHttpRequests = () => $http.pendingRequests;
|
||||
const removeSystemApiRequests = (pendingHttpRequests = []) => remove(pendingHttpRequests, isSystemApiRequest);
|
||||
$scope.$watchCollection(allPendingHttpRequests, removeSystemApiRequests);
|
||||
|
||||
// and some local values
|
||||
chrome.httpActive = $http.pendingRequests;
|
||||
$scope.notifList = require('ui/notify')._notifs;
|
||||
|
|
38
src/ui/public/system_api/__tests__/system_api.js
Normal file
38
src/ui/public/system_api/__tests__/system_api.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
import expect from 'expect.js';
|
||||
import ngMock from 'ng_mock';
|
||||
import { addSystemApiHeader, isSystemApiRequest } from '../system_api';
|
||||
|
||||
describe('system_api', () => {
|
||||
describe('#addSystemApiHeader', () => {
|
||||
it ('adds the correct system API header', () => {
|
||||
const headers = {
|
||||
'kbn-version': '4.6.0'
|
||||
};
|
||||
const newHeaders = addSystemApiHeader(headers);
|
||||
|
||||
expect(newHeaders).to.have.property('kbn-system-api');
|
||||
expect(newHeaders['kbn-system-api']).to.be(true);
|
||||
|
||||
expect(newHeaders).to.have.property('kbn-version');
|
||||
expect(newHeaders['kbn-version']).to.be('4.6.0');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isSystemApiRequest', () => {
|
||||
it ('returns true for a system API HTTP request', () => {
|
||||
const mockRequest = {
|
||||
headers: {
|
||||
'kbn-system-api': true
|
||||
}
|
||||
};
|
||||
expect(isSystemApiRequest(mockRequest)).to.be(true);
|
||||
});
|
||||
|
||||
it ('returns false for a non-system API HTTP request', () => {
|
||||
const mockRequest = {
|
||||
headers: {}
|
||||
};
|
||||
expect(isSystemApiRequest(mockRequest)).to.be(false);
|
||||
});
|
||||
});
|
||||
});
|
26
src/ui/public/system_api/system_api.js
Normal file
26
src/ui/public/system_api/system_api.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
const SYSTEM_API_HEADER_NAME = 'kbn-system-api';
|
||||
|
||||
/**
|
||||
* Adds a custom header designating request as system API
|
||||
* @param originalHeaders Object representing set of headers
|
||||
* @return Object representing set of headers, with system API header added in
|
||||
*/
|
||||
export function addSystemApiHeader(originalHeaders) {
|
||||
const systemApiHeaders = {
|
||||
[SYSTEM_API_HEADER_NAME]: true
|
||||
};
|
||||
return {
|
||||
...originalHeaders,
|
||||
...systemApiHeaders
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if request is a system API request; false otherwise
|
||||
*
|
||||
* @param request Object Request object created by $http service
|
||||
* @return true if request is a system API request; false otherwise
|
||||
*/
|
||||
export function isSystemApiRequest(request) {
|
||||
return !!request.headers[SYSTEM_API_HEADER_NAME];
|
||||
}
|
Loading…
Reference in a new issue