Skip to content

Commit

Permalink
use callWithInternalUser
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Dec 4, 2018
1 parent b7ed480 commit ea35c43
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,8 @@ import { get } from 'lodash';
* Check user privileges for read access to monitoring
* Pass callWithInternalUser to bulkFetchUsage
*/
export async function getKibana(server, callWithInternalUser, callWithReq) {
export async function getKibana(server, callWithInternalUser) {
const { collectorSet } = server.usage;

const hasPrivilegesResponse = await callWithReq('transport.request', {
method: 'POST',
path: '/_xpack/security/user/_has_privileges',
body: {
index: [ { names: [ '.monitoring-*' ], privileges: [ 'read' ] } ]
},
ignoreUnavailable: true // we allow 404 incase the user shutdown security in-between the check and now
});
const { has_all_requested: hasPrivileges } = hasPrivilegesResponse;

if (!hasPrivileges) {
return;
}

const usage = await collectorSet.bulkFetch(callWithInternalUser);
const { kibana, kibana_stats: stats, ...plugins } = collectorSet.toObject(usage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ export function handleLocalStats(clusterInfo, clusterStats, license, xpack, kiba
* @param {function} callCluster The callWithInternalUser handler (exposed for testing)
* @return {Promise} The object containing the current Elasticsearch cluster's telemetry.
*/
export function getLocalStatsWithCaller(server, callCluster, callWithReq) {
export function getLocalStatsWithCaller(server, callCluster) {
return Promise.all([
getClusterInfo(callCluster), // cluster info
getClusterStats(callCluster), // cluster stats (not to be confused with cluster _state_)
getXPack(callCluster), // { license, xpack }
getKibana(server, callCluster, callWithReq)
getKibana(server, callCluster)
]).then(([clusterInfo, clusterStats, { license, xpack }, kibana]) => {
return handleLocalStats(clusterInfo, clusterStats, license, xpack, kibana);
}
Expand All @@ -73,7 +73,5 @@ export function getLocalStatsWithCaller(server, callCluster, callWithReq) {
export function getLocalStats(req) {
const { server } = req;
const { callWithInternalUser } = server.plugins.elasticsearch.getCluster('data');
const { callWithRequest } = server.plugins.elasticsearch.getCluster('data');
const callWithReq = (...args) => callWithRequest(req, ...args);
return getLocalStatsWithCaller(server, callWithInternalUser, callWithReq);
return getLocalStatsWithCaller(server, callWithInternalUser);
}

0 comments on commit ea35c43

Please sign in to comment.