Skip to content

Commit b2ca809

Browse files
committed
Remove keyvault dependencies
1 parent c9653a7 commit b2ca809

6 files changed

Lines changed: 31 additions & 13 deletions

File tree

backend/api/EventHandlers/TeamsMessageEventHandler.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,17 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
4545
private async void OnTeamsMessageReceived(TeamsMessageEventArgs e)
4646
{
4747
string teamsMessage = e.TeamsMessage;
48+
string url;
4849

49-
string url = GetWebhookURL(_configuration, "TeamsSystemStatusNotification");
50+
try
51+
{
52+
url = GetWebhookURL(_configuration);
53+
}
54+
catch (KeyNotFoundException ex)
55+
{
56+
_logger.LogError(ex, "Failed to get webhook URL from configuration");
57+
return;
58+
}
5059
var client = new HttpClient();
5160
client.DefaultRequestHeaders.Accept.Add(
5261
new MediaTypeWithQualityHeaderValue("application/json")
@@ -92,20 +101,14 @@ private StringContent CreateTeamsMessageCard(string message)
92101
return content;
93102
}
94103

95-
private static string GetWebhookURL(IConfiguration configuration, string secretName)
104+
private static string GetWebhookURL(IConfiguration configuration)
96105
{
97-
string? keyVaultUri =
98-
configuration.GetSection("KeyVault")["VaultUri"]
99-
?? throw new KeyNotFoundException("No key vault in config");
100-
101-
var keyVault = new SecretClient(
102-
new Uri(keyVaultUri),
103-
new DefaultAzureCredential(new DefaultAzureCredentialOptions())
104-
);
105-
106-
string webhookURL = keyVault.GetSecret(secretName).Value.Value;
106+
string? webhookUrlFromConfig = configuration.GetSection("TeamsNotification")[
107+
"WebhookUrl"
108+
];
107109

108-
return webhookURL;
110+
return webhookUrlFromConfig
111+
?? throw new KeyNotFoundException("No webhook URL in config");
109112
}
110113
}
111114
}

backend/api/appsettings.Development.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,8 @@
3838
},
3939
"Redis": {
4040
"HostName": "robotics-dev-redis.northeurope.redis.azure.net"
41+
},
42+
"TeamsNotification":{
43+
"WebhookUrl": "Fill in ASP.NET Secret Manager"
4144
}
4245
}

backend/api/appsettings.Local.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,8 @@
5656
},
5757
"Redis": {
5858
"UseRedis": false
59+
},
60+
"TeamsNotification":{
61+
"WebhookUrl": "Fill in ASP.NET Secret Manager"
5962
}
6063
}

backend/api/appsettings.Production.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,8 @@
3333
},
3434
"Redis": {
3535
"HostName": "robotics-prod-redis.northeurope.redis.azure.net"
36+
},
37+
"TeamsNotification":{
38+
"WebhookUrl": "Fill in ASP.NET Secret Manager"
3639
}
3740
}

backend/api/appsettings.Staging.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@
3434
},
3535
"Redis": {
3636
"HostName": "robotics-staging-redis.northeurope.redis.azure.net"
37+
},
38+
"TeamsNotification":{
39+
"WebhookUrl": "Fill in ASP.NET Secret Manager"
3740
}
3841
}

backend/api/appsettings.Test.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@
2121
},
2222
"Redis": {
2323
"UseRedis": false
24+
},
25+
"TeamsNotification":{
26+
"WebhookUrl": "Fill in ASP.NET Secret Manager"
2427
}
2528
}

0 commit comments

Comments
 (0)