Fix upgrade assistant warning for optional roles and roleTemplate properties (#179818)

Closes https://github.com/elastic/kibana/issues/177065

## Summary
Upgrade assistant in cloud shows a warning when trying to upgrade due to
mutually exclusive `roles` and `roleTemplates` property in the `Get Role
Mappings` API from ES. This PR fixes that by introducing conditional
checks for where we check for the `roles` property.


## Release notes
Fix warning displayed in Upgrade Assistant regarding `roles` and
`roleTemplate` properties when checking response from Get Role Mappings
API.

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Kurt <kc13greiner@users.noreply.github.com>
This commit is contained in:
Sid 2024-04-06 18:20:25 +02:00 committed by GitHub
parent f04153ba2c
commit 597ab88d9e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 3 deletions

View file

@ -211,7 +211,7 @@ async function getRoleMappingsDeprecations(
const roleMappingsWithReportingRole: string[] = Object.entries(roleMappings).reduce(
(roleSet, current) => {
const [roleName, role] = current;
const foundMapping = role.roles.find((roll) => deprecatedRoles.includes(roll));
const foundMapping = role.roles?.find((roll) => deprecatedRoles.includes(roll));
if (foundMapping) {
roleSet.push(`${roleName}[${foundMapping}]`);
}

View file

@ -156,7 +156,7 @@ async function getRoleMappingsDeprecations(
}
const roleMappingsWithKibanaUserRole = Object.entries(roleMappings)
.filter(([, roleMapping]) => roleMapping.roles.includes(KIBANA_USER_ROLE_NAME))
.filter(([, roleMapping]) => roleMapping.roles?.includes(KIBANA_USER_ROLE_NAME))
.map(([mappingName]) => mappingName);
if (roleMappingsWithKibanaUserRole.length === 0) {
return [];

View file

@ -100,7 +100,7 @@ export function defineKibanaUserRoleDeprecationRoutes({ router, logger }: RouteD
}
const roleMappingsWithKibanaUserRole = Object.entries(roleMappings).filter(([, mapping]) =>
mapping.roles.includes(KIBANA_USER_ROLE_NAME)
mapping.roles?.includes(KIBANA_USER_ROLE_NAME)
);
if (roleMappingsWithKibanaUserRole.length === 0) {