Imagine, we have 2 Azure storage accounts, one of them is regular, other one - Government (or Germany, Chine etc.). Here is how we create CloudBlobClient:
private const string ConnectionStringTemplate = "DefaultEndpointsProtocol={0};AccountName={1};AccountKey={2};";
public static CloudBlobClient Create(string protocol, string accountName, string accountKey)
{
var connectionString = string.Format(CultureInfo.InvariantCulture, ConnectionStringTemplate, protocol, accountName, accountKey);
var account = CloudStorageAccount.Parse(connectionString);
return account.CreateCloudBlobClient();
}
This code works fine for regular account, but for Government one doesn't. We should specify EndpointSuffix (core.usgovcloudapi.net instead of core.windows.net which is default), and connection string should be like this:
"DefaultEndpointsProtocol={0};AccountName={1};AccountKey={2};EndpointSuffix={3}";
So, the question is, how can I know which account is if have only AccountName and AccountKey? Is there some API method to check account type or endpoint suffix for them?
So, the question is, how can I know which account is if have only AccountName and AccountKey? Is there some API method to check account type or endpoint suffix for them?
As of today, there's no API to do that. One thing you could do is create an instance of CloudStorageAccount
using the information you have and try to list blob containers.
Assuming a storage account by that name exists and if the account name/key combination is correct, then you should be able to see blob containers list. If the account name/key combination is incorrect, then storage service will return a 403 error.
Since your intent is only to check the account name/key combination, you can ask storage service to return just 1 blob container to reduce the response data and speed up the operation.