Skip to content

Commit 6296959

Browse files
committed
moving enviroment.ts settings server side
1 parent 34b5ec7 commit 6296959

File tree

13 files changed

+119
-22
lines changed

13 files changed

+119
-22
lines changed

INSTALL.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ Azure OpenAI settings:
7979

8080
With these settings Chat API will return a `429` status code if you make more than 5 calls per minute (60000 milliseconds)
8181

82+
Angulare application settings:
83+
* **spa_applicationinsights_connection_string**: Application Insights connection string
84+
* **spa_builddate**: build timestamp
85+
* **spa_local_queuelength**: 100000
86+
87+
> **spa_local_queuelength** is the number of log items that are kept client-side in the browser. When the number of log items in the event-hub is greater than this number, only the latest ones are kept and all others are deleted.
88+
8289
# Limit access
8390
After setup is complete, anyone with a valid Microsoft account can access your copy of `az-firewall-mon`. If you want to restrict access, you have several options:
8491

bicep/setup.bicep

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ resource staticWebAppSettings 'Microsoft.Web/staticSites/config@2023-01-01' = {
8080
llm_throttling_calls: '5'
8181
llm_throttling_window_milliseconds: '60000'
8282

83-
// Build date timestamp
84-
BUILD_DATE: baseTime
83+
spa_applicationinsights_connection_string: appInsights.properties.ConnectionString
84+
spa_builddate: baseTime
85+
spa_local_queuelength: '100000'
8586
}
8687
}
8788

bicep/setup.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"_generator": {
66
"name": "bicep",
77
"version": "0.36.1.42791",
8-
"templateHash": "14750720778315896797"
8+
"templateHash": "1576006689434796107"
99
}
1010
},
1111
"parameters": {
@@ -142,7 +142,9 @@
142142
"aoai_deployment": "[parameters('gpt4oDeploymentName')]",
143143
"llm_throttling_calls": "5",
144144
"llm_throttling_window_milliseconds": "60000",
145-
"BUILD_DATE": "[parameters('baseTime')]"
145+
"spa_applicationinsights_connection_string": "[reference(resourceId('Microsoft.Insights/components', parameters('appInsightsName')), '2020-02-02').ConnectionString]",
146+
"spa_builddate": "[parameters('baseTime')]",
147+
"spa_local_queuelength": "100000"
146148
},
147149
"dependsOn": [
148150
"[resourceId('Microsoft.Insights/components', parameters('appInsightsName'))]",

firewall-mon-api/backend.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,20 @@ public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post
5252
};
5353
}
5454

55-
string author = Environment.GetEnvironmentVariable("author") ?? "unknown";
56-
return new OkObjectResult($"Hello from the other side... of the endpoint.\r\nbackend owned by {author}.\r\n");
55+
return new OkObjectResult($"Hello from the other side... of the endpoint.");
5756
}
5857

58+
[Function("settings")]
59+
public IActionResult RunSettings([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "settings/{attribute}")] HttpRequest req, string attribute)
60+
{
61+
string attributeName = $"spa_{attribute}";
62+
63+
string? attributeValue = Environment.GetEnvironmentVariable(attributeName);
64+
//return new OkObjectResult($"did you say {attribute}? it contains: {attributeValue ?? "not set"}");
65+
return new OkObjectResult(attributeValue ?? "not set");
66+
}
67+
68+
5969
[Function("ip")]
6070
public async Task<IActionResult> RunIpAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "ip/{ipAddress}")] HttpRequest req, string ipAddress)
6171
{

firewall-mon-api/local.settings.json.sample

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"AzureWebJobsStorage": "",
55
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
66
"APPLICATIONINSIGHTS_CONNECTION_STRING": "<your-connection-string>",
7-
"author" : "john john",
87
"llm_throttling_window_milliseconds" : "60000",
98
"llm_throttling_calls" : "3",
109
"ip_throttling_window_milliseconds" : "1000",
@@ -13,6 +12,10 @@
1312

1413
"aoai_endpoint": "https://<lorem-aoai-endpoint>.openai.azure.com/openai/",
1514
"aoai_deployment": "",
16-
"aoai_api_key": ""
15+
"aoai_api_key": "",
16+
17+
"spa_applicationinsights_connection_string": "<your-connection-string>",
18+
"spa_builddate": "19720229",
19+
"spa_local_queuelength": "100000"
1720
}
1821
}

firewall-mon-app/src/app/login/login.component.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ export class LoginComponent implements OnInit {
2020
}
2121

2222
username: string = '';
23-
2423
ngOnInit(): void {
2524
this.getUserName();
25+
this.getBuildDate();
2626
}
2727

28-
buildDate: string = environment.BuildDate;
28+
buildDate: string = '';
2929
eventHubConnectionString: string = this.model.eventHubConnection;
3030
eventHubConsumerGroup: string = this.model.eventHubConsumerGroup;
3131
isDemoMode: boolean = this.model.demoMode;
@@ -61,7 +61,6 @@ export class LoginComponent implements OnInit {
6161
}
6262

6363
}
64-
6564
async getUserName(): Promise<void> {
6665
try {
6766
// Set default username in case of errors
@@ -83,4 +82,22 @@ export class LoginComponent implements OnInit {
8382
// Keep default username
8483
}
8584
}
85+
86+
async getBuildDate(): Promise<void> {
87+
try {
88+
const response = await fetch('/api/settings/builddate');
89+
90+
if (!response.ok) {
91+
console.error('Build date API endpoint returned error:', response.status);
92+
this.buildDate = 'Unknown';
93+
return;
94+
}
95+
96+
// Parse the response as text since we expect a simple string
97+
this.buildDate = await response.text();
98+
} catch (error) {
99+
console.error('Error fetching build date:', error);
100+
this.buildDate = 'Unknown';
101+
}
102+
}
86103
}

firewall-mon-app/src/app/main-page/main-page.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
class="container-lottie"/>
8787
</div>
8888

89-
<br/><label class="jsontext" [innerHTML]="this.JSONfySearchParams()"></label>
89+
<br/><label *ngIf="isDevelopmentMode" class="jsontext" [innerHTML]="this.JSONfySearchParams()"></label>
9090
</mat-card-content>
9191
</mat-card>
9292
</div>

firewall-mon-app/src/app/main-page/main-page.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, HostListener, ElementRef, AfterViewInit, ViewChild, OnDestroy } from '@angular/core';
1+
import { Component, isDevMode, OnInit, HostListener, ElementRef, AfterViewInit, ViewChild, OnDestroy } from '@angular/core';
22

33
import { IFirewallSource, FirewallDataRow, ModelService } from '../services/model.service';
44
import { DemoSourceService } from '../services/demo-source.service';
@@ -470,6 +470,10 @@ export class MainPageComponent implements AfterViewInit, OnInit, OnDestroy {
470470
return this.searchFieldService.promptType == PromptType.Chatgpt;
471471
}
472472

473+
public isDevelopmentMode(): boolean {
474+
return isDevMode();
475+
}
476+
473477
public setPromptTypeClassic() {
474478
this.filterText = "";
475479
this.timestampFilterMinutes = 0;

firewall-mon-app/src/app/services/demo-source.service.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class DemoSourceService implements IFirewallSource {
4747
}
4848
}
4949

50+
private queueLength: number = 0;
5051
private intervalId: any=null;
5152
private protocolsArray: Array<string> = ["TCP", "UDP"];
5253
private actionsArray: Array<string> = ["Allow", "Deny", "Request", "Alert", "Drop"];
@@ -65,6 +66,8 @@ export class DemoSourceService implements IFirewallSource {
6566
await this.randomQuote();
6667
await this.randomQuote();
6768

69+
this.queueLength = await this.getQueueLenght();
70+
6871
this.outputMessage("");
6972

7073
this.onDataArrived?.(this.DATA);
@@ -109,7 +112,7 @@ export class DemoSourceService implements IFirewallSource {
109112
}
110113
this.DATA.unshift(row);
111114

112-
while (this.DATA.length > environment.EventsQueueLength) {
115+
while (this.DATA.length > this.queueLength) {
113116
this.DATA.pop();
114117
}
115118

@@ -122,6 +125,24 @@ export class DemoSourceService implements IFirewallSource {
122125
}, this.intervalBetweenMoreRows);
123126
}
124127

128+
private async getQueueLenght(): Promise<number> {
129+
try {
130+
const response = await fetch('/api/settings/local_queuelength');
131+
132+
if (!response.ok) {
133+
console.error('queue lenght API endpoint returned error:', response.status);
134+
return 10;
135+
}
136+
137+
// Parse the response as text and convert to number
138+
const text = await response.text();
139+
return Number(text);
140+
} catch (error) {
141+
console.error('Error fetching queue lenght endpoint:', error);
142+
return 10;
143+
}
144+
}
145+
125146
public async pause() {
126147
clearInterval(this.intervalId);
127148
this.logginService.logEvent("demo source paused");

firewall-mon-app/src/app/services/event-hub-source.service.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export class EventHubSourceService implements Model.IFirewallSource {
1717
private model:Model.ModelService
1818
) {
1919
}
20+
21+
private queueLength: number = 0;
2022
private defaultSleepTime: number = 1500;
2123
private consumerClient: EventHubConsumerClient | undefined;
2224
private subscription: any;
@@ -28,6 +30,7 @@ export class EventHubSourceService implements Model.IFirewallSource {
2830
public onMessageArrived?: ((message: string) => void);
2931

3032
public async start() {
33+
this.queueLength = await this.getQueueLenght();
3134

3235
try {
3336
this.outputMessage(`connecting to azure event hub`);
@@ -119,7 +122,7 @@ export class EventHubSourceService implements Model.IFirewallSource {
119122
moreRows++;
120123
this.DATA.unshift(row);
121124

122-
while (this.DATA.length > environment.EventsQueueLength) {
125+
while (this.DATA.length > this.queueLength) {
123126
this.DATA.pop();
124127
}
125128
}
@@ -185,6 +188,24 @@ export class EventHubSourceService implements Model.IFirewallSource {
185188
this.outputMessage("Logs successfully deleted!");
186189
}
187190

191+
private async getQueueLenght(): Promise<number> {
192+
try {
193+
const response = await fetch('/api/settings/local_queuelength');
194+
195+
if (!response.ok) {
196+
console.error('queue lenght API endpoint returned error:', response.status);
197+
return 10;
198+
}
199+
200+
// Parse the response as text and convert to number
201+
const text = await response.text();
202+
return Number(text);
203+
} catch (error) {
204+
console.error('Error fetching queue lenght endpoint:', error);
205+
return 10;
206+
}
207+
}
208+
188209
private outputMessage (text:string): void {
189210
this.onMessageArrived?.(text);
190211
}

0 commit comments

Comments
 (0)