是否有办法使用Azure存储Java API或Azure REST API查明帐户是否为高级帐户?
如果我有存储帐户名称和密钥,是否可以找出存储帐户类型?
答案 0 :(得分:3)
您可以从REST API中检索sku.tier中的此信息:
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
答案 1 :(得分:1)
如果您知道subscriptionId,请使用@Thiago Custodio提供的REST解决方案。
如果您不了解subscriptionId,请查看以下解决方法。
根据this thread,我们知道高级存储帐户不支持CORS和存储分析,因此我们可以根据此类型获取帐户类型。如果downloadServiceProperties方法不引发异常,则帐户类型为Standard。否则,帐户类型为Premium。以下代码供您参考。
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";
}
}