You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
4.7 KiB

  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "fmt"
  6. "net/http"
  7. )
  8. // Notice bucket_inventory only for test. can not use
  9. // BucketGetInventoryResult same struct to options
  10. type BucketGetInventoryResult BucketPutInventoryOptions
  11. // BucketListInventoryConfiguartion same struct to options
  12. type BucketListInventoryConfiguartion BucketPutInventoryOptions
  13. // BucketInventoryFilter ...
  14. type BucketInventoryFilter struct {
  15. Prefix string `xml:"Prefix,omitempty"`
  16. }
  17. // BucketInventoryOptionalFields ...
  18. type BucketInventoryOptionalFields struct {
  19. XMLName xml.Name `xml:"OptionalFields,omitempty"`
  20. BucketInventoryFields []string `xml:"Field,omitempty"`
  21. }
  22. // BucketInventorySchedule ...
  23. type BucketInventorySchedule struct {
  24. Frequency string `xml:"Frequency"`
  25. }
  26. // BucketInventoryEncryption ...
  27. type BucketInventoryEncryption struct {
  28. XMLName xml.Name `xml:"Encryption"`
  29. SSECOS string `xml:"SSE-COS,omitempty"`
  30. }
  31. // BucketInventoryDestinationContent ...
  32. type BucketInventoryDestinationContent struct {
  33. Bucket string `xml:"Bucket"`
  34. AccountId string `xml:"AccountId,omitempty"`
  35. Prefix string `xml:"Prefix,omitempty"`
  36. Format string `xml:"Format"`
  37. Encryption *BucketInventoryEncryption `xml:"Encryption,omitempty"`
  38. }
  39. // BucketInventoryDestination ...
  40. type BucketInventoryDestination struct {
  41. XMLName xml.Name `xml:"Destination"`
  42. BucketDestination *BucketInventoryDestinationContent `xml:"COSBucketDestination"`
  43. }
  44. // BucketPutInventoryOptions ...
  45. type BucketPutInventoryOptions struct {
  46. XMLName xml.Name `xml:"InventoryConfiguration"`
  47. ID string `xml:"Id"`
  48. IsEnabled string `xml:"IsEnabled"`
  49. IncludedObjectVersions string `xml:"IncludedObjectVersions"`
  50. Filter *BucketInventoryFilter `xml:"Filter,omitempty"`
  51. OptionalFields *BucketInventoryOptionalFields `xml:"OptionalFields,omitempty"`
  52. Schedule *BucketInventorySchedule `xml:"Schedule"`
  53. Destination *BucketInventoryDestination `xml:"Destination"`
  54. }
  55. // ListBucketInventoryConfigResult result of ListBucketInventoryConfiguration
  56. type ListBucketInventoryConfigResult struct {
  57. XMLName xml.Name `xml:"ListInventoryConfigurationResult"`
  58. InventoryConfigurations []BucketListInventoryConfiguartion `xml:"InventoryConfiguration,omitempty"`
  59. IsTruncated bool `xml:"IsTruncated,omitempty"`
  60. ContinuationToken string `xml:"ContinuationToken,omitempty"`
  61. NextContinuationToken string `xml:"NextContinuationToken,omitempty"`
  62. }
  63. // PutBucketInventory https://cloud.tencent.com/document/product/436/33707
  64. func (s *BucketService) PutBucketInventoryTest(ctx context.Context, id string, opt *BucketPutInventoryOptions) (*Response, error) {
  65. u := fmt.Sprintf("/?inventory&id=%s", id)
  66. sendOpt := sendOptions{
  67. baseURL: s.client.BaseURL.BucketURL,
  68. uri: u,
  69. method: http.MethodPut,
  70. body: opt,
  71. }
  72. resp, err := s.client.send(ctx, &sendOpt)
  73. return resp, err
  74. }
  75. // GetBucketInventory https://cloud.tencent.com/document/product/436/33705
  76. func (s *BucketService) GetBucketInventoryTest(ctx context.Context, id string) (*BucketGetInventoryResult, *Response, error) {
  77. u := fmt.Sprintf("/?inventory&id=%s", id)
  78. var res BucketGetInventoryResult
  79. sendOpt := sendOptions{
  80. baseURL: s.client.BaseURL.BucketURL,
  81. uri: u,
  82. method: http.MethodGet,
  83. result: &res,
  84. }
  85. resp, err := s.client.send(ctx, &sendOpt)
  86. return &res, resp, err
  87. }
  88. // DeleteBucketInventory https://cloud.tencent.com/document/product/436/33704
  89. func (s *BucketService) DeleteBucketInventoryTest(ctx context.Context, id string) (*Response, error) {
  90. u := fmt.Sprintf("/?inventory&id=%s", id)
  91. sendOpt := sendOptions{
  92. baseURL: s.client.BaseURL.BucketURL,
  93. uri: u,
  94. method: http.MethodDelete,
  95. }
  96. resp, err := s.client.send(ctx, &sendOpt)
  97. return resp, err
  98. }
  99. // ListBucketInventoryConfigurations https://cloud.tencent.com/document/product/436/33706
  100. func (s *BucketService) ListBucketInventoryConfigurationsTest(ctx context.Context, token string) (*ListBucketInventoryConfigResult, *Response, error) {
  101. var res ListBucketInventoryConfigResult
  102. var u string
  103. if token == "" {
  104. u = "/?inventory"
  105. } else {
  106. u = fmt.Sprintf("/?inventory&continuation-token=%s", encodeURIComponent(token))
  107. }
  108. sendOpt := sendOptions{
  109. baseURL: s.client.BaseURL.BucketURL,
  110. uri: u,
  111. method: http.MethodGet,
  112. result: &res,
  113. }
  114. resp, err := s.client.send(ctx, &sendOpt)
  115. return &res, resp, err
  116. }