コード例 #1
0
 public Task <List <SecretData> > RotateValues(RotationContext context, CancellationToken cancellationToken)
 {
     return(_that.RotateValues(_parameters, context, cancellationToken));
 }
コード例 #2
0
 public abstract Task <List <SecretData> > RotateValues(IDictionary <string, object> parameters, RotationContext context, CancellationToken cancellationToken);
コード例 #3
0
 public virtual async Task <List <SecretData> > RotateValues(RotationContext context, CancellationToken cancellationToken)
 {
     return(new List <SecretData> {
         await RotateValue(context, cancellationToken)
     });
 }
コード例 #4
0
 protected virtual Task <SecretData> RotateValue(RotationContext context, CancellationToken cancellationToken)
 {
     throw new NotImplementedException("Must implement either RotateValue or RotateValues");
 }
コード例 #5
0
        public static async Task <string> RotateStorageAccountKey(string subscriptionId, string accountName, RotationContext context, TokenCredentialProvider tokenCredentialProvider, CancellationToken cancellationToken)
        {
            StorageManagementClient client = await CreateManagementClient(subscriptionId, tokenCredentialProvider, cancellationToken);

            StorageAccount account = await FindAccount(accountName, client, cancellationToken);

            if (account == null)
            {
                throw new ArgumentException($"Storage account '{accountName}' in subscription '{subscriptionId}' not found.");
            }

            string     currentKey = context.GetValue("currentKey", "key1");
            ResourceId id         = ResourceId.FromString(account.Id);
            StorageAccountListKeysResult keys;
            string keyToReturn;

            switch (currentKey)
            {
            case "key1":
                keys = await client.StorageAccounts.RegenerateKeyAsync(id.ResourceGroupName, id.Name, "key2", cancellationToken : cancellationToken);

                keyToReturn = "key2";
                break;

            case "key2":
                keys = await client.StorageAccounts.RegenerateKeyAsync(id.ResourceGroupName, id.Name, "key1", cancellationToken : cancellationToken);

                keyToReturn = "key1";
                break;

            default:
                throw new InvalidOperationException($"Unexpected 'currentKey' value '{currentKey}'.");
            }

            StorageAccountKey key = keys.Keys.FirstOrDefault(k => k.KeyName == keyToReturn) ?? throw new InvalidOperationException($"Key {keyToReturn} not found.");

            context.SetValue("currentKey", keyToReturn);

            return(key.Value);
        }