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.

126 lines
4.3 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. BucketInventoryFields []string `xml:"Field,omitempty"`
  20. }
  21. // BucketInventorySchedule ...
  22. type BucketInventorySchedule struct {
  23. Frequency string `xml:"Frequency"`
  24. }
  25. // BucketInventoryEncryption ...
  26. type BucketInventoryEncryption struct {
  27. SSECOS string `xml:"SSE-COS"`
  28. }
  29. // BucketInventoryDestination ...
  30. type BucketInventoryDestination struct {
  31. Bucket string `xml:"Bucket"`
  32. AccountId string `xml:"AccountId,omitempty"`
  33. Prefix string `xml:"Prefix,omitempty"`
  34. Format string `xml:"Format"`
  35. Encryption *BucketInventoryEncryption `xml:"Encryption,omitempty"`
  36. }
  37. // BucketPutInventoryOptions ...
  38. type BucketPutInventoryOptions struct {
  39. XMLName xml.Name `xml:"InventoryConfiguration"`
  40. ID string `xml:"Id"`
  41. IsEnabled string `xml:"IsEnabled"`
  42. IncludedObjectVersions string `xml:"IncludedObjectVersions"`
  43. Filter *BucketInventoryFilter `xml:"Filter,omitempty"`
  44. OptionalFields *BucketInventoryOptionalFields `xml:"OptionalFields,omitempty"`
  45. Schedule *BucketInventorySchedule `xml:"Schedule"`
  46. Destination *BucketInventoryDestination `xml:"Destination>COSBucketDestination"`
  47. }
  48. // ListBucketInventoryConfigResult result of ListBucketInventoryConfiguration
  49. type ListBucketInventoryConfigResult struct {
  50. XMLName xml.Name `xml:"ListInventoryConfigurationResult"`
  51. InventoryConfigurations []BucketListInventoryConfiguartion `xml:"InventoryConfiguration,omitempty"`
  52. IsTruncated bool `xml:"IsTruncated,omitempty"`
  53. ContinuationToken string `xml:"ContinuationToken,omitempty"`
  54. NextContinuationToken string `xml:"NextContinuationToken,omitempty"`
  55. }
  56. // PutBucketInventory https://cloud.tencent.com/document/product/436/33707
  57. func (s *BucketService) PutInventory(ctx context.Context, id string, opt *BucketPutInventoryOptions) (*Response, error) {
  58. u := fmt.Sprintf("/?inventory&id=%s", id)
  59. sendOpt := sendOptions{
  60. baseURL: s.client.BaseURL.BucketURL,
  61. uri: u,
  62. method: http.MethodPut,
  63. body: opt,
  64. }
  65. resp, err := s.client.send(ctx, &sendOpt)
  66. return resp, err
  67. }
  68. // GetBucketInventory https://cloud.tencent.com/document/product/436/33705
  69. func (s *BucketService) GetInventory(ctx context.Context, id string) (*BucketGetInventoryResult, *Response, error) {
  70. u := fmt.Sprintf("/?inventory&id=%s", id)
  71. var res BucketGetInventoryResult
  72. sendOpt := sendOptions{
  73. baseURL: s.client.BaseURL.BucketURL,
  74. uri: u,
  75. method: http.MethodGet,
  76. result: &res,
  77. }
  78. resp, err := s.client.send(ctx, &sendOpt)
  79. return &res, resp, err
  80. }
  81. // DeleteBucketInventory https://cloud.tencent.com/document/product/436/33704
  82. func (s *BucketService) DeleteInventory(ctx context.Context, id string) (*Response, error) {
  83. u := fmt.Sprintf("/?inventory&id=%s", id)
  84. sendOpt := sendOptions{
  85. baseURL: s.client.BaseURL.BucketURL,
  86. uri: u,
  87. method: http.MethodDelete,
  88. }
  89. resp, err := s.client.send(ctx, &sendOpt)
  90. return resp, err
  91. }
  92. // ListBucketInventoryConfigurations https://cloud.tencent.com/document/product/436/33706
  93. func (s *BucketService) ListInventoryConfigurations(ctx context.Context, token string) (*ListBucketInventoryConfigResult, *Response, error) {
  94. var res ListBucketInventoryConfigResult
  95. var u string
  96. if token == "" {
  97. u = "/?inventory"
  98. } else {
  99. u = fmt.Sprintf("/?inventory&continuation-token=%s", encodeURIComponent(token))
  100. }
  101. sendOpt := sendOptions{
  102. baseURL: s.client.BaseURL.BucketURL,
  103. uri: u,
  104. method: http.MethodGet,
  105. result: &res,
  106. }
  107. resp, err := s.client.send(ctx, &sendOpt)
  108. return &res, resp, err
  109. }