Esempio n. 1
0
        private static async Task ProcessStorageAccountAsync(StorageAccount account, StorageAccountListKeysResponse keys, ILogger log, CancellationToken ct)
        {
            try
            {
                log.LogInformation($"Found storage account: {account.Name}");
                if (!IsBackupStorageAccount(account))
                {
                    return;
                }

                //var azureServiceTokenProvider = new AzureServiceTokenProvider();
                //var endpointSuffix = "core.windows.net";
                //var storageTokenString = await azureServiceTokenProvider.GetAccessTokenAsync(resource: $"https://{account.Name}.blob.{endpointSuffix}/");
                //var storageToken = new StorageCredentials(tokenCredential: new TokenCredential(initialToken: storageTokenString));
                //var storageAccount = new CloudStorageAccount(storageCredentials: storageToken, accountName: account.Name, endpointSuffix: endpointSuffix, useHttps: true);

                var storageAccount = new CloudStorageAccount(
                    storageCredentials: new StorageCredentials(
                        accountName: account.Name,
                        keyValue: keys.StorageAccountKeys.Key1),
                    useHttps: true);

                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                await blobClient.IterateContainers(ct, container => ProcessContainerAsync(account, blobClient, container, log, ct));
            }
            catch (Exception accountException)
            {
                log.LogError($"{accountException.GetType().FullName} while processing account {account.Name}: \"{accountException.Message}\" - {accountException.StackTrace}");
            }
        }