Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rbac): fix the error handling for the RBAC file watcher #2

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 53 additions & 27 deletions plugins/rbac-backend/src/file-permissions/csv-file-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,13 @@ export class CSVFileWatcher {
this.logger.warn(err.message);
continue;
}
await this.enforcer.addOrUpdatePolicy(policy, 'csv-file', true);
try {
await this.enforcer.addOrUpdatePolicy(policy, 'csv-file', true);
} catch (e) {
this.logger.warn(
`Failed to add or update policy ${policy} after modification ${this.csvFileName}. Cause: ${e}`,
);
}
}

this.csvFilePolicies.addedPolicies = [];
Expand All @@ -289,11 +295,19 @@ export class CSVFileWatcher {
* removePermissionPolicies will remove the permission policies that are no longer present in the CSV file.
*/
async removePermissionPolicies(): Promise<void> {
await this.enforcer.removePolicies(
this.csvFilePolicies.removedPolicies,
'csv-file',
true,
);
try {
await this.enforcer.removePolicies(
this.csvFilePolicies.removedPolicies,
'csv-file',
true,
);
} catch (e) {
this.logger.warn(
`Failed to remove policies ${JSON.stringify(
this.csvFilePolicies.removedPolicies,
)} after modification ${this.csvFileName}. Cause: ${e}`,
);
}
this.csvFilePolicies.removedPolicies = [];
}

Expand Down Expand Up @@ -326,16 +340,22 @@ export class CSVFileWatcher {
continue;
}

await this.enforcer.addOrUpdateGroupingPolicy(
groupPolicy,
{
source: 'csv-file',
roleEntityRef: groupPolicy[1],
author: CSV_PERMISSION_POLICY_FILE_AUTHOR,
modifiedBy: CSV_PERMISSION_POLICY_FILE_AUTHOR,
},
true,
);
try {
await this.enforcer.addOrUpdateGroupingPolicy(
groupPolicy,
{
source: 'csv-file',
roleEntityRef: groupPolicy[1],
author: CSV_PERMISSION_POLICY_FILE_AUTHOR,
modifiedBy: CSV_PERMISSION_POLICY_FILE_AUTHOR,
},
true,
);
} catch (e) {
this.logger.warn(
`Failed to add or update group policy ${groupPolicy} after modification ${this.csvFileName}. Cause: ${e}`,
);
}
}
this.csvFilePolicies.addedGroupPolicies = [];
}
Expand All @@ -354,17 +374,23 @@ export class CSVFileWatcher {
);

// Need to update the time
await this.enforcer.removeGroupingPolicy(
groupPolicy,
{
source: 'csv-file',
roleEntityRef: groupPolicy[1],
author: CSV_PERMISSION_POLICY_FILE_AUTHOR,
modifiedBy: CSV_PERMISSION_POLICY_FILE_AUTHOR,
},
isUpdate.length > 1,
true,
);
try {
await this.enforcer.removeGroupingPolicy(
groupPolicy,
{
source: 'csv-file',
roleEntityRef: groupPolicy[1],
author: CSV_PERMISSION_POLICY_FILE_AUTHOR,
modifiedBy: CSV_PERMISSION_POLICY_FILE_AUTHOR,
},
isUpdate.length > 1,
true,
);
} catch (e) {
this.logger.warn(
`Failed to remove group policy ${groupPolicy} after modification ${this.csvFileName}. Cause: ${e}`,
);
}
}
this.csvFilePolicies.removedGroupPolicies = [];
}
Expand Down