Skip to content

Commit

Permalink
Reinstate version check for privileges route.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal committed Oct 12, 2021
1 parent ebafe06 commit dbc7a8e
Showing 1 changed file with 41 additions and 38 deletions.
79 changes: 41 additions & 38 deletions x-pack/plugins/upgrade_assistant/server/routes/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { API_BASE_PATH, DEPRECATION_LOGS_INDEX } from '../../common/constants';
import { versionCheckHandlerWrapper } from '../lib/es_version_precheck';
import { Privileges } from '../shared_imports';
import { RouteDependencies } from '../types';

Expand All @@ -29,49 +30,51 @@ export function registerAppRoutes({
path: `${API_BASE_PATH}/privileges`,
validate: false,
},
async (
{
core: {
elasticsearch: { client },
},
},
request,
response
) => {
const privilegesResult: Privileges = {
hasAllPrivileges: true,
missingPrivileges: {
index: [],
versionCheckHandlerWrapper(
async (
{
core: {
elasticsearch: { client },
},
},
};

if (!isSecurityEnabled()) {
return response.ok({ body: privilegesResult });
}

try {
const {
body: { has_all_requested: hasAllPrivileges, index },
} = await client.asCurrentUser.security.hasPrivileges({
body: {
index: [
{
names: [DEPRECATION_LOGS_INDEX],
privileges: ['read'],
},
],
request,
response
) => {
const privilegesResult: Privileges = {
hasAllPrivileges: true,
missingPrivileges: {
index: [],
},
});
};

if (!hasAllPrivileges) {
privilegesResult.missingPrivileges.index = extractMissingPrivileges(index);
if (!isSecurityEnabled()) {
return response.ok({ body: privilegesResult });
}

privilegesResult.hasAllPrivileges = hasAllPrivileges;
return response.ok({ body: privilegesResult });
} catch (error) {
return handleEsError({ error, response });
try {
const {
body: { has_all_requested: hasAllPrivileges, index },
} = await client.asCurrentUser.security.hasPrivileges({
body: {
index: [
{
names: [DEPRECATION_LOGS_INDEX],
privileges: ['read'],
},
],
},
});

if (!hasAllPrivileges) {
privilegesResult.missingPrivileges.index = extractMissingPrivileges(index);
}

privilegesResult.hasAllPrivileges = hasAllPrivileges;
return response.ok({ body: privilegesResult });
} catch (error) {
return handleEsError({ error, response });
}
}
}
)
);
}

0 comments on commit dbc7a8e

Please sign in to comment.