Skip to content

Commit

Permalink
generify util functions (#13)
Browse files Browse the repository at this point in the history
Addresses PR feedback to generalize util params.
  • Loading branch information
yctercero authored Jun 22, 2021
1 parent e6987db commit 437dd59
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1992,8 +1992,13 @@ describe('AlertingAuthorization', () => {
});
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);

await expect(alertAuthorization.getAugmentRuleTypesWithAuthorization(['myApp'])).resolves
.toMatchInlineSnapshot(`
await expect(
alertAuthorization.getAugmentRuleTypesWithAuthorization(
['myApp'],
[ReadOperations.Find, ReadOperations.Get, WriteOperations.Update],
AlertingAuthorizationEntity.Alert
)
).resolves.toMatchInlineSnapshot(`
Object {
"authorizedRuleTypes": Set {
Object {
Expand Down Expand Up @@ -2060,8 +2065,13 @@ describe('AlertingAuthorization', () => {
});
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);

await expect(alertAuthorization.getAugmentRuleTypesWithAuthorization(['myApp'])).resolves
.toMatchInlineSnapshot(`
await expect(
alertAuthorization.getAugmentRuleTypesWithAuthorization(
['myApp'],
[ReadOperations.Find, ReadOperations.Get, WriteOperations.Update],
AlertingAuthorizationEntity.Alert
)
).resolves.toMatchInlineSnapshot(`
Object {
"authorizedRuleTypes": Set {
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,18 @@ export class AlertingAuthorization {
* used by the RAC/Alerts client
*/
public async getAugmentRuleTypesWithAuthorization(
featureIds: string[]
featureIds: string[],
operations: Array<ReadOperations | WriteOperations>,
authorizationEntity: AlertingAuthorizationEntity
): Promise<{
username?: string;
hasAllRequested: boolean;
authorizedRuleTypes: Set<RegistryAlertTypeWithAuth>;
}> {
return this.augmentRuleTypesWithAuthorization(
this.alertTypeRegistry.list(),
[ReadOperations.Find, ReadOperations.Get, WriteOperations.Update],
AlertingAuthorizationEntity.Alert,
operations,
authorizationEntity,
new Set(featureIds)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ export class AlertsClient {
this.auditLogger = auditLogger;
}

public async getAlertsIndex(featureIds: string[]) {
public async getAlertsIndex(
featureIds: string[],
operations: Array<ReadOperations | WriteOperations>
) {
return this.authorization.getAugmentRuleTypesWithAuthorization(
featureIds.length !== 0 ? featureIds : ['apm', 'siem']
featureIds.length !== 0 ? featureIds : ['apm', 'siem'],
operations,
AlertingAuthorizationEntity.Alert
);
}

Expand Down Expand Up @@ -186,7 +191,9 @@ export class AlertsClient {

public async getAuthorizedAlertsIndices(featureIds: string[]): Promise<string[] | undefined> {
const augmentedRuleTypes = await this.authorization.getAugmentRuleTypesWithAuthorization(
featureIds
featureIds,
[ReadOperations.Find, ReadOperations.Get, WriteOperations.Update],
AlertingAuthorizationEntity.Alert
);

const arrayOfAuthorizedRuleTypes = Array.from(augmentedRuleTypes.authorizedRuleTypes);
Expand Down

0 comments on commit 437dd59

Please sign in to comment.