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.

66 lines
2.2 KiB

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