Skip to content

Commit 60cdc6c

Browse files
committed
App to use key vault
1 parent 4e39a55 commit 60cdc6c

File tree

8 files changed

+2138
-7
lines changed

8 files changed

+2138
-7
lines changed

App/Api/Api.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<ItemGroup>
3-
<PackageReference Include="APIWeaver.OpenApi" />
43
<ProjectReference Include="..\Services\Services.csproj" />
4+
<PackageReference Include="APIWeaver.OpenApi" />
5+
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" />
6+
<PackageReference Include="Azure.Identity" />
57
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" />
8+
<PackageReference Include="DotNetEnv" />
69
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
710
<PackageReference Include="Scalar.AspNetCore" />
811
<PackageReference Include="Serilog" />

App/Api/Program.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using Api.Setup;
2+
using Azure.Identity;
23
using Serilog;
34

5+
DotNetEnv.Env.TraversePath().Load();
6+
47
var config = new ConfigurationBuilder()
58
.SetBasePath(Directory.GetCurrentDirectory())
69
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
@@ -12,6 +15,14 @@
1215

1316
var builder = WebApplication.CreateBuilder(args);
1417

18+
var keyVaultName = Environment.GetEnvironmentVariable("KEY_VAULT_NAME");
19+
20+
if (!string.IsNullOrEmpty(keyVaultName))
21+
{
22+
var keyVaultUri = new Uri($"https://{keyVaultName}.vault.azure.net/");
23+
builder.Configuration.AddAzureKeyVault(keyVaultUri, new DefaultAzureCredential());
24+
}
25+
1526
builder.Services.ConfigureServices(builder.Environment, builder.Configuration);
1627

1728
var app = builder.Build();

App/Api/Properties/launchSettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"hotReloadEnabled": true,
66
"dotnetRunMessages": true,
77
"launchBrowser": true,
8-
"launchUrl": "http://localhost:5000/scalar",
8+
"launchUrl": "http://localhost:8080/scalar",
99
"environmentVariables": {
1010
"ASPNETCORE_ENVIRONMENT": "Development",
11-
"ASPNETCORE_HTTP_PORTS": "5000"
11+
"ASPNETCORE_HTTP_PORTS": "8080"
1212
}
1313
}
1414
}

0 commit comments

Comments
 (0)