diff --git a/bun.lockb b/bun.lockb index 9005ac7..f86db2c 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/charts/ror-webapp/values.yaml b/charts/ror-webapp/values.yaml index 57be261..2daa96e 100644 --- a/charts/ror-webapp/values.yaml +++ b/charts/ror-webapp/values.yaml @@ -4,7 +4,7 @@ enabled: true web: # hosts is a list of hosts that the webapp should be available on - hosts: + hosts: - host.ror.io # apiUrl is the url of the ror api apiUrl: https://api.ror.io @@ -67,7 +67,7 @@ resources: memory: 128Mi autoscaling: enabled: true - minReplicas: 2 + minReplicas: 1 maxReplicas: 5 targetCPUUtilizationPercentage: 85 nodeSelector: {} diff --git a/src/app/core/models/config.ts b/src/app.config.ts similarity index 76% rename from src/app/core/models/config.ts rename to src/app.config.ts index d26d140..8e4639d 100644 --- a/src/app/core/models/config.ts +++ b/src/app.config.ts @@ -1,4 +1,8 @@ -export interface Config { +import { InjectionToken } from '@angular/core'; + +export const APP_CONFIG = new InjectionToken('app.config'); + +export interface AppConfig { auth: Auth; regex: Regex; rowsPerPage: number[]; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 6492b68..5b3ff7a 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -22,7 +22,6 @@ import localeEnExtra from '@angular/common/locales/extra/en'; import { CoreModule } from './core/core.modules'; import { SharedModule } from './shared/shared.module'; import { MessageService } from 'primeng/api'; -import { ConfigService, configFactory } from './core/services/config.service'; import { provideHighlightOptions } from 'ngx-highlightjs'; import { InMemoryScrollingFeature, InMemoryScrollingOptions, withInMemoryScrolling } from '@angular/router'; import { environment } from '../environments/environment'; @@ -70,18 +69,11 @@ const inMemoryScrollingFeature: InMemoryScrollingFeature = withInMemoryScrolling }), ], providers: [ - //provideRouter(routes, inMemoryScrollingFeature, withViewTransitions(), withDebugTracing()), { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true, }, - { - provide: APP_INITIALIZER, - useFactory: configFactory, - multi: true, - deps: [ConfigService], - }, MessageService, provideHighlightOptions({ lineNumbersOptions: { diff --git a/src/app/core/services/auth.service.ts b/src/app/core/services/auth.service.ts index 6f1457e..bcc6b8d 100644 --- a/src/app/core/services/auth.service.ts +++ b/src/app/core/services/auth.service.ts @@ -10,25 +10,14 @@ import { jwtDecode } from 'jwt-decode'; }) export class AuthService { authenticationEventObservable: Subject = new Subject(); - authConfig: AuthConfig = { - issuer: this.configService.config.auth.issuer, - redirectUri: this.configService.config.auth.redirectUri, - clientId: this.configService.config.auth.clientId, - responseType: this.configService.config.auth.responseType, - scope: this.configService.config.auth.scope, - showDebugInformation: false, - timeoutFactor: 0.75, - postLogoutRedirectUri: this.configService.config.auth.postLogoutRedirectUri, - logoutUrl: this.configService.config.auth.logoutUrl, - requireHttps: this.configService.config.auth.requireHttps, - strictDiscoveryDocumentValidation: this.configService.config.auth.strictDiscoveryDocumentValidation, - }; + authConfig: AuthConfig | undefined; constructor( private oauthService: OAuthService, private userService: UserService, private configService: ConfigService, ) { + this.setConfig(); this.oauthService.configure(this.authConfig); } @@ -53,6 +42,7 @@ export class AuthService { this.authenticationEventObservable.next(result); }) .catch((error: any) => { + console.error('Error logging in', error); this.logout(); }); @@ -79,4 +69,21 @@ export class AuthService { exp.setUTCSeconds(decodedToken.exp); return now > exp; } + + private setConfig() { + const config = this.configService.config; + this.authConfig = { + issuer: config?.auth.issuer, + redirectUri: config?.auth?.redirectUri, + clientId: config?.auth?.clientId, + responseType: config?.auth?.responseType, + scope: config?.auth?.scope, + showDebugInformation: false, + timeoutFactor: 0.75, + postLogoutRedirectUri: config?.auth?.postLogoutRedirectUri, + logoutUrl: config?.auth?.logoutUrl, + requireHttps: config?.auth?.requireHttps, + strictDiscoveryDocumentValidation: config?.auth?.strictDiscoveryDocumentValidation, + }; + } } diff --git a/src/app/core/services/config.service.ts b/src/app/core/services/config.service.ts index dcb6839..2dee96e 100644 --- a/src/app/core/services/config.service.ts +++ b/src/app/core/services/config.service.ts @@ -1,79 +1,18 @@ -import { HttpClient } from '@angular/common/http'; -import { Injectable } from '@angular/core'; -import { Observable, catchError, map, of } from 'rxjs'; -import { Config } from '../models/config'; -import { environment } from '../../../environments/environment'; - -export const configFactory = (config: ConfigService) => { - return () => config.loadConfig(); -}; +import { Inject, Injectable } from '@angular/core'; +import { APP_CONFIG, AppConfig } from '../../../app.config'; @Injectable({ providedIn: 'root', }) export class ConfigService { - config: Config; - - constructor(private httpClient: HttpClient) { - this.config = this.defaultConfig(); - } - - loadConfig(): Observable { - return this.httpClient.get(environment.configPath).pipe( - map((response: any) => { - // do something to reflect into local model - this.config = this.createConfig(response); - return true; - }), - catchError((error: any) => { - this.config = this.defaultConfig(); - console.error('Error loading config', error); - return of(false); - }), - ); - } + config: AppConfig; - private createConfig(json: any): Config { - const config = { ...(json) }; - config.auth.redirectUri = window.location.origin + config.auth.redirectUri; - config.auth.postLogoutRedirectUri = window.location.origin; - return config; - } - - private defaultConfig(): Config { - const config: Config = { - auth: { - issuer: 'http://localhost:5556/dex', - clientId: 'ror.sky.test.nhn.no', - redirectUri: window.location.origin + '/auth/callback', - scope: 'profile email groups', - responseType: 'id_token token', - logoutUrl: window.location.origin, - postLogoutRedirectUri: window.location.origin, - requireHttps: false, - strictDiscoveryDocumentValidation: false, - }, - regex: { - forms: `^[@()\\/:?\\r\\n.,a-zA-Z æøåÆØÅ0-9_-]+$`, - }, - rorApi: 'https://ror.sky.test.nhn.no', - rows: 25, - rowsPerPage: [10, 25, 50, 75, 100], - sse: { - postfixUrl: '/v1/events/listen', - timeout: 30000, - method: 'GET', - }, - }; - - if (environment.production) { - config.auth.clientId = 'ror.sky.test.nhn.no'; - config.auth.issuer = 'https://auth.sky.nhn.no/dex'; - config.rorApi = 'https://api.ror.nhn.no'; - config.auth.requireHttps = true; - config.auth.strictDiscoveryDocumentValidation = true; + constructor(@Inject(APP_CONFIG) config: AppConfig) { + this.config = config; + if (!config) { + console.error('Config not loaded'); + return; } - - return config; + this.config.auth.redirectUri = window.location.origin + this.config.auth.redirectUri; } } diff --git a/src/main.ts b/src/main.ts index d9a2e7e..133ffb1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,10 +4,19 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './app/app.module'; import { environment } from './environments/environment'; -if (environment.production) { - enableProdMode(); -} +import { APP_CONFIG } from './app.config'; -platformBrowserDynamic() - .bootstrapModule(AppModule) - .catch((err) => console.error(err)); +fetch(environment.configPath) + .then((response) => response.json()) + .then((config) => { + if (environment.production) { + enableProdMode(); + } + platformBrowserDynamic([{ provide: APP_CONFIG, useValue: config }]) + .bootstrapModule(AppModule) + .catch((err) => console.error(err)); + }) + .catch((err) => { + console.error(err); + return 'Failed to load config'; + });