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.

269 lines
11 KiB

5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "fmt"
  6. "net/http"
  7. )
  8. type BatchService service
  9. type BatchRequestHeaders struct {
  10. XCosAppid int `header:"x-cos-appid" xml:"-" url:"-"`
  11. ContentLength string `header:"Content-Length,omitempty" xml:"-" url:"-"`
  12. ContentType string `header:"Content-Type,omitempty" xml:"-" url:"-"`
  13. Headers *http.Header `header:"-" xml:"-" url:"-"`
  14. }
  15. // BatchProgressSummary
  16. type BatchProgressSummary struct {
  17. NumberOfTasksFailed int `xml:"NumberOfTasksFailed" header:"-" url:"-"`
  18. NumberOfTasksSucceeded int `xml:"NumberOfTasksSucceeded" header:"-" url:"-"`
  19. TotalNumberOfTasks int `xml:"TotalNumberOfTasks" header:"-" url:"-"`
  20. }
  21. // BatchJobReport
  22. type BatchJobReport struct {
  23. Bucket string `xml:"Bucket" header:"-" url:"-"`
  24. Enabled string `xml:"Enabled" header:"-" url:"-"`
  25. Format string `xml:"Format" header:"-" url:"-"`
  26. Prefix string `xml:"Prefix,omitempty" header:"-" url:"-"`
  27. ReportScope string `xml:"ReportScope" header:"-" url:"-"`
  28. }
  29. // BatchJobOperationCopy
  30. type BatchMetadata struct {
  31. Key string `xml:"Key" header:"-" url:"-"`
  32. Value string `xml:"Value" header:"-" url:"-"`
  33. }
  34. type BatchNewObjectMetadata struct {
  35. CacheControl string `xml:"CacheControl,omitempty" header:"-" url:"-"`
  36. ContentDisposition string `xml:"ContentDisposition,omitempty" header:"-" url:"-"`
  37. ContentEncoding string `xml:"ContentEncoding,omitempty" header:"-" url:"-"`
  38. ContentType string `xml:"ContentType,omitempty" header:"-" url:"-"`
  39. HttpExpiresDate string `xml:"HttpExpiresDate,omitempty" header:"-" url:"-"`
  40. SSEAlgorithm string `xml:"SSEAlgorithm,omitempty" header:"-" url:"-"`
  41. UserMetadata []BatchMetadata `xml:"UserMetadata>member,omitempty" header:"-" url:"-"`
  42. }
  43. type BatchGrantee struct {
  44. DisplayName string `xml:"DisplayName,omitempty" header:"-" url:"-"`
  45. Identifier string `xml:"Identifier" header:"-" url:"-"`
  46. TypeIdentifier string `xml:"TypeIdentifier" header:"-" url:"-"`
  47. }
  48. type BatchCOSGrant struct {
  49. Grantee *BatchGrantee `xml:"Grantee" header:"-" url:"-"`
  50. Permission string `xml:"Permission" header:"-" url:"-"`
  51. }
  52. type BatchAccessControlGrants struct {
  53. COSGrants *BatchCOSGrant `xml:"COSGrant,omitempty" header:"-" url:"-"`
  54. }
  55. type BatchJobOperationCopy struct {
  56. AccessControlGrants *BatchAccessControlGrants `xml:"AccessControlGrants,omitempty" header:"-" url:"-"`
  57. CannedAccessControlList string `xml:"CannedAccessControlList,omitempty" header:"-" url:"-"`
  58. MetadataDirective string `xml:"MetadataDirective,omitempty" header:"-" url:"-"`
  59. ModifiedSinceConstraint int64 `xml:"ModifiedSinceConstraint,omitempty" header:"-" url:"-"`
  60. UnModifiedSinceConstraint int64 `xml:"UnModifiedSinceConstraint,omitempty" header:"-" url:"-"`
  61. NewObjectMetadata *BatchNewObjectMetadata `xml:"NewObjectMetadata,omitempty" header:"-" url:"-"`
  62. StorageClass string `xml:"StorageClass,omitempty" header:"-" url:"-"`
  63. TargetResource string `xml:"TargetResource" header:"-" url:"-"`
  64. }
  65. // BatchInitiateRestoreObject
  66. type BatchInitiateRestoreObject struct {
  67. ExpirationInDays int `xml:"ExpirationInDays"`
  68. JobTier string `xml:"JobTier"`
  69. }
  70. // BatchJobOperation
  71. type BatchJobOperation struct {
  72. PutObjectCopy *BatchJobOperationCopy `xml:"COSPutObjectCopy,omitempty" header:"-" url:"-"`
  73. RestoreObject *BatchInitiateRestoreObject `xml:"COSInitiateRestoreObject,omitempty" header:"-" url:"-"`
  74. }
  75. // BatchJobManifest
  76. type BatchJobManifestLocation struct {
  77. ETag string `xml:"ETag" header:"-" url:"-"`
  78. ObjectArn string `xml:"ObjectArn" header:"-" url:"-"`
  79. ObjectVersionId string `xml:"ObjectVersionId,omitempty" header:"-" url:"-"`
  80. }
  81. type BatchJobManifestSpec struct {
  82. Fields []string `xml:"Fields>member,omitempty" header:"-" url:"-"`
  83. Format string `xml:"Format" header:"-" url:"-"`
  84. }
  85. type BatchJobManifest struct {
  86. Location *BatchJobManifestLocation `xml:"Location" header:"-" url:"-"`
  87. Spec *BatchJobManifestSpec `xml:"Spec" header:"-" url:"-"`
  88. }
  89. type BatchCreateJobOptions struct {
  90. XMLName xml.Name `xml:"CreateJobRequest" header:"-" url:"-"`
  91. ClientRequestToken string `xml:"ClientRequestToken" header:"-" url:"-"`
  92. ConfirmationRequired string `xml:"ConfirmationRequired,omitempty" header:"-" url:"-"`
  93. Description string `xml:"Description,omitempty" header:"-" url:"-"`
  94. Manifest *BatchJobManifest `xml:"Manifest" header:"-" url:"-"`
  95. Operation *BatchJobOperation `xml:"Operation" header:"-" url:"-"`
  96. Priority int `xml:"Priority" header:"-" url:"-"`
  97. Report *BatchJobReport `xml:"Report" header:"-" url:"-"`
  98. RoleArn string `xml:"RoleArn" header:"-" url:"-"`
  99. }
  100. type BatchCreateJobResult struct {
  101. XMLName xml.Name `xml:"CreateJobResult"`
  102. JobId string `xml:"JobId,omitempty"`
  103. }
  104. func processETag(opt *BatchCreateJobOptions) *BatchCreateJobOptions {
  105. if opt != nil && opt.Manifest != nil && opt.Manifest.Location != nil {
  106. opt.Manifest.Location.ETag = "<ETag>" + opt.Manifest.Location.ETag + "</ETag>"
  107. }
  108. return opt
  109. }
  110. func (s *BatchService) CreateJob(ctx context.Context, opt *BatchCreateJobOptions, headers *BatchRequestHeaders) (*BatchCreateJobResult, *Response, error) {
  111. var res BatchCreateJobResult
  112. sendOpt := sendOptions{
  113. baseURL: s.client.BaseURL.BatchURL,
  114. uri: "/jobs",
  115. method: http.MethodPost,
  116. optHeader: headers,
  117. body: opt,
  118. result: &res,
  119. }
  120. resp, err := s.client.send(ctx, &sendOpt)
  121. return &res, resp, err
  122. }
  123. type BatchJobFailureReasons struct {
  124. FailureCode string `xml:"FailureCode" header:"-" url:"-"`
  125. FailureReason string `xml:"FailureReason" header:"-" url:"-"`
  126. }
  127. type BatchDescribeJob struct {
  128. ConfirmationRequired string `xml:"ConfirmationRequired,omitempty" header:"-" url:"-"`
  129. CreationTime string `xml:"CreationTime,omitempty" header:"-" url:"-"`
  130. Description string `xml:"Description,omitempty" header:"-" url:"-"`
  131. FailureReasons *BatchJobFailureReasons `xml:"FailureReasons>JobFailure,omitempty" header:"-" url:"-"`
  132. JobId string `xml:"JobId" header:"-" url:"-"`
  133. Manifest *BatchJobManifest `xml:"Manifest" header:"-" url:"-"`
  134. Operation *BatchJobOperation `xml:"Operation" header:"-" url:"-"`
  135. Priority int `xml:"Priority" header:"-" url:"-"`
  136. ProgressSummary *BatchProgressSummary `xml:"ProgressSummary" header:"-" url:"-"`
  137. Report *BatchJobReport `xml:"Report,omitempty" header:"-" url:"-"`
  138. RoleArn string `xml:"RoleArn,omitempty" header:"-" url:"-"`
  139. Status string `xml:"Status,omitempty" header:"-" url:"-"`
  140. StatusUpdateReason string `xml:"StatusUpdateReason,omitempty" header:"-" url:"-"`
  141. SuspendedCause string `xml:"SuspendedCause,omitempty" header:"-" url:"-"`
  142. SuspendedDate string `xml:"SuspendedDate,omitempty" header:"-" url:"-"`
  143. TerminationDate string `xml:"TerminationDate,omitempty" header:"-" url:"-"`
  144. }
  145. type BatchDescribeJobResult struct {
  146. XMLName xml.Name `xml:"DescribeJobResult"`
  147. Job *BatchDescribeJob `xml:"Job,omitempty"`
  148. }
  149. func (s *BatchService) DescribeJob(ctx context.Context, id string, headers *BatchRequestHeaders) (*BatchDescribeJobResult, *Response, error) {
  150. var res BatchDescribeJobResult
  151. u := fmt.Sprintf("/jobs/%s", id)
  152. sendOpt := sendOptions{
  153. baseURL: s.client.BaseURL.BatchURL,
  154. uri: u,
  155. method: http.MethodGet,
  156. optHeader: headers,
  157. result: &res,
  158. }
  159. resp, err := s.client.send(ctx, &sendOpt)
  160. return &res, resp, err
  161. }
  162. type BatchListJobsOptions struct {
  163. JobStatuses string `url:"jobStatuses,omitempty" header:"-" xml:"-"`
  164. MaxResults int `url:"maxResults,omitempty" header:"-" xml:"-"`
  165. NextToken string `url:"nextToken,omitempty" header:"-" xml:"-"`
  166. }
  167. type BatchListJobsMember struct {
  168. CreationTime string `xml:"CreationTime,omitempty" header:"-" url:"-"`
  169. Description string `xml:"Description,omitempty" header:"-" url:"-"`
  170. JobId string `xml:"JobId,omitempty" header:"-" url:"-"`
  171. Operation string `xml:"Operation,omitempty" header:"-" url:"-"`
  172. Priority int `xml:"Priority,omitempty" header:"-" url:"-"`
  173. ProgressSummary *BatchProgressSummary `xml:"ProgressSummary,omitempty" header:"-" url:"-"`
  174. Status string `xml:"Status,omitempty" header:"-" url:"-"`
  175. TerminationDate string `xml:"TerminationDate,omitempty" header:"-" url:"-"`
  176. }
  177. type BatchListJobs struct {
  178. Members []BatchListJobsMember `xml:"member,omitempty" header:"-" url:"-"`
  179. }
  180. type BatchListJobsResult struct {
  181. XMLName xml.Name `xml:"ListJobsResult"`
  182. Jobs *BatchListJobs `xml:"Jobs,omitempty"`
  183. NextToken string `xml:"NextToken,omitempty"`
  184. }
  185. func (s *BatchService) ListJobs(ctx context.Context, opt *BatchListJobsOptions, headers *BatchRequestHeaders) (*BatchListJobsResult, *Response, error) {
  186. var res BatchListJobsResult
  187. sendOpt := sendOptions{
  188. baseURL: s.client.BaseURL.BatchURL,
  189. uri: "/jobs",
  190. method: http.MethodGet,
  191. optQuery: opt,
  192. optHeader: headers,
  193. result: &res,
  194. }
  195. resp, err := s.client.send(ctx, &sendOpt)
  196. return &res, resp, err
  197. }
  198. type BatchUpdatePriorityOptions struct {
  199. JobId string `url:"-" header:"-" xml:"-"`
  200. Priority int `url:"priority" header:"-" xml:"-"`
  201. }
  202. type BatchUpdatePriorityResult struct {
  203. XMLName xml.Name `xml:"UpdateJobPriorityResult"`
  204. JobId string `xml:"JobId,omitempty"`
  205. Priority int `xml:"Priority,omitempty"`
  206. }
  207. func (s *BatchService) UpdateJobPriority(ctx context.Context, opt *BatchUpdatePriorityOptions, headers *BatchRequestHeaders) (*BatchUpdatePriorityResult, *Response, error) {
  208. u := fmt.Sprintf("/jobs/%s/priority", opt.JobId)
  209. var res BatchUpdatePriorityResult
  210. sendOpt := sendOptions{
  211. baseURL: s.client.BaseURL.BatchURL,
  212. uri: u,
  213. method: http.MethodPost,
  214. optQuery: opt,
  215. optHeader: headers,
  216. result: &res,
  217. }
  218. resp, err := s.client.send(ctx, &sendOpt)
  219. return &res, resp, err
  220. }
  221. type BatchUpdateStatusOptions struct {
  222. JobId string `header:"-" url:"-" xml:"-"`
  223. RequestedJobStatus string `url:"requestedJobStatus" header:"-" xml:"-"`
  224. StatusUpdateReason string `url:"statusUpdateReason,omitempty" header:"-" xml:"-"`
  225. }
  226. type BatchUpdateStatusResult struct {
  227. XMLName xml.Name `xml:"UpdateJobStatusResult"`
  228. JobId string `xml:"JobId,omitempty"`
  229. Status string `xml:"Status,omitempty"`
  230. StatusUpdateReason string `xml:"StatusUpdateReason,omitempty"`
  231. }
  232. func (s *BatchService) UpdateJobStatus(ctx context.Context, opt *BatchUpdateStatusOptions, headers *BatchRequestHeaders) (*BatchUpdateStatusResult, *Response, error) {
  233. u := fmt.Sprintf("/jobs/%s/status", opt.JobId)
  234. var res BatchUpdateStatusResult
  235. sendOpt := sendOptions{
  236. baseURL: s.client.BaseURL.BatchURL,
  237. uri: u,
  238. method: http.MethodPost,
  239. optQuery: opt,
  240. optHeader: headers,
  241. result: &res,
  242. }
  243. resp, err := s.client.send(ctx, &sendOpt)
  244. return &res, resp, err
  245. }