in src/Microsoft.Azure.WebJobs.Host.Storage/DefaultStorageCredentialsValidator.cs [27:81]
private static async Task ValidateCredentialsAsyncCore(IStorageAccount account, CancellationToken cancellationToken)
{
// Verify the credentials are correct.
// Have to actually ping a storage operation.
IStorageBlobClient client = account.CreateBlobClient();
try
{
// This can hang for a long time if the account name is wrong.
// If will fail fast if the password is incorrect.
await client.GetServicePropertiesAsync(cancellationToken);
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception e)
{
var storageException = e as StorageException;
var isDevStoreAccount = GetIsDevStoreAccountFromCloudStorageAccount(account.SdkObject);
if (storageException?.RequestInformation?.HttpStatusCode == 400 &&
storageException?.RequestInformation?.ExtendedErrorInformation?.ErrorCode == "InvalidQueryParameterValue")
{
// Premium storage accounts do not support the GetServicePropertiesAsync call, and respond with a 400 'InvalidQueryParameterValue'.
// If we see this error response classify the account as a premium account
account.Type = StorageAccountType.Premium;
return;
}
else if (isDevStoreAccount)
{
// If using the storage emulator, it might not be running
throw new InvalidOperationException(Constants.CheckAzureStorageEmulatorMessage, e);
}
else
{
// If not a recognized error, the credentials are invalid
string message = String.Format(CultureInfo.CurrentCulture,
"Invalid storage account '{0}'. Please make sure your credentials are correct.",
account.Credentials.AccountName);
throw new InvalidOperationException(message, e);
}
}
IStorageQueueClient queueClient = account.CreateQueueClient();
IStorageQueue queue = queueClient.GetQueueReference("name");
try
{
await queue.ExistsAsync(cancellationToken);
}
catch (StorageException exception) when (IsBlobOnlyStorageException(exception))
{
account.Type = StorageAccountType.BlobOnly;
}
}