Skip to content

Commit 27a623c

Browse files
committed
Uses asCurrentUser in getClusterUuid
1 parent b08677b commit 27a623c

File tree

2 files changed

+10
-6
lines changed
  • src/plugins/usage_collection/server/routes/stats
  • x-pack/test/api_integration/apis/kibana/stats

2 files changed

+10
-6
lines changed

src/plugins/usage_collection/server/routes/stats/stats.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ export function registerStatsRoute({
7373
return collectorSet.toObject(usage);
7474
};
7575

76-
const getClusterUuid = async (callCluster: LegacyAPICaller): Promise<string> => {
77-
const { cluster_uuid: uuid } = await callCluster('info', { filterPath: 'cluster_uuid' });
76+
const getClusterUuid = async (asCurrentUser: ElasticsearchClient): Promise<string> => {
77+
const { body } = await asCurrentUser.info({ filter_path: 'cluster_uuid' });
78+
const { cluster_uuid: uuid } = body;
7879
return uuid;
7980
};
8081

@@ -103,7 +104,7 @@ export function registerStatsRoute({
103104
let extended;
104105
if (isExtended) {
105106
const callCluster = context.core.elasticsearch.legacy.client.callAsCurrentUser;
106-
const esClient = context.core.elasticsearch.client.asCurrentUser;
107+
const { asCurrentUser } = context.core.elasticsearch.client;
107108
const savedObjectsClient = context.core.savedObjects.client;
108109

109110
if (shouldGetUsage) {
@@ -114,9 +115,12 @@ export function registerStatsRoute({
114115
}
115116

116117
const usagePromise = shouldGetUsage
117-
? getUsage(callCluster, esClient, savedObjectsClient)
118+
? getUsage(callCluster, asCurrentUser, savedObjectsClient)
118119
: Promise.resolve({});
119-
const [usage, clusterUuid] = await Promise.all([usagePromise, getClusterUuid(callCluster)]);
120+
const [usage, clusterUuid] = await Promise.all([
121+
usagePromise,
122+
getClusterUuid(asCurrentUser),
123+
]);
120124

121125
let modifiedUsage = usage;
122126
if (isLegacy) {

x-pack/test/api_integration/apis/kibana/stats/stats.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function ({ getService }) {
3030
});
3131

3232
it('should return 401 for extended', async () => {
33-
await supertestNoAuth.get('/api/stats?extended').expect(401);
33+
await supertestNoAuth.get('/api/stats?extended').auth(null, null).expect(401);
3434
});
3535
});
3636

0 commit comments

Comments
 (0)