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.

51 lines
1.3 KiB

  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "net/http"
  6. )
  7. type BucketEncryptionConfiguration struct {
  8. SSEAlgorithm string `xml:"SSEAlgorithm"`
  9. }
  10. type BucketPutEncryptionOptions struct {
  11. XMLName xml.Name `xml:"ServerSideEncryptionConfiguration"`
  12. Rule *BucketEncryptionConfiguration `xml:"Rule>ApplyServerSideEncryptionByDefault"`
  13. }
  14. type BucketGetEncryptionResult BucketPutEncryptionOptions
  15. func (s *BucketService) PutEncryption(ctx context.Context, opt *BucketPutEncryptionOptions) (*Response, error) {
  16. sendOpt := &sendOptions{
  17. baseURL: s.client.BaseURL.BucketURL,
  18. uri: "/?encryption",
  19. method: http.MethodPut,
  20. body: opt,
  21. }
  22. resp, err := s.client.doRetry(ctx, sendOpt)
  23. return resp, err
  24. }
  25. func (s *BucketService) GetEncryption(ctx context.Context) (*BucketGetEncryptionResult, *Response, error) {
  26. var res BucketGetEncryptionResult
  27. sendOpt := &sendOptions{
  28. baseURL: s.client.BaseURL.BucketURL,
  29. uri: "/?encryption",
  30. method: http.MethodGet,
  31. result: &res,
  32. }
  33. resp, err := s.client.doRetry(ctx, sendOpt)
  34. return &res, resp, err
  35. }
  36. func (s *BucketService) DeleteEncryption(ctx context.Context) (*Response, error) {
  37. sendOpt := &sendOptions{
  38. baseURL: s.client.BaseURL.BucketURL,
  39. uri: "/?encryption",
  40. method: http.MethodDelete,
  41. }
  42. resp, err := s.client.doRetry(ctx, sendOpt)
  43. return resp, err
  44. }