Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server/indexPatterns] expose indexPatternService getter/factory #13012

Merged
merged 2 commits into from
Jul 31, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/server/index_patterns/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,35 @@ export function indexPatternsMixin(kbnServer, server) {
*/
getIndexPatternsService: {
assign: 'indexPatterns',
method(req, reply) {
const dataCluster = req.server.plugins.elasticsearch.getCluster('data');
const callDataCluster = (...args) => (
dataCluster.callWithRequest(req, ...args)
);

reply(new IndexPatternsService(callDataCluster));
method(request, reply) {
reply(request.getIndexPatternsService());
}
}
};

/**
* Create an instance of the IndexPatternsService
*
* @method server.indexPatternsServiceFactory
* @type {IndexPatternsService}
*/
server.decorate('server', 'indexPatternsServiceFactory', ({ callCluster }) => {
return new IndexPatternsService(callCluster);
});

/**
* Get an instance of the IndexPatternsService configured for use
* the current request
*
* @method request.getIndexPatternsService
* @type {IndexPatternsService}
*/
server.addMemoizedFactoryToRequest('getIndexPatternsService', request => {
const { callWithRequest } = request.server.plugins.elasticsearch.getCluster('data');
const callCluster = (...args) => callWithRequest(request, ...args);
return server.indexPatternsServiceFactory({ callCluster });
});

server.route(createFieldsForWildcardRoute(pre));
server.route(createFieldsForTimePatternRoute(pre));
}