فهرست منبع

add bucket inventory api coded by zhanghang

taowei.wtw 6 سال پیش
والد
کامیت
7af5833a5a
8فایلهای تغییر یافته به همراه565 افزوده شده و 1 حذف شده
  1. 41 0
      oss/bucket_test.go
  2. 124 0
      oss/client.go
  3. 244 0
      oss/client_test.go
  4. 2 1
      oss/conn.go
  5. 49 0
      oss/type.go
  6. 1 0
      sample.go
  7. 102 0
      sample/bucket_inventory.go
  8. 2 0
      sample/config.go

+ 41 - 0
oss/bucket_test.go

@@ -3181,6 +3181,47 @@ func (s *OssBucketSuite) TestUploadFileMimeShtml(c *C) {
 	forceDeleteBucket(client, bucketName, c)
 	forceDeleteBucket(client, bucketName, c)
 }
 }
 
 
+func (s *OssBucketSuite) TestVersioningBucketVerison(c *C) {
+	// create a bucket with default proprety
+	client, err := New(endpoint, accessID, accessKey)
+	c.Assert(err, IsNil)
+
+	bucketName := bucketNamePrefix + randLowStr(6)
+	err = client.CreateBucket(bucketName)
+	c.Assert(err, IsNil)
+
+	// Get default bucket info
+	bucketResult, err := client.GetBucketInfo(bucketName)
+	c.Assert(err, IsNil)
+
+	c.Assert(bucketResult.BucketInfo.SseRule.KMSMasterKeyID, Equals, "")
+	c.Assert(bucketResult.BucketInfo.SseRule.SSEAlgorithm, Equals, "")
+	c.Assert(bucketResult.BucketInfo.Versioning, Equals, "")
+
+	// put bucket version:enabled
+	var respHeader http.Header
+	var versioningConfig VersioningConfig
+	versioningConfig.Status = string(VersionEnabled)
+	err = client.SetBucketVersioning(bucketName, versioningConfig, GetResponseHeader(&respHeader))
+	c.Assert(err, IsNil)
+	c.Assert(GetRequestId(respHeader) != "", Equals, true)
+
+	bucketResult, err = client.GetBucketInfo(bucketName)
+	c.Assert(err, IsNil)
+	c.Assert(bucketResult.BucketInfo.Versioning, Equals, string(VersionEnabled))
+
+	// put bucket version:Suspended
+	versioningConfig.Status = string(VersionSuspended)
+	err = client.SetBucketVersioning(bucketName, versioningConfig)
+	c.Assert(err, IsNil)
+
+	bucketResult, err = client.GetBucketInfo(bucketName)
+	c.Assert(err, IsNil)
+	c.Assert(bucketResult.BucketInfo.Versioning, Equals, string(VersionSuspended))
+
+	forceDeleteBucket(client, bucketName, c)
+}
+
 func (s *OssBucketSuite) TestVersioningPutAndGetObject(c *C) {
 func (s *OssBucketSuite) TestVersioningPutAndGetObject(c *C) {
 	// create a bucket with default proprety
 	// create a bucket with default proprety
 	client, err := New(endpoint, accessID, accessKey)
 	client, err := New(endpoint, accessID, accessKey)

+ 124 - 0
oss/client.go

@@ -1219,6 +1219,130 @@ func Timeout(connectTimeoutSec, readWriteTimeout int64) ClientOption {
 	}
 	}
 }
 }
 
 
+// SetBucketInventory API operation for Object Storage Service
+//
+// Set the Bucket inventory.
+//
+// bucketName tht bucket name.
+//
+// inventoryConfig the inventory configuration.
+//
+// error    it's nil if no error, otherwise it's an error.
+//
+func (client Client) SetBucketInventory(bucketName string, inventoryConfig InventoryConfiguration, options ...Option) error {
+	params := map[string]interface{}{}
+	params["inventoryId"] = inventoryConfig.Id
+	params["inventory"] = nil
+
+	var bs []byte
+	bs, err := xml.Marshal(inventoryConfig)
+
+	if err != nil {
+		return err
+	}
+
+	buffer := new(bytes.Buffer)
+	buffer.Write(bs)
+
+	contentType := http.DetectContentType(buffer.Bytes())
+	headers := make(map[string]string)
+	headers[HTTPHeaderContentType] = contentType
+
+	resp, err := client.do("PUT", bucketName, params, headers, buffer, options...)
+
+	if err != nil {
+		return err
+	}
+
+	defer resp.Body.Close()
+
+	return checkRespCode(resp.StatusCode, []int{http.StatusOK})
+}
+
+// GetBucketInventory API operation for Object Storage Service
+//
+// Get the Bucket inventory.
+//
+// bucketName tht bucket name.
+//
+// strInventoryId the inventory id.
+//
+// InventoryConfiguration the inventory configuration.
+//
+// error    it's nil if no error, otherwise it's an error.
+//
+func (client Client) GetBucketInventory(bucketName string, strInventoryId string, options ...Option) (InventoryConfiguration, error) {
+	var out InventoryConfiguration
+	params := map[string]interface{}{}
+	params["inventory"] = nil
+	params["inventoryId"] = strInventoryId
+
+	resp, err := client.do("GET", bucketName, params, nil, nil, options...)
+	if err != nil {
+		return out, err
+	}
+	defer resp.Body.Close()
+
+	err = xmlUnmarshal(resp.Body, &out)
+	return out, err
+}
+
+// ListBucketInventory API operation for Object Storage Service
+//
+// List the Bucket inventory.
+//
+// bucketName tht bucket name.
+//
+// continuationToken the users token.
+//
+// ListInventoryConfigurationsResult list all inventory configuration by .
+//
+// error    it's nil if no error, otherwise it's an error.
+//
+func (client Client) ListBucketInventory(bucketName, continuationToken string, options ...Option) (ListInventoryConfigurationsResult, error) {
+	var out ListInventoryConfigurationsResult
+	params := map[string]interface{}{}
+	params["inventory"] = nil
+	if continuationToken == "" {
+		params["continuation-token"] = nil
+	} else {
+		params["continuation-token"] = continuationToken
+	}
+
+	resp, err := client.do("GET", bucketName, params, nil, nil, options...)
+	if err != nil {
+		return out, err
+	}
+	defer resp.Body.Close()
+
+	err = xmlUnmarshal(resp.Body, &out)
+	return out, err
+}
+
+// DeleteBucketInventory API operation for Object Storage Service.
+//
+// Delete Bucket inventory information.
+//
+// bucketName tht bucket name.
+//
+// strInventoryId the inventory id.
+//
+// error    it's nil if no error, otherwise it's an error.
+//
+func (client Client) DeleteBucketInventory(bucketName, strInventoryId string, options ...Option) error {
+	params := map[string]interface{}{}
+	params["inventory"] = nil
+	params["inventoryId"] = strInventoryId
+
+	resp, err := client.do("DELETE", bucketName, params, nil, nil, options...)
+	if err != nil {
+		return err
+	}
+	defer resp.Body.Close()
+
+	return checkRespCode(resp.StatusCode, []int{http.StatusNoContent})
+}
+
 // SecurityToken sets the temporary user's SecurityToken.
 // SecurityToken sets the temporary user's SecurityToken.
 //
 //
 // token    STS token
 // token    STS token

+ 244 - 0
oss/client_test.go

@@ -37,6 +37,7 @@ var (
 	endpoint  = os.Getenv("OSS_TEST_ENDPOINT")
 	endpoint  = os.Getenv("OSS_TEST_ENDPOINT")
 	accessID  = os.Getenv("OSS_TEST_ACCESS_KEY_ID")
 	accessID  = os.Getenv("OSS_TEST_ACCESS_KEY_ID")
 	accessKey = os.Getenv("OSS_TEST_ACCESS_KEY_SECRET")
 	accessKey = os.Getenv("OSS_TEST_ACCESS_KEY_SECRET")
+	accountID = os.Getenv("OSS_TEST_ACCOUNT_ID")
 
 
 	// Proxy
 	// Proxy
 	proxyHost   = os.Getenv("OSS_TEST_PROXY_HOST")
 	proxyHost   = os.Getenv("OSS_TEST_PROXY_HOST")
@@ -3080,3 +3081,246 @@ func (s *OssClientSuite) TestClientBucketError(c *C) {
 	_, err = client.Bucket(bucketName)
 	_, err = client.Bucket(bucketName)
 	c.Assert(err, NotNil)
 	c.Assert(err, NotNil)
 }
 }
+
+func (s *OssClientSuite) TestSetBucketInventory(c *C) {
+	client, err := New(endpoint, accessID, accessKey)
+	c.Assert(err, IsNil)
+
+	bucketName := bucketNamePrefix + randLowStr(5)
+	err = client.CreateBucket(bucketName)
+	c.Assert(err, IsNil)
+
+	// encryption config
+	var invSseOss InvSseOss
+	invSseKms := InvSseKms{
+		KmsId: "keyId",
+	}
+	var invEncryption InvEncryption
+
+	bl := true
+	// not any encryption
+	invConfig := InventoryConfiguration{
+		Id:        "report1",
+		IsEnabled: &bl,
+		Prefix:    "filterPrefix/",
+		OSSBucketDestination: OSSBucketDestination{
+			Format:    "CSV",
+			AccountId: accountID,
+			RoleArn:   stsARN,
+			Bucket:    "acs:oss:::" + bucketName,
+			Prefix:    "prefix1",
+		},
+		Frequency:              "Daily",
+		IncludedObjectVersions: "All",
+		OptionalFields: OptionalFields{
+			Field: []string{
+				"Size", "LastModifiedDate", "ETag", "StorageClass", "IsMultipartUploaded", "EncryptionStatus",
+			},
+		},
+	}
+
+	// case 1: not any encryption
+	err = client.SetBucketInventory(bucketName, invConfig)
+	c.Assert(err, IsNil)
+
+	// case 2: use kms encryption
+	invConfig.Id = "report2"
+	invEncryption.SseKms = &invSseKms
+	invEncryption.SseOss = nil
+	invConfig.OSSBucketDestination.Encryption = &invEncryption
+	err = client.SetBucketInventory(bucketName, invConfig)
+	c.Assert(err, IsNil)
+
+	// case 3: use SseOss encryption
+	invConfig.Id = "report3"
+	invEncryption.SseKms = nil
+	invEncryption.SseOss = &invSseOss
+	invConfig.OSSBucketDestination.Encryption = &invEncryption
+	err = client.SetBucketInventory(bucketName, invConfig)
+	c.Assert(err, IsNil)
+
+	//case 4: use two type encryption
+	invConfig.Id = "report4"
+	invEncryption.SseKms = &invSseKms
+	invEncryption.SseOss = &invSseOss
+	invConfig.OSSBucketDestination.Encryption = &invEncryption
+	err = client.SetBucketInventory(bucketName, invConfig)
+	c.Assert(err, NotNil)
+
+	err = client.DeleteBucket(bucketName)
+	c.Assert(err, IsNil)
+}
+
+func (s *OssClientSuite) TestBucketInventory(c *C) {
+	client, err := New(endpoint, accessID, accessKey)
+	c.Assert(err, IsNil)
+
+	bucketName := bucketNamePrefix + randLowStr(5)
+	err = client.CreateBucket(bucketName)
+	c.Assert(err, IsNil)
+
+	bl := true
+	invConfig := InventoryConfiguration{
+		Id:        "report1",
+		IsEnabled: &bl,
+		Prefix:    "filterPrefix/",
+		OSSBucketDestination: OSSBucketDestination{
+			Format:    "CSV",
+			AccountId: accountID,
+			RoleArn:   stsARN,
+			Bucket:    "acs:oss:::" + bucketName,
+			Prefix:    "prefix1",
+		},
+		Frequency:              "Daily",
+		IncludedObjectVersions: "All",
+		OptionalFields: OptionalFields{
+			Field: []string{
+				"Size", "LastModifiedDate", "ETag", "StorageClass", "IsMultipartUploaded", "EncryptionStatus",
+			},
+		},
+	}
+
+	// case 1: test SetBucketInventory
+	err = client.SetBucketInventory(bucketName, invConfig)
+	c.Assert(err, IsNil)
+
+	// case 2: test GetBucketInventory
+	out, err := client.GetBucketInventory(bucketName, "report1")
+	c.Assert(err, IsNil)
+	invConfig.XMLName.Local = "InventoryConfiguration"
+	invConfig.OSSBucketDestination.XMLName.Local = "OSSBucketDestination"
+	invConfig.OptionalFields.XMLName.Local = "OptionalFields"
+	c.Assert(struct2string(invConfig, c), Equals, struct2string(out, c))
+
+	// case 3: test ListBucketInventory
+	invConfig2 := InventoryConfiguration{
+		Id:        "report2",
+		IsEnabled: &bl,
+		Prefix:    "filterPrefix/",
+		OSSBucketDestination: OSSBucketDestination{
+			Format:    "CSV",
+			AccountId: accountID,
+			RoleArn:   stsARN,
+			Bucket:    "acs:oss:::" + bucketName,
+			Prefix:    "prefix1",
+		},
+		Frequency:              "Daily",
+		IncludedObjectVersions: "All",
+		OptionalFields: OptionalFields{
+			Field: []string{
+				"Size", "LastModifiedDate", "ETag", "StorageClass", "IsMultipartUploaded", "EncryptionStatus",
+			},
+		},
+	}
+	invConfig2.XMLName.Local = "InventoryConfiguration"
+	invConfig2.OSSBucketDestination.XMLName.Local = "OSSBucketDestination"
+	invConfig2.OptionalFields.XMLName.Local = "OptionalFields"
+
+	err = client.SetBucketInventory(bucketName, invConfig2)
+	c.Assert(err, IsNil)
+
+	listInvConf, err := client.ListBucketInventory(bucketName, "", Marker("report1"), MaxKeys(2))
+	c.Assert(err, IsNil)
+	var listInvLocal ListInventoryConfigurationsResult
+	listInvLocal.InventoryConfiguration = []InventoryConfiguration{
+		invConfig,
+		invConfig2,
+	}
+	bo := false
+	listInvLocal.IsTruncated = &bo
+	listInvLocal.XMLName.Local = "ListInventoryConfigurationsResult"
+	c.Assert(struct2string(listInvLocal, c), Equals, struct2string(listInvConf, c))
+
+	for i := 3; i < 109; i++ {
+		invConfig2 := InventoryConfiguration{
+			Id:        "report" + strconv.Itoa(i),
+			IsEnabled: &bl,
+			Prefix:    "filterPrefix/",
+			OSSBucketDestination: OSSBucketDestination{
+				Format:    "CSV",
+				AccountId: accountID,
+				RoleArn:   stsARN,
+				Bucket:    "acs:oss:::" + bucketName,
+				Prefix:    "prefix1",
+			},
+			Frequency:              "Daily",
+			IncludedObjectVersions: "All",
+			OptionalFields: OptionalFields{
+				Field: []string{
+					"Size", "LastModifiedDate", "ETag", "StorageClass", "IsMultipartUploaded", "EncryptionStatus",
+				},
+			},
+		}
+		err = client.SetBucketInventory(bucketName, invConfig2)
+		c.Assert(err, IsNil)
+	}
+	token := ""
+	for {
+		listInvConf1, err := client.ListBucketInventory(bucketName, token)
+		c.Assert(err, IsNil)
+		token = listInvConf1.NextContinuationToken
+		testLogger.Println(listInvConf1.NextContinuationToken, *listInvConf1.IsTruncated, token)
+		if *listInvConf1.IsTruncated == false {
+			break
+		} else {
+			c.Assert(listInvConf1.NextContinuationToken, Equals, "report91")
+		}
+	}
+
+	// case 4: test DeleteBucketInventory
+	for i := 1; i < 109; i++ {
+		err = client.DeleteBucketInventory(bucketName, "report"+strconv.Itoa(i))
+		c.Assert(err, IsNil)
+	}
+
+	err = client.DeleteBucket(bucketName)
+	c.Assert(err, IsNil)
+}
+
+func (s *OssClientSuite) TestBucketInventoryNegative(c *C) {
+	client, err := New(endpoint, accessID, accessKey)
+	c.Assert(err, IsNil)
+
+	bucketName := bucketNamePrefix + randLowStr(5)
+	err = client.CreateBucket(bucketName)
+	c.Assert(err, IsNil)
+
+	bl := true
+	invConfigErr := InventoryConfiguration{
+		Id:        "report1",
+		IsEnabled: &bl,
+		Prefix:    "filterPrefix/",
+		OSSBucketDestination: OSSBucketDestination{
+			Format:    "CSV",
+			AccountId: accountID,
+			RoleArn:   stsARN,
+			Bucket:    "test",
+			Prefix:    "prefix1",
+		},
+		Frequency:              "Daily",
+		IncludedObjectVersions: "All",
+		OptionalFields: OptionalFields{
+			Field: []string{
+				"Size", "LastModifiedDate", "ETag", "StorageClass", "IsMultipartUploaded", "EncryptionStatus",
+			},
+		},
+	}
+	// case 1: test SetBucketInventory
+	err = client.SetBucketInventory(bucketName, invConfigErr)
+	c.Assert(err, NotNil)
+
+	// case 2: test GetBucketInventory
+	_, err = client.GetBucketInventory(bucketName, "report1")
+	c.Assert(err, NotNil)
+
+	// case 3: test ListBucketInventory
+	_, err = client.ListBucketInventory(bucketName, "", Marker("report1"), MaxKeys(2))
+	c.Assert(err, NotNil)
+
+	// case 4: test DeleteBucketInventory
+	err = client.DeleteBucketInventory(bucketName, "report1")
+	c.Assert(err, IsNil)
+
+	err = client.DeleteBucket(bucketName)
+	c.Assert(err, IsNil)
+}

+ 2 - 1
oss/conn.go

@@ -43,7 +43,8 @@ var signKeyList = []string{"acl", "uploads", "location", "cors",
 	"udfId", "udfImageDesc", "udfApplication", "comp",
 	"udfId", "udfImageDesc", "udfApplication", "comp",
 	"udfApplicationLog", "restore", "callback", "callback-var", "qosInfo",
 	"udfApplicationLog", "restore", "callback", "callback-var", "qosInfo",
 	"policy", "stat", "encryption", "versions", "versioning", "versionId", "requestPayment",
 	"policy", "stat", "encryption", "versions", "versioning", "versionId", "requestPayment",
-	"x-oss-request-payer", "sequential"}
+	"x-oss-request-payer", "sequential",
+	"inventory", "inventoryId", "continuation-token"}
 
 
 // init initializes Conn
 // init initializes Conn
 func (conn *Conn) init(config *Config, urlMaker *urlMaker, client *http.Client) error {
 func (conn *Conn) init(config *Config, urlMaker *urlMaker, client *http.Client) error {

+ 49 - 0
oss/type.go

@@ -1078,3 +1078,52 @@ type MetaEndFrameJSON struct {
 	RowsCount    int64
 	RowsCount    int64
 	ErrorMsg     string
 	ErrorMsg     string
 }
 }
+
+// InventoryConfiguration is Inventory config
+type InventoryConfiguration struct {
+	XMLName                xml.Name             `xml:"InventoryConfiguration"`
+	Id                     string               `xml:"Id,omitempty"`
+	IsEnabled              *bool                `xml:"IsEnabled,omitempty"`
+	Prefix                 string               `xml:"Filter>Prefix,omitempty"`
+	OSSBucketDestination   OSSBucketDestination `xml:"Destination>OSSBucketDestination,omitempty"`
+	Frequency              string               `xml:"Schedule>Frequency,omitempty"`
+	IncludedObjectVersions string               `xml:"IncludedObjectVersions,omitempty"`
+	OptionalFields         OptionalFields       `xml:OptionalFields,omitempty`
+}
+
+type OptionalFields struct {
+	XMLName xml.Name `xml:"OptionalFields,omitempty`
+	Field   []string `xml:"Field,omitempty`
+}
+
+type OSSBucketDestination struct {
+	XMLName    xml.Name       `xml:"OSSBucketDestination"`
+	Format     string         `xml:"Format,omitempty"`
+	AccountId  string         `xml:"AccountId,omitempty"`
+	RoleArn    string         `xml:"RoleArn,omitempty"`
+	Bucket     string         `xml:"Bucket,omitempty"`
+	Prefix     string         `xml:"Prefix,omitempty"`
+	Encryption *InvEncryption `xml:"Encryption,omitempty"`
+}
+
+type InvEncryption struct {
+	XMLName xml.Name   `xml:"Encryption"`
+	SseOss  *InvSseOss `xml:"SSE-OSS"`
+	SseKms  *InvSseKms `xml:"SSE-KMS"`
+}
+
+type InvSseOss struct {
+	XMLName xml.Name `xml:"SSE-OSS"`
+}
+
+type InvSseKms struct {
+	XMLName xml.Name `xml:"SSE-KMS"`
+	KmsId   string   `xml:"KeyId,omitempty"`
+}
+
+type ListInventoryConfigurationsResult struct {
+	XMLName                xml.Name                 `xml:"ListInventoryConfigurationsResult"`
+	InventoryConfiguration []InventoryConfiguration `xml:"InventoryConfiguration,omitempty`
+	IsTruncated            *bool                    `xml:"IsTruncated,omitempty"`
+	NextContinuationToken  string                   `xml:"NextContinuationToken,omitempty"`
+}

+ 1 - 0
sample.go

@@ -24,6 +24,7 @@ var sampleMap = map[string]interface{}{
 	"BucketPolicySample":          sample.BucketPolicySample,
 	"BucketPolicySample":          sample.BucketPolicySample,
 	"BucketrRequestPaymentSample": sample.BucketrRequestPaymentSample,
 	"BucketrRequestPaymentSample": sample.BucketrRequestPaymentSample,
 	"BucketQoSInfoSample":         sample.BucketQoSInfoSample,
 	"BucketQoSInfoSample":         sample.BucketQoSInfoSample,
+	"BucketInventorySample":       sample.BucketInventorySample,
 	"ObjectACLSample":             sample.ObjectACLSample,
 	"ObjectACLSample":             sample.ObjectACLSample,
 	"ObjectMetaSample":            sample.ObjectMetaSample,
 	"ObjectMetaSample":            sample.ObjectMetaSample,
 	"ListObjectsSample":           sample.ListObjectsSample,
 	"ListObjectsSample":           sample.ListObjectsSample,

+ 102 - 0
sample/bucket_inventory.go

@@ -0,0 +1,102 @@
+package sample
+
+import (
+	"fmt"
+
+	"github.com/aliyun/aliyun-oss-go-sdk/oss"
+)
+
+// BucketInventorySample shows how to set, get, list and delete the bucket inventory configuration
+func BucketInventorySample() {
+	// New client
+	client, err := oss.New(endpoint, accessID, accessKey)
+	if err != nil {
+		HandleError(err)
+	}
+
+	// Create the bucket with default parameters
+	err = client.CreateBucket(bucketName)
+	if err != nil {
+		HandleError(err)
+	}
+
+	// the inventory configuration,not use any encryption
+	bl := true
+	invConfig := oss.InventoryConfiguration{
+		Id:        "report1",
+		IsEnabled: &bl,
+		Prefix:    "filterPrefix/",
+		OSSBucketDestination: oss.OSSBucketDestination{
+			Format:    "CSV",
+			AccountId: accountID,
+			RoleArn:   stsARN,
+			Bucket:    "acs:oss:::" + bucketName,
+			Prefix:    "prefix1",
+		},
+		Frequency:              "Daily",
+		IncludedObjectVersions: "All",
+		OptionalFields: oss.OptionalFields{
+			Field: []string{
+				"Size", "LastModifiedDate", "ETag", "StorageClass", "IsMultipartUploaded", "EncryptionStatus",
+			},
+		},
+	}
+
+	// case 1: Set inventory
+	err = client.SetBucketInventory(bucketName, invConfig)
+	if err != nil {
+		HandleError(err)
+	}
+
+	// case 2: Get Bucket inventory
+	ret, err := client.GetBucketInventory(bucketName, invConfig.Id)
+	if err != nil {
+		HandleError(err)
+	}
+	fmt.Println("Bucket inventory:", ret)
+
+	// case 3: List Bucket inventory
+	invConfig2 := oss.InventoryConfiguration{
+		Id:        "report2",
+		IsEnabled: &bl,
+		Prefix:    "filterPrefix/",
+		OSSBucketDestination: oss.OSSBucketDestination{
+			Format:    "CSV",
+			AccountId: accountID,
+			RoleArn:   stsARN,
+			Bucket:    "acs:oss:::" + bucketName,
+			Prefix:    "prefix1",
+		},
+		Frequency:              "Daily",
+		IncludedObjectVersions: "All",
+		OptionalFields: oss.OptionalFields{
+			Field: []string{
+				"Size", "LastModifiedDate", "ETag", "StorageClass", "IsMultipartUploaded", "EncryptionStatus",
+			},
+		},
+	}
+	err = client.SetBucketInventory(bucketName, invConfig2)
+	if err != nil {
+		HandleError(err)
+	}
+	NextContinuationToken := ""
+	listInvConf, err := client.ListBucketInventory(bucketName, NextContinuationToken)
+	if err != nil {
+		HandleError(err)
+	}
+	fmt.Println("Bucket inventory list:", listInvConf)
+
+	// case 4: Delete Bucket inventory
+	err = client.DeleteBucketInventory(bucketName, invConfig.Id)
+	if err != nil {
+		HandleError(err)
+	}
+
+	// Delete bucket
+	err = client.DeleteBucket(bucketName)
+	if err != nil {
+		HandleError(err)
+	}
+
+	fmt.Println("BucketInventorySample completed")
+}

+ 2 - 0
sample/config.go

@@ -9,6 +9,8 @@ var (
 	accessKey  = os.Getenv("OSS_TEST_ACCESS_KEY_SECRET")
 	accessKey  = os.Getenv("OSS_TEST_ACCESS_KEY_SECRET")
 	bucketName = os.Getenv("OSS_TEST_BUCKET")
 	bucketName = os.Getenv("OSS_TEST_BUCKET")
 	kmsID      = os.Getenv("OSS_TEST_KMS_ID")
 	kmsID      = os.Getenv("OSS_TEST_KMS_ID")
+	accountID  = os.Getenv("OSS_TEST_ACCOUNT_ID")
+	stsARN     = os.Getenv("OSS_TEST_STS_ARN")
 
 
 	// Credential
 	// Credential
 	credentialAccessID  = os.Getenv("OSS_CREDENTIAL_KEY_ID")
 	credentialAccessID  = os.Getenv("OSS_CREDENTIAL_KEY_ID")