You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure存储账户模型对象查询:获取全量属性的实现疑问

获取Azure存储账户全部属性的实现方案

Got it, let's break this down step by step to get all properties of your Azure storage accounts!

核心模型对象:StorageAccount

你已经完成了Azure客户端的初始化,接下来要用到的核心模型就是StorageAccount——它对应着每个存储账户的实体,封装了所有你需要的属性信息。

步骤1:获取所有存储账户实例

通过StorageAccounts接口的list()方法,就能拿到当前订阅下所有存储账户的StorageAccount对象集合:

List<StorageAccount> allStorageAccounts = storageAccounts.list();

步骤2:遍历并访问核心属性

每个StorageAccount对象提供了大量方法来读取各类属性,下面是常用属性的获取示例:

  • 基础标识信息:
    • 账户名称:storageAccount.name()
    • 所属资源组:storageAccount.resourceGroupName()
    • 唯一账户ID:storageAccount.id()
  • 部署配置信息:
    • 区域位置:storageAccount.regionName()
    • SKU类型(如Standard_LRS、Premium_ZRS):storageAccount.sku().name()
    • 账户类型(StorageV2、BlobStorage等):storageAccount.kind()
    • 数据访问层级(Hot/Cool):storageAccount.accessTier()
  • 状态与时间信息:
    • 账户创建时间:storageAccount.creationTime()
    • 主节点状态:storageAccount.statusOfPrimary()
    • 备用节点状态:storageAccount.statusOfSecondary()

步骤3:获取进阶服务属性

如果需要获取Blob服务、文件服务等子服务的详细配置(比如CORS规则、日志设置),可以通过StorageAccount的子服务方法获取:
比如读取Blob服务的存储分析配置:

BlobServiceProperties blobServiceProps = storageAccount.blobServices().getServiceProperties();
// 获取CORS规则列表
List<CorsRule> corsRules = blobServiceProps.cors().corsRules();
// 获取日志记录配置
LoggingProperties loggingConfig = blobServiceProps.logging();

完整代码示例

把这些整合到你的现有代码中,最终实现如下:

// 你的已有初始化代码
Azure azure = Azure.configure()
    .withLogLevel(LogLevel.NONE)
    .authenticate(credFile)
    .withDefaultSubscription();
StorageAccounts storageAccounts = azure.storageAccounts();

// 遍历所有存储账户并输出属性
List<StorageAccount> allStorageAccounts = storageAccounts.list();
for (StorageAccount sa : allStorageAccounts) {
    System.out.println("=== 存储账户 " + sa.name() + " 属性详情 ===");
    System.out.println("所属资源组: " + sa.resourceGroupName());
    System.out.println("部署区域: " + sa.regionName());
    System.out.println("SKU类型: " + sa.sku().name());
    System.out.println("账户类型: " + sa.kind());
    System.out.println("访问层级: " + sa.accessTier());
    System.out.println("创建时间: " + sa.creationTime());
    System.out.println("主节点状态: " + sa.statusOfPrimary());
    
    // 可选:输出Blob服务CORS规则数量
    BlobServiceProperties blobProps = sa.blobServices().getServiceProperties();
    System.out.println("Blob服务CORS规则数量: " + blobProps.cors().corsRules().size());
    System.out.println("------------------------");
}

内容的提问来源于stack exchange,提问作者Deepak S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:25:14