Reputation: 474
I added a connection string in my KeyVault Secret. I wanted to update the same using .Net SDK but not able to find any method that will allow me to do so.
I tried using UpdateSecretAsync()
but this method doesn't accept Secret Value.
Can someone please point me to correct method.
Upvotes: 4
Views: 4927
Reputation: 9
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
namespace key_vault_console_app
{
class Program
{
public static void Main()
{
var kvUri = $"https://{your keyvault name}.vault.azure.net";
var client = new SecretClient(new Uri(kvUri), new DefaultAzureCredential());
var secretValue = client.GetSecret("Vishwa-Test");
Console.WriteLine(secretValue.Value.Value);
client.SetSecret("Vishwa-Test", "Test1234");
}
}
}
Upvotes: -1
Reputation: 11256
Use the SetSecretAsync
method. If the secretName doesn't exists it will create it. If it does exist it will replace it.
// Code to generate a new secret
var newSecret = "<the new secret>"
// Update the secret in the key vault
client.SetSecretAsync(vault, secretName, newSecret);
Upvotes: 10