|
1 | 1 | import { Injectable } from "@angular/core";
|
2 | 2 | import {
|
3 |
| - AppConfig, |
4 |
| - AppConfigFeatureFlags, |
5 |
| - AppConfigLoginInstructions, |
| 3 | + AppRuntimeConfig, |
| 4 | + AppUIConfigFeatureFlags, |
| 5 | + AppLoginInstructions, |
6 | 6 | GrafanaLogsConfiguration,
|
| 7 | + AppUIConfig, |
7 | 8 | } from "./app-config.model";
|
8 | 9 | import { environment } from "src/environments/environment";
|
9 | 10 | import { MaybeUndefined } from "./common/app.types";
|
| 11 | +import AppValues from "./common/app.values"; |
10 | 12 |
|
11 | 13 | @Injectable({
|
12 | 14 | providedIn: "root",
|
13 | 15 | })
|
14 | 16 | export class AppConfigService {
|
15 |
| - private appConfig?: AppConfig; |
| 17 | + private appRuntimeConfig?: AppRuntimeConfig; |
| 18 | + private appUiConfig?: AppUIConfig; |
16 | 19 |
|
17 | 20 | get apiServerUrl(): string {
|
18 |
| - if (!this.appConfig) { |
19 |
| - this.appConfig = AppConfigService.loadAppConfig(); |
| 21 | + if (!this.appRuntimeConfig) { |
| 22 | + this.appRuntimeConfig = AppConfigService.loadAppRuntimeConfig(); |
20 | 23 | }
|
21 | 24 |
|
22 | 25 | return new URL(this.apiServerGqlUrl).origin;
|
23 | 26 | }
|
24 | 27 |
|
25 | 28 | get apiServerGqlUrl(): string {
|
26 |
| - if (!this.appConfig) { |
27 |
| - this.appConfig = AppConfigService.loadAppConfig(); |
| 29 | + if (!this.appRuntimeConfig) { |
| 30 | + this.appRuntimeConfig = AppConfigService.loadAppRuntimeConfig(); |
28 | 31 | }
|
29 | 32 |
|
30 |
| - return this.appConfig.apiServerGqlUrl; |
| 33 | + return this.appRuntimeConfig.apiServerGqlUrl; |
31 | 34 | }
|
32 | 35 |
|
33 | 36 | get apiServerHttpUrl(): string {
|
34 |
| - if (!this.appConfig) { |
35 |
| - this.appConfig = AppConfigService.loadAppConfig(); |
| 37 | + if (!this.appRuntimeConfig) { |
| 38 | + this.appRuntimeConfig = AppConfigService.loadAppRuntimeConfig(); |
36 | 39 | }
|
37 | 40 |
|
38 |
| - return this.appConfig.apiServerHttpUrl; |
| 41 | + return this.appRuntimeConfig.apiServerHttpUrl; |
39 | 42 | }
|
40 | 43 |
|
41 |
| - get ingestUploadFileLimitMb(): number { |
42 |
| - if (!this.appConfig) { |
43 |
| - this.appConfig = AppConfigService.loadAppConfig(); |
| 44 | + get githubClientId(): MaybeUndefined<string> { |
| 45 | + if (!this.appRuntimeConfig) { |
| 46 | + this.appRuntimeConfig = AppConfigService.loadAppRuntimeConfig(); |
44 | 47 | }
|
45 | 48 |
|
46 |
| - return this.appConfig.ingestUploadFileLimitMb; |
| 49 | + return this.appRuntimeConfig.githubClientId; |
47 | 50 | }
|
48 | 51 |
|
49 |
| - get githubClientId(): MaybeUndefined<string> { |
50 |
| - if (!this.appConfig) { |
51 |
| - this.appConfig = AppConfigService.loadAppConfig(); |
| 52 | + get grafanaLogs(): GrafanaLogsConfiguration | null { |
| 53 | + if (!this.appRuntimeConfig) { |
| 54 | + this.appRuntimeConfig = AppConfigService.loadAppRuntimeConfig(); |
52 | 55 | }
|
53 | 56 |
|
54 |
| - return this.appConfig.githubClientId; |
| 57 | + return this.appRuntimeConfig.grafanaLogs ?? null; |
55 | 58 | }
|
56 | 59 |
|
57 |
| - get featureFlags(): AppConfigFeatureFlags { |
58 |
| - if (!this.appConfig) { |
59 |
| - this.appConfig = AppConfigService.loadAppConfig(); |
| 60 | + get loginInstructions(): AppLoginInstructions | null { |
| 61 | + if (!this.appRuntimeConfig) { |
| 62 | + this.appRuntimeConfig = AppConfigService.loadAppRuntimeConfig(); |
60 | 63 | }
|
61 | 64 |
|
62 |
| - return this.appConfig.featureFlags; |
| 65 | + if (this.appRuntimeConfig.loginInstructions) { |
| 66 | + return this.appRuntimeConfig.loginInstructions; |
| 67 | + } else { |
| 68 | + return null; |
| 69 | + } |
63 | 70 | }
|
64 | 71 |
|
65 |
| - get grafanaLogs(): GrafanaLogsConfiguration | null { |
66 |
| - if (!this.appConfig) { |
67 |
| - this.appConfig = AppConfigService.loadAppConfig(); |
| 72 | + get ingestUploadFileLimitMb(): number { |
| 73 | + if (!this.appRuntimeConfig) { |
| 74 | + this.appRuntimeConfig = AppConfigService.loadAppRuntimeConfig(); |
| 75 | + } |
| 76 | + if (!this.appUiConfig) { |
| 77 | + this.appUiConfig = AppConfigService.loadAppUIConfig(this.appRuntimeConfig); |
68 | 78 | }
|
69 | 79 |
|
70 |
| - return this.appConfig.grafanaLogs ?? null; |
| 80 | + return this.appUiConfig.ingestUploadFileLimitMb; |
71 | 81 | }
|
72 | 82 |
|
73 |
| - get loginInstructions(): AppConfigLoginInstructions | null { |
74 |
| - if (!this.appConfig) { |
75 |
| - this.appConfig = AppConfigService.loadAppConfig(); |
| 83 | + get featureFlags(): AppUIConfigFeatureFlags { |
| 84 | + if (!this.appRuntimeConfig) { |
| 85 | + this.appRuntimeConfig = AppConfigService.loadAppRuntimeConfig(); |
76 | 86 | }
|
77 |
| - |
78 |
| - if (this.appConfig.loginInstructions) { |
79 |
| - return this.appConfig.loginInstructions; |
80 |
| - } else { |
81 |
| - return null; |
| 87 | + if (!this.appUiConfig) { |
| 88 | + this.appUiConfig = AppConfigService.loadAppUIConfig(this.appRuntimeConfig); |
82 | 89 | }
|
| 90 | + |
| 91 | + return this.appUiConfig.featureFlags; |
83 | 92 | }
|
84 | 93 |
|
85 |
| - private static loadAppConfig(): AppConfig { |
| 94 | + private static loadAppRuntimeConfig(): AppRuntimeConfig { |
86 | 95 | const request = new XMLHttpRequest();
|
87 | 96 | request.open("GET", environment.runtime_config_file, false);
|
88 | 97 | request.send(null);
|
89 |
| - const data: AppConfig = JSON.parse(request.responseText) as AppConfig; |
| 98 | + const data: AppRuntimeConfig = JSON.parse(request.responseText) as AppRuntimeConfig; |
90 | 99 | return {
|
91 | 100 | ...data,
|
92 | 101 | apiServerGqlUrl: AppConfigService.toRemoteURL(data.apiServerGqlUrl),
|
93 | 102 | };
|
94 | 103 | }
|
95 | 104 |
|
| 105 | + private static loadAppUIConfig(app_runtime_config: AppRuntimeConfig): AppUIConfig { |
| 106 | + const request = new XMLHttpRequest(); |
| 107 | + request.open("GET", app_runtime_config.apiServerHttpUrl + "/ui-config", false); |
| 108 | + try { |
| 109 | + request.send(null); |
| 110 | + const data: AppUIConfig = JSON.parse(request.responseText) as AppUIConfig; |
| 111 | + return data; |
| 112 | + } catch (error) { |
| 113 | + return AppValues.DEFAULT_UI_CONFIGURATION; |
| 114 | + } |
| 115 | + } |
| 116 | + |
96 | 117 | // If loopback or any address is used - replace hostname with hostname from the browser
|
97 | 118 | private static toRemoteURL(url: string): string {
|
98 | 119 | const turl = new URL(url);
|
|
0 commit comments