Uses asCurrentUser in getClusterUuid (#82908)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Christiane (Tina) Heiligers 2020-11-09 10:31:21 -07:00 committed by GitHub
parent e1b7073a64
commit fdb9d76fbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View file

@ -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;
};
@ -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) {
@ -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) {

View file

@ -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);
});
});