Updated on 2026-08-14 GMT+08:00

Obtaining a Bucket Inventory Rule

Function

OBS uses the GET method to obtain a specific inventory of a bucket. To perform this operation, you must have the GetBucketInventoryConfiguration permission. By default, the bucket owner has this permission and can grant it to others.

For fusion buckets, inventory rules can be configured for an active bucket, but cannot be configured for a standby bucket.

Authorization Information

To call this API, you must be the bucket owner or have the permissions to obtain bucket inventory rules. You are advised to use IAM or bucket policies for authorization. For details about OBS authorization methods, see Differences Between OBS Permissions Control Methods.

  • If you use IAM for authorization, you need to use either role/policy-based authorization or identity policy-based authorization and configure the required permission:
    • If you use role/policy-based authorization (IAM v3 APIs in the old IAM version), the obs:bucket:GetBucketInventoryConfiguration permission is required. For details, see Creating a Custom IAM Policy.
    • If you use identity policy-based authorization (IAM v5 APIs in the new IAM version), as shown in the following table, the obs:bucket:getBucketInventoryConfiguration permission is required. For details, see Creating a Custom IAM Identity Policy.

      Action

      Action

      Access Level

      Access Level

      Resource Type (*: required)

      Resource Type (*: required)

      Condition Key

      Condition Key

      AliasAlias

      Alias

      Dependency

      Dependencies

      obs:bucket:getBucketInventoryConfiguration

      Read

      bucket *

      -

      -

      -

      • obs:EpochTime
      • obs:SourceIp
      • obs:TlsVersion
      • obs:CustomDomain
  • If you use bucket policies for authorization, the obs:bucket:GetBucketInventoryConfiguration permission is required. For details, see Creating a Custom Bucket Policy.

Restrictions

  • The mapping between OBS regions and endpoints must comply with what is listed in Regions and Endpoints.
  • Before calling APIs related to bucket inventories, you need to call obs.WithSignature(obs.SignatureObs) to specify the protocol type when initializing the obsClient.

Method

func (obsClient ObsClient) GetBucketInventory(input *GetBucketInventoryInput, extensions ...extensionOptions) (output *GetBucketInventoryOutput, err error)

Request Parameters

Table 1 GetBucketInventoryInput parameters

Parameter

Type

Mandatory (Yes/No)

Description

Bucket

string

Yes

Explanation:

Bucket name.

Value range:

None

Id

string

Yes

Explanation:

Inventory rule ID.

Value range:

The value can contain a maximum of 64 bytes, including letters (a–z and A–Z), digits (0–9), hyphens (-), underscores (_), and periods (.).

Response Parameter Description

Table 2 GetBucketInventoryOutput parameters

Parameter

Type

Description

BaseModel

BaseModel

Explanation:

Basic model, including RequestId.

Value range:

None

InventoryConfiguration

InventoryConfiguration

Explanation:

Inventory configuration details.

Value range:

None

Table 3 InventoryConfiguration parameters

Field

Type

Description

Id

string

Explanation:

Inventory rule ID.

Value range:

None

IsEnabled

bool

Explanation:

Whether the inventory rule is enabled. If this parameter is set to true, inventory files will be generated. If not, inventory files will not be generated.

Value range:

  • true: Inventory files will be generated.
  • false: Inventory files will not be generated.

Destination

InventoryDestination

Explanation:

Destination configuration of an inventory.

Value range:

None

Schedule

InventorySchedule

Explanation:

Inventory generation frequency.

Value range:

None

Filter

*InventoryFilter

Explanation:

Inventory filter configuration. The inventory contains only objects that meet the filter criteria (filtering by object name prefix). If no filter criteria are configured, all objects are included.

Value range:

None

IncludedObjectVersions

string

Explanation:

Whether versions of objects are included in an inventory.

Value range:

  • All: Versioning related fields including VersionId, IsLatest, and DeleteMarker will appear in inventory files, and information about all object versions will be included.
  • Current: Versioning related fields including VersionId, IsLatest, and DeleteMarker will not appear in inventory files, and only information about the current object version will be included.

OptionalFields

*InventoryOptionalFields

Explanation:

Additional object metadata fields that are contained in an inventory file.

Value range:

None

Table 4 InventoryDestination parameters

Parameter

Type

Mandatory (Yes/No)

Description

Format

string

Yes

Inventory file format. Only the CSV format is supported.

Bucket

string

Yes

Name of the bucket for storing inventories.

Prefix

string

Yes

Name prefix for inventory files. If no prefix is configured, the inventory file names will start with the BucketInventory prefix by default.

Table 5 InventorySchedule parameters

Parameter

Type

Mandatory (Yes/No)

Description

Frequency

string

Yes

The intervals at which inventories are generated. You can set it to Daily or Weekly. An inventory is generated within one hour after it is configured for the first time, and subsequently at the specified intervals.

Valid values: Daily, Weekly

Table 6 InventoryFilter parameters

Parameter

Type

Mandatory (Yes/No)

Description

Prefix

string

No

Prefix for filtering objects. Only objects with the specified name prefix are included in the inventory.

Table 7 InventoryOptionalFields parameters

Parameter

Type

Mandatory (Yes/No)

Description

Fields

[]string

No

List of optional fields. Valid values are as follows:

Size, LastModifiedDate, StorageClass, ETag, IsMultipartUploaded, ReplicationStatus, EncryptionStatus

Sample Code

This example queries the inventory rule with ID inventory-rule-1 configured for bucket examplebucket.

package main

import (
	"fmt"
	"log"

        obs "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs"
)

func main() {
    // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
    // Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
        ak := os.Getenv("AccessKeyID")
        sk := os.Getenv("SecretAccessKey")
    // (Optional) If you use a temporary AK/SK pair and a security token to access OBS, you are not advised to use hard coding, which may result in information leakage. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
    securityToken := os.Getenv("SecurityToken")


    // Enter the endpoint corresponding to the bucket. CN-Hong Kong is used here as an example. Replace it with the one currently in use.
    endPoint := "https://obs.ap-southeast-1.myhuaweicloud.com"




	// Create a client.
    obsClient, err := obs.New(ak, sk, endPoint, obs.WithSecurityToken(securityToken))
    if err != nil {
        fmt.Printf("Create obsClient error, errMsg: %s", err.Error())
    }

	// Obtain the inventory configuration.
	input := &obs.GetBucketInventoryInput{
		Bucket: "examplebucket",
		Id:     "inventory-rule-1",
	}

	output, err := client.GetBucketInventory(input)
	if err != nil {
		log.Fatalf("Failed to get bucket inventory: %v", err)
	}

	fmt.Printf("Request ID: %s\n", output.RequestId)
	fmt.Printf("Inventory ID: %s\n", output.Id)
	fmt.Printf("Enabled: %v\n", output.IsEnabled)
	fmt.Printf("Frequency: %s\n", output.Schedule.Frequency)
	fmt.Printf("Format: %s\n", output.Destination.Format)
	fmt.Printf("Destination Bucket: %s\n", output.Destination.Bucket)
	fmt.Printf("Prefix: %s\n", output.Destination.Prefix)

	if output.Filter != nil {
		fmt.Printf("Filter Prefix: %s\n", output.Filter.Prefix)
	}

	if output.OptionalFields != nil {
		fmt.Printf("Optional Fields: %v\n", output.OptionalFields.Fields)
	}
}