-
Notifications
You must be signed in to change notification settings - Fork 1
/
Helper.cs
33 lines (28 loc) · 1.19 KB
/
Helper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
using Microsoft.Extensions.Configuration;
namespace Surfrider {
public static class Helper {
// https://docs.microsoft.com/en-us/azure/key-vault/secrets/quick-create-net
private static string GetKeyVaultConnectionString(string secretName)
{
string keyVaultName = Environment.GetEnvironmentVariable("KEY_VAULT_NAME");
var kvUri = "https://" + keyVaultName + ".vault.azure.net";
var client = new SecretClient(new Uri(kvUri), new DefaultAzureCredential());
KeyVaultSecret secret = client.GetSecret(secretName);
return secret.Value;
}
public static string GetConnectionString()
{
if (Environment.GetEnvironmentVariable("AZURE_FUNCTIONS_ENVIRONMENT") != "Local")
return GetKeyVaultConnectionString("db-plastico-dev-connectionstring");
else
return Environment.GetEnvironmentVariable("postgre_connection");
}
// I add another useless code line
public static void DoNothing(){
Environment.GetEnvironmentVariable("postgre_connection");
}
}
}