Skip to content

Commit

Permalink
chore: Update KEYVAULT_URL in dotnet and python examples (#573)
Browse files Browse the repository at this point in the history
* Update KEYVAULT_URL in dotnet and python examples
* chore: update example code
  • Loading branch information
karataliu committed Sep 28, 2022
1 parent 83fbae3 commit a00ef76
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 7 additions & 5 deletions examples/msal-net/akvdotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ public class Program
static void Main(string[] args)
{
Program P = new Program();
string keyvaultName = Environment.GetEnvironmentVariable("KEYVAULT_NAME");
string secretName = Environment.GetEnvironmentVariable("SECRET_NAME");
string keyvaultURL = Environment.GetEnvironmentVariable("KEYVAULT_URL");
if (string.IsNullOrEmpty(keyvaultURL)) {
string keyvaultName = Environment.GetEnvironmentVariable("KEYVAULT_NAME");
keyvaultURL = "https://" + keyvaultName + ".vault.azure.net/";
}

// keyvault URL
string keyvaultURL = "https://" + keyvaultName + ".vault.azure.net/";
string secretName = Environment.GetEnvironmentVariable("SECRET_NAME");

SecretClient client = new SecretClient(
new Uri(keyvaultURL),
Expand All @@ -25,7 +27,7 @@ static void Main(string[] args)
{
Console.WriteLine($"{Environment.NewLine}START {DateTime.UtcNow} ({Environment.MachineName})");

// <getsecret>
// <getsecret>
var keyvaultSecret = client.GetSecret(secretName).Value;
Console.WriteLine("Your secret is " + keyvaultSecret.Value);

Expand Down
7 changes: 5 additions & 2 deletions examples/msal-python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ def main():
# create a token credential object, which has a get_token method that returns a token
token_credential = MyClientAssertionCredential(azure_client_id, azure_tenant_id, azure_authority_host, azure_federated_token_file)

keyvault_name = os.getenv('KEYVAULT_NAME', '')
keyvault_url = os.getenv('KEYVAULT_URL', '')
if not keyvault_url:
keyvault_name = os.getenv('KEYVAULT_NAME', '')
keyvault_url='https://{}.vault.azure.net'.format(keyvault_name)
secret_name = os.getenv('SECRET_NAME', '')

# create a secret client with the token credential
keyvault = SecretClient(vault_url='https://{}.vault.azure.net'.format(keyvault_name), credential=token_credential)
keyvault = SecretClient(vault_url=keyvault_url, credential=token_credential)
secret = keyvault.get_secret(secret_name)
print('successfully got secret, secret={}'.format(secret.value))

Expand Down

0 comments on commit a00ef76

Please sign in to comment.