Exemple #1
0
        public async Task <IStorageAccount> GetAccountAsync(string connectionStringName, CancellationToken cancellationToken)
        {
            IStorageAccount account   = null;
            var             isPrimary = true;

            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);
                    isPrimary = false;
                }
            }

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

            return(account);
        }
Exemple #2
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);
        }
Exemple #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);
        }
Exemple #4
0
        private async Task <IStorageAccount> CreateAndValidateAccountAsync(string connectionStringName, CancellationToken cancellationToken)
        {
            IStorageAccount account   = null;
            var             isPrimary = true;

            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);
                    isPrimary = false;
                }
            }

            if (account != null)
            {
                await _storageCredentialsValidator.ValidateCredentialsAsync(account, cancellationToken);

                if (isPrimary)
                {
                    account.AssertTypeOneOf(StorageAccountType.GeneralPurpose);
                }
            }

            return(account);
        }