Skip to content

Commit

Permalink
Reconfigure some Azure Keyvault related stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ewdlop committed Jun 8, 2024
1 parent c0acf82 commit 7bdff00
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,7 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd
/ConsoleApp/Properties/serviceDependencies.json
/ConsoleApp/Properties/serviceDependencies.local.json
/ConsoleApp/Properties/ServiceDependencies/local/local.arm.json
2 changes: 2 additions & 0 deletions ConsoleApp/ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>4e612343-5fff-4b56-8bbe-1926c4d6f531</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="OneOf" Version="3.0.271" />
</ItemGroup>

Expand Down
20 changes: 18 additions & 2 deletions ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,25 @@

const string connectionStringSecret = "MyCosmosDBConnectionString";
const string databaseIdSecret = "MyCosmosDBDatabaseId";
string azureKeyVaultEndpoint = $"https://kv-ray81081506952833917.vault.azure.net/";

SecretClient secretClient = new SecretClient(new Uri(azureKeyVaultEndpoint), new DefaultAzureCredential(true));
Console.WriteLine("Hello from CosmosDB Partial Update!");

//Azure Key Vault
//https://docs.microsoft.com/en-us/azure/key-vault/general/basic-concepts
//https://docs.microsoft.com/en-us/azure/key-vault/secrets/quick-create-net
//https://docs.microsoft.com/en-us/azure/key-vault/secrets/quick-create-python
//https://learn.microsoft.com/en-us/azure/key-vault/secrets/quick-create-node?tabs=azure-cli%2Cwindows

Console.WriteLine("Please enter your Azure Key Vault endpoint:");
string? azureKeyVaultEndpoint = Console.ReadLine();

if (string.IsNullOrWhiteSpace(azureKeyVaultEndpoint))
{
Console.WriteLine("Azure Key Vault endpoint is required.");
return;
}

SecretClient secretClient = new SecretClient(new Uri(azureKeyVaultEndpoint), new DefaultAzureCredential(includeInteractiveCredentials: true));
Azure.Response<KeyVaultSecret> connectionStringSecretResponse = await secretClient.GetSecretAsync(connectionStringSecret);
Azure.Response<KeyVaultSecret> databaseIdSecretResponse = await secretClient.GetSecretAsync(databaseIdSecret);

Expand Down
7 changes: 7 additions & 0 deletions ConsoleApp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"profiles": {
"ConsoleApp": {
"commandName": "Project"
}
}
}

0 comments on commit 7bdff00

Please sign in to comment.