Example #1
0
        public async Task <IStorageAccount> GetAccountAsync(string connectionStringName,
                                                            CancellationToken cancellationToken)
        {
            IStorageAccount account;

            if (connectionStringName == ConnectionStringNames.Dashboard)
            {
                account = DashboardAccount;
            }
            else if (connectionStringName == ConnectionStringNames.Storage)
            {
                account = StorageAccount;
            }
            else
            {
                account = null;
            }

            // Only dashboard may be null when requested.
            if (account == null && connectionStringName != ConnectionStringNames.Dashboard)
            {
                throw new InvalidOperationException(StorageAccountParser.FormatParseAccountErrorMessage(
                                                        StorageAccountParseResult.MissingOrEmptyConnectionStringError, connectionStringName));
            }

            if (account != null)
            {
                // On the first attempt, this will make a network call to verify the credentials work.
                await _storageCredentialsValidator.ValidateCredentialsAsync(account, cancellationToken);
            }

            return(account);
        }
Example #2
0
 private static void ValidateStorageAccount(IStorageAccount account, string connectionStringName)
 {
     if (account == null)
     {
         string message = StorageAccountParser.FormatParseAccountErrorMessage(StorageAccountParseResult.MissingOrEmptyConnectionStringError, connectionStringName);
         throw new InvalidOperationException(message);
     }
 }
Example #3
0
        public async Task <IStorageAccount> GetAccountAsync(string connectionStringName, CancellationToken cancellationToken)
        {
            IStorageAccount account = null;

            if (connectionStringName == ConnectionStringNames.Dashboard)
            {
                account = DashboardAccount;
            }
            else if (connectionStringName == ConnectionStringNames.Storage)
            {
                account = StorageAccount;
            }
            else
            {
                // see if this is a user connnection string (i.e. for multi-account scenarios)
                string connectionString = _ambientConnectionStringProvider.GetConnectionString(connectionStringName);
                if (!string.IsNullOrEmpty(connectionString))
                {
                    account = ParseAccount(connectionStringName, connectionString);
                }
            }

            // Only dashboard may be null when requested.
            if (account == null && connectionStringName != ConnectionStringNames.Dashboard)
            {
                throw new InvalidOperationException(StorageAccountParser.FormatParseAccountErrorMessage(
                                                        StorageAccountParseResult.MissingOrEmptyConnectionStringError, connectionStringName));
            }

            if (account != null)
            {
                // On the first attempt, this will make a network call to verify the credentials work.
                await _storageCredentialsValidator.ValidateCredentialsAsync(account, cancellationToken);
            }

            return(account);
        }