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.

65 lines
2.1 KiB

4 years ago
4 years ago
  1. package cos
  2. import (
  3. "context"
  4. "net/http"
  5. )
  6. // BucketGetACLResult is same to the ACLXml
  7. type BucketGetACLResult = ACLXml
  8. // GetACL 使用API读取Bucket的ACL表,只有所有者有权操作。
  9. //
  10. // https://www.qcloud.com/document/product/436/7733
  11. func (s *BucketService) GetACL(ctx context.Context) (*BucketGetACLResult, *Response, error) {
  12. var res BucketGetACLResult
  13. sendOpt := sendOptions{
  14. baseURL: s.client.BaseURL.BucketURL,
  15. uri: "/?acl",
  16. method: http.MethodGet,
  17. result: &res,
  18. }
  19. resp, err := s.client.send(ctx, &sendOpt)
  20. if err == nil {
  21. decodeACL(resp, &res)
  22. }
  23. return &res, resp, err
  24. }
  25. // BucketPutACLOptions is the option of PutBucketACL
  26. type BucketPutACLOptions struct {
  27. Header *ACLHeaderOptions `url:"-" xml:"-"`
  28. Body *ACLXml `url:"-" header:"-"`
  29. }
  30. // PutACL 使用API写入Bucket的ACL表,您可以通过Header:"x-cos-acl","x-cos-grant-read",
  31. // "x-cos-grant-write","x-cos-grant-full-control"传入ACL信息,也可以通过body以XML格式传入ACL信息,
  32. //
  33. // 但是只能选择Header和Body其中一种,否则返回冲突。
  34. //
  35. // Put Bucket ACL是一个覆盖操作,传入新的ACL将覆盖原有ACL。只有所有者有权操作。
  36. //
  37. // "x-cos-acl":枚举值为public-read,private;public-read意味这个Bucket有公有读私有写的权限,
  38. // private意味这个Bucket有私有读写的权限。
  39. //
  40. // "x-cos-grant-read":意味被赋予权限的用户拥有该Bucket的读权限
  41. // "x-cos-grant-write":意味被赋予权限的用户拥有该Bucket的写权限
  42. // "x-cos-grant-full-control":意味被赋予权限的用户拥有该Bucket的读写权限
  43. //
  44. // https://www.qcloud.com/document/product/436/7737
  45. func (s *BucketService) PutACL(ctx context.Context, opt *BucketPutACLOptions) (*Response, error) {
  46. header := opt.Header
  47. body := opt.Body
  48. if body != nil {
  49. header = nil
  50. }
  51. sendOpt := sendOptions{
  52. baseURL: s.client.BaseURL.BucketURL,
  53. uri: "/?acl",
  54. method: http.MethodPut,
  55. body: body,
  56. optHeader: header,
  57. }
  58. resp, err := s.client.send(ctx, &sendOpt)
  59. return resp, err
  60. }