2
votes

Is there a way to find out if an account is premium or not using either Azure Storage Java API or the Azure REST API ?

If I have a storage account name and key, is there a way to figure out the storage account type?

2

2 Answers

1
votes

If you know the subscriptionId, please use the REST solution provided by @Thiago Custodio.

If you don't know the subscriptionId, please check my following workaround.

Based on this thread, we know CORS and Storage Analytics are not supported for Premium storage account, so we can get the account type based on this. If downloadServiceProperties method doesn’t throw exception, the account type is Standard. Otherwise, the account type is Premium. Code below is for your reference.

public string getAccountType(string accountName, string accountKey)
{
    string connectionString = "DefaultEndpointsProtocol=http;AccountName=" + accountName + ";AccountKey=" + accountKey + ";";
    // Setup the cloud storage account.
    CloudStorageAccount account = CloudStorageAccount.parse(connectionString);
    // Create a blob service client
    CloudBlobClient blobClient = account.createCloudBlobClient();
    try
    {
        bloblClient.downloadServiceProperties();
        return "Standard";
    }
    catch(StorageException e)
    {
        return "Premium";
    }
}
3
votes

You can retrive this information inside sku.tier from the REST API:

REQUEST

GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}?api-version=2016-12-01

RESPONSE

{
    "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}",
    "name": "accountName",
    "location": "account geo region",
    "tags": {
        "key1": "value1", 
        "key2": "value2"
    },
    "type": "Microsoft.Storage/StorageAccount",
    "properties": {
        "provisioningState": "status",
        "encryption": {
                "services": {
                        "blob": {
                                "enabled": true,
                                "lastEnabledTime": dateTime}
                }
                "keySource": "Microsoft.Storage"
        }
        "primaryEndpoints": {
            "blob": "blob endpoint",
            "queue": "queue endpoint",
            "table": "table endpoint",
             "file": "file endpoint"
        },
        "primaryLocation": "primary geo region",
        "statusOfPrimary": "available|unavailable",
        "lastGeoFailoverTime": "dateTime",
        "secondaryLocation": "secondary geo region",
        "statusOfSecondary": "available|unavailable",
        "secondaryEndpoints": {
            "blob": "secondary blob endpoint",
            "queue": "secondary queue endpoint",
            "table": "secondary table endpoint",
        },
        "creationTime": "dateTime",
        "customDomain": {
                "name": "user domain”
         },
        "accessTier": "Cool|Hot"
    },
    "sku": {
            "name": "Standard_LRS|Standard_ZRS|Standard_GRS|Standard_RAGRS|Premium_LRS"
            "tier": "Standard|Premium"
    }
    "kind": "Storage|BlobStorage"
}

https://docs.microsoft.com/en-us/rest/api/storagerp/storageaccounts

https://docs.microsoft.com/en-us/rest/api/storagerp/srp_json_get_storage_account_properties