Skip to content

Commit

Permalink
Merge pull request #408 from meriamBenSassi/fix/update-sa-list
Browse files Browse the repository at this point in the history
[FIX] Update in memory SA list
  • Loading branch information
meriamBenSassi authored Mar 8, 2023
2 parents bc7e6e3 + 44a253a commit e014059
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/hooks/services/hooks.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/* eslint-disable max-lines */
import { EventStatus, ServiceAccount, Subscription, SubscriptionEvent } from '@algoan/rest';
import {
EventStatus,
ServiceAccount,
Subscription,
SubscriptionEvent,
EventName as AlgoanRestEventName,
} from '@algoan/rest';
import { Inject, Injectable, Logger, NotFoundException, UnauthorizedException } from '@nestjs/common';
import * as delay from 'delay';
import { isEmpty } from 'lodash';
Expand Down Expand Up @@ -518,7 +524,18 @@ export class HooksService {
* Gets the Service Account given the event
*/
public async getServiceAccount(event: EventDTO): Promise<ServiceAccount> {
const serviceAccount = this.algoanService.algoanClient.getServiceAccountBySubscriptionId(event.subscription.id);
let serviceAccount = this.algoanService.algoanClient.getServiceAccountBySubscriptionId(event.subscription.id);
// eslint-disable-next-line no-magic-numbers
if (serviceAccount === undefined && this.config.algoan.version === 2) {
// Update the service accounts list. If a service account is created, only one instance of the
// connector is notified though the webhook. the other instances need to update their service account list also
await this.algoanService.initRestHooks(
this.config.targetUrl,
this.config.eventList as AlgoanRestEventName[],
this.config.restHooksSecret,
);
serviceAccount = this.algoanService.algoanClient.getServiceAccountBySubscriptionId(event.subscription.id);
}
if (serviceAccount === undefined) {
throw new UnauthorizedException(`No service account found for subscription ${event.subscription.id}`);
}
Expand Down

0 comments on commit e014059

Please sign in to comment.