Skip to content

Commit

Permalink
Merge pull request #2778 from uselagoon/opendistro_cleanup
Browse files Browse the repository at this point in the history
Fix some of the residual OpenDistro Group/Tenant issues
  • Loading branch information
Schnitzel authored Jul 21, 2021
2 parents e4ab92e + d7eeb3e commit 2a5c9ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions services/api/src/resources/group/opendistroSecurity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const OpendistroSecurityOperations = (
try {
// Create a new Tenant for this Group
await opendistroSecurityClient.put(`tenants/${tenantName}`, { body: { description: `${tenantName}` } });
logger.debug(`${groupName}: Created Tentant "${tenantName}"`);
logger.debug(`${groupName}: Created Tenant "${tenantName}"`);
} catch (err) {
logger.error(`Opendistro-Security create tenant error: ${err}`);
}
Expand Down Expand Up @@ -199,7 +199,7 @@ export const OpendistroSecurityOperations = (
// Delete the Tenant for this Group
await opendistroSecurityClient.delete(`tenants/${tenantName}`);
logger.debug(
`${tenantName}: Deleted Opendistro-Security Tentant "${tenantName}"`
`${tenantName}: Deleted Opendistro-Security Tenant "${tenantName}"`
);
} catch (err) {
// 404 Errors are expected and mean that the role does not exist
Expand All @@ -215,6 +215,9 @@ export const OpendistroSecurityOperations = (
}
},
deleteGroup: async function(groupName) {
await this.deleteGroupWithSpecificTenant(groupName, groupName);
},
deleteGroupWithSpecificTenant: async function(groupName, tenantName) {
// delete groups that have no Projects assigned to them
try {
await opendistroSecurityClient.delete(`roles/${groupName}`);
Expand All @@ -234,6 +237,6 @@ export const OpendistroSecurityOperations = (
}
}

await this.deleteTenant(groupName);
await this.deleteTenant(tenantName);
}
});
5 changes: 3 additions & 2 deletions services/api/src/resources/project/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ export const addProject = async (
OpendistroSecurityOperations(sqlClientPool, models.GroupModel).syncGroupWithSpecificTenant(
`p${project.id}`,
`project-${project.name}`,
project.id
`${project.id}`
);

// Find or create a user that has the public key linked to them
Expand Down Expand Up @@ -451,7 +451,8 @@ export const deleteProject: ResolverFn = async (
`project-${project.name}`
);
await models.GroupModel.deleteGroup(group.id);
OpendistroSecurityOperations(sqlClientPool, models.GroupModel).deleteGroup(
OpendistroSecurityOperations(sqlClientPool, models.GroupModel).deleteGroupWithSpecificTenant(
`p${pid}`,
group.name
);
} catch (err) {
Expand Down

0 comments on commit 2a5c9ba

Please sign in to comment.