AzureNamedKeyCredential
Credential allowing a named key to be used for authenticating to an Azure Service.
It provides the ability to update the key without creating a new client.
using Azure.Core;
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading;
namespace Azure
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class AzureNamedKeyCredential
{
private Tuple<string, string> _namedKey;
public string Name => Volatile.Read(ref _namedKey).Item1;
public AzureNamedKeyCredential(string name, string key)
{
Update(name, key);
}
public void Update(string name, string key)
{
Argument.AssertNotNullOrEmpty(name, "name");
Argument.AssertNotNullOrEmpty(key, "key");
Volatile.Write(ref _namedKey, Tuple.Create(name, key));
}
[EditorBrowsable(EditorBrowsableState.Never)]
public void Deconstruct(out string name, out string key)
{
Tuple<string, string> tuple = Volatile.Read(ref _namedKey);
name = tuple.Item1;
key = tuple.Item2;
}
}
}