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

Listing Bucket Inventory Rules

Function

The bucket inventory function periodically generates a list of object metadata information for a bucket, helping you better understand object statuses in the bucket. You can call this API to list all inventory rules of a bucket. All inventory rules are returned at a time without pagination.

To perform this operation, you must have the GetBucketInventoryConfiguration permission. By default, only the bucket owner can perform this operation. The bucket owner can grant the permission to other users by configuring the bucket policy or user policy.

For more information about permission control, see the permission control in the OBS Permission Configuration Guide.

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

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) ListBucketInventory(bucketName string, extensions ...extensionOptions) (output *ListBucketInventoryOutput, err error)

Request Parameters

Table 1 Request Parameters

Parameter

Type

Mandatory (Yes/No)

Description

bucketName

string

Yes

Bucket name.

Response Parameter Description

Table 2 ListBucketInventoryOutput parameters

Parameter

Type

Description

  

BaseModel

BaseModel

Basic model.

  

InventoryConfigurations

[]InventoryConfiguration

List of bucket inventory rules.

  
Table 3 BaseModel

Parameter

Type

Description

StatusCode

int

Explanation:

HTTP status code

Restrictions:

None

Value range:

A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. For more information, see Status Code.

Default value:

None

RequestId

string

Explanation:

Request ID returned by the OBS server

Restrictions:

None

Value range:

None

Default value:

None

ResponseHeaders

map[string][]string

Explanation:

HTTP response headers

Restrictions:

None

Value range:

None

Default value:

None

Table 4 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 5 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 6 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 7 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 8 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 lists all inventory rules 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())
    }
	// List all inventory rules.
	output, err := client.ListBucketInventory("my-bucket")
	if err != nil {
		log.Fatalf("Failed to list bucket inventory: %v", err)
	}

	fmt.Printf("Request ID: %s\n", output.RequestId)
	fmt.Printf("Total configurations: %d\n", len(output.InventoryConfigurations))

	for i, config := range output.InventoryConfigurations {
		fmt.Printf("\n[%d] Inventory Configuration:\n", i+1)
		fmt.Printf("  ID: %s\n", config.Id)
		fmt.Printf("  Enabled: %v\n", config.IsEnabled)
		fmt.Printf("  Frequency: %s\n", config.Schedule.Frequency)
		fmt.Printf("  Format: %s\n", config.Destination.Format)
		fmt.Printf("  Destination: %s/%s\n", config.Destination.Bucket, config.Destination.Prefix)

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

		fmt.Printf("  Included Versions: %s\n", config.IncludedObjectVersions)

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

	if output.IsTruncated {
		fmt.Printf("\nNote: Results truncated. NextId: %s\n", output.NextId)
	}
}