Skip to content

Commit

Permalink
Uses asCurrentUser in getClusterUuid (#82908)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
TinaHeiligers and kibanamachine authored Nov 9, 2020
1 parent e1b7073 commit fdb9d76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/plugins/usage_collection/server/routes/stats/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ export function registerStatsRoute({
return collectorSet.toObject(usage);
};

const getClusterUuid = async (callCluster: LegacyAPICaller): Promise<string> => {
const { cluster_uuid: uuid } = await callCluster('info', { filterPath: 'cluster_uuid' });
const getClusterUuid = async (asCurrentUser: ElasticsearchClient): Promise<string> => {
const { body } = await asCurrentUser.info({ filter_path: 'cluster_uuid' });
const { cluster_uuid: uuid } = body;
return uuid;
};

Expand Down Expand Up @@ -103,7 +104,7 @@ export function registerStatsRoute({
let extended;
if (isExtended) {
const callCluster = context.core.elasticsearch.legacy.client.callAsCurrentUser;
const esClient = context.core.elasticsearch.client.asCurrentUser;
const { asCurrentUser } = context.core.elasticsearch.client;
const savedObjectsClient = context.core.savedObjects.client;

if (shouldGetUsage) {
Expand All @@ -114,9 +115,12 @@ export function registerStatsRoute({
}

const usagePromise = shouldGetUsage
? getUsage(callCluster, esClient, savedObjectsClient)
? getUsage(callCluster, asCurrentUser, savedObjectsClient)
: Promise.resolve({});
const [usage, clusterUuid] = await Promise.all([usagePromise, getClusterUuid(callCluster)]);
const [usage, clusterUuid] = await Promise.all([
usagePromise,
getClusterUuid(asCurrentUser),
]);

let modifiedUsage = usage;
if (isLegacy) {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/api_integration/apis/kibana/stats/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function ({ getService }) {
});

it('should return 401 for extended', async () => {
await supertestNoAuth.get('/api/stats?extended').expect(401);
await supertestNoAuth.get('/api/stats?extended').auth(null, null).expect(401);
});
});

Expand Down

0 comments on commit fdb9d76

Please sign in to comment.