示例#1
0
        public async Task <StorageAccount> GetStorageAccountsAsync(ArmWrapper <object> armWrapper)
        {
            var regex = new Regex("/subscriptions/(.*)/resourceGroups/(.*)/providers/Microsoft.Storage/storageAccounts/(.*)", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            var match = regex.Match(armWrapper.Id);

            if (match.Success)
            {
                var storageAccount = new StorageAccount(match.Groups[1].ToString(), match.Groups[2].ToString(), match.Groups[3].ToString(), string.Empty);
                return(await LoadAsync(storageAccount));
            }
            else
            {
                return(null);
            }
        }
        private static async Task <StorageAccount> GetStorageAccount(ArmWrapper <ArmGenericResource> armWrapper, string accessToken, string managementURL)
        {
            try
            {
                var url  = new Uri($"{managementURL}{armWrapper.id}/listKeys?api-version={_storageApiVersion}");
                var keys = await ArmHttpAsync <ArmStorageKeysArray>(HttpMethod.Post, url, accessToken);

                return(new StorageAccount
                {
                    StorageAccountName = armWrapper.name,
                    StorageAccountKey = keys.keys.First().value
                });
            }
            catch (Exception e)
            {
                if (StaticSettings.IsDebug)
                {
                    ColoredConsole.Error.WriteLine(ErrorColor(e.ToString()));
                }

                throw new CliException($"Cannot get keys for storage account {armWrapper.name}. Make sure you have access to the storage account.");
            }
        }