0

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?

Saca
  • 10,355
  • 1
  • 34
  • 47
Lubch
  • 57
  • 1
  • 9

2 Answers2

2

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.

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • Thanks, I thought about this approach, but it looks more like workaround. But if there is no other ways, it can be :-) – Lubch Jun 21 '17 at 13:59
  • It is indeed a workaround :). We also use this approach to test if the account name/key combination is correct in our products as there's no "Validate Connection" API available (like you have in SQL Server). – Gaurav Mantri Jun 21 '17 at 14:00
1

There isn't such an API to do that since your accounts are across different clouds and Azure APIs are always serving within one cloud. Actually, you can even create accounts with the same name across different clouds. Therefore, you need to maintain the "account, cloud name (public Azure/China/Germany Gov)" mapping by yourself. :)

Zhaoxing Lu
  • 6,319
  • 18
  • 41