列举桶清单(HarmonyOS SDK)
功能说明
调用列举桶清单接口,您可获取指定桶的所有清单配置信息。
接口约束
- 您必须是桶拥有者或拥有列举桶清单的权限,才能列举桶清单配置。建议使用IAM或桶策略进行授权,如果使用IAM则需授予obs:bucket:GetBucketInventoryConfiguration权限,如果使用桶策略则需授予GetBucketInventoryConfiguration权限。相关授权方式介绍可参见OBS权限控制概述,配置方式详见使用IAM自定义策略、自定义创建桶策略。
- OBS支持的Region与Endpoint的对应关系,详细信息请参见地区与终端节点。
方法定义
1 | listBucketInventory(input: ListBucketInventoryInput): Response<ListBucketInventoryOutput> |
请求参数
| 参数名称 | 参数类型 | 是否必选 | 描述 |
|---|---|---|---|
| input | 必选 | 参数解释: 列举桶清单接口入参,详见ListBucketInventoryInput。 |
| 参数名称 | 参数类型 | 是否可选 | 描述 |
|---|---|---|---|
| Bucket | string | 必选 | 桶名。 约束限制:
取值范围: 长度为3~63个字符。 |
返回结果
| 参数名称 | 参数类型 | 描述 |
|---|---|---|
| CommonMsg | 参数解释: 接口调用完成后的公共信息,包含HTTP状态码,操作失败的错误码等,详见ICommonMsg。 | |
| InterfaceResult | 参数解释: 操作成功后的结果数据,详见ListBucketInventoryOutput。 约束限制: 当Status大于300时为空。 |
| 参数名称 | 参数类型 | 描述 |
|---|---|---|
| Status | number | 参数解释: OBS服务端返回的HTTP状态码。 取值范围: 状态码是一组从2xx(成功)到4xx或5xx(错误)的数字代码,状态码表示了请求响应的状态。完整的状态码列表请参见状态码。 |
| Code | string | 参数解释: OBS服务端返回的错误码。 |
| Message | string | 参数解释: OBS服务端返回的错误描述。 |
| HostId | string | 参数解释: OBS服务端返回的请求服务端ID。 |
| RequestId | string | 参数解释: OBS服务端返回的请求ID。 |
| Id2 | string | 参数解释: OBS服务端返回的请求ID2。 |
| Indicator | string | 参数解释: OBS服务端返回的详细错误码。 |
| 参数名称 | 参数类型 | 描述 |
|---|---|---|
| IsTruncated | boolean | 参数解释: 本次列举是否被截断。true表示结果不完整,需结合NextInventoryMarker继续列举。 |
| NextInventoryMarker | string | 参数解释:下次列举的起始位置,当IsTruncated为true时返回。 |
| Rules | 参数解释: 桶下全部清单规则列表。每项为一条清单规则,含规则ID、是否启用、过滤条件、清单周期、目标位置等字段。 |
| 参数名称 | 参数类型 | 描述 |
|---|---|---|
| Id | string | 参数解释: 清单规则 ID。 默认取值: 无。 |
| IsEnabled | boolean | 参数解释: 是否启用该清单规则。 默认取值: 无。 |
| Filter | 参数解释: 过滤条件,按对象名前缀筛选导出对象。 默认取值: 无。 | |
| Schedule | 参数解释: 清单导出周期。 默认取值: 无。 | |
| Destination | 参数解释: 清单导出目标位置。 默认取值: 无。 | |
| IncludedObjectVersions | 参数解释: 清单包含的对象版本。 默认取值: 无。 | |
| OptionalFields | 参数解释: 清单可选字段。 默认取值: 无。 |
| 常量名 | 原始值 | 说明 |
|---|---|---|
| DAILY | Daily | 每日导出一次清单。 |
| WEEKLY | Weekly | 每周导出一次清单。 |
代码示例
本示例用于列举名为 examplebucket 的桶下全部清单规则。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | // 引入依赖包 import ObsClient, { ListBucketInventoryInput } from '@obs/esdk-obs-harmony'; import { process } from '@kit.ArkTS'; import { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; const processManager = new process.ProcessManager(); // 创建ObsClient实例 const obsClient = new ObsClient({ // 推荐通过环境变量获取AKSK,这里也可以使用其他外部引入方式传入,如果使用硬编码可能会存在泄露风险 // 您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html AccessKeyId: processManager.getEnvironmentVar("ACCESS_KEY_ID"), SecretAccessKey: processManager.getEnvironmentVar("SECRET_ACCESS_KEY"), // 【可选】如果使用临时AK/SK和SecurityToken访问OBS,同样建议您尽量避免使用硬编码,以降低信息泄露风险。您可以通过环境变量获取访问密钥AK/SK,也可以使用其他外部引入方式传入 // SecurityToken: processManager.getEnvironmentVar("SECURITY_TOKEN"), // Server填写Bucket对应的Endpoint, 这里以华北-北京四为例,其他地区请按实际情况填写 Server: "https://obs.cn-north-4.myhuaweicloud.com", }); async function listBucketInventory() { try { const params: ListBucketInventoryInput = { Bucket: "examplebucket" }; const result = await obsClient.listBucketInventory(params); if (result.CommonMsg.Status < 300) { hilog.info(0x0001, 'OBS-Harmony', "List bucket(%s)'s inventory successful!", params.Bucket); const rules = result.InterfaceResult?.Rules ?? []; for (const rule of rules) { hilog.info(0x0001, 'OBS-Harmony', "Inventory rule id: %s, enabled: %s", rule.Id, rule.IsEnabled); } return; } hilog.error(0x0001, 'OBS-Harmony', "An ObsError was found, which means your request sent to OBS was rejected with an error response."); hilog.error(0x0001, 'OBS-Harmony', "Status: %d", result.CommonMsg.Status); hilog.error(0x0001, 'OBS-Harmony', "Code: %s", result.CommonMsg.Code); hilog.error(0x0001, 'OBS-Harmony', "Message: %s", result.CommonMsg.Message); hilog.error(0x0001, 'OBS-Harmony', "RequestId: %s", result.CommonMsg.RequestId); } catch (error) { const err = error as BusinessError; hilog.error(0x0001, 'OBS-Harmony', 'An Exception occurred: code=%d, message: %s', err.code, err.message); } } listBucketInventory(); |