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.

262 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 (s *BatchService) CreateJob(ctx context.Context, opt *BatchCreateJobOptions, headers *BatchRequestHeaders) (*BatchCreateJobResult, *Response, error) {
  105. var res BatchCreateJobResult
  106. sendOpt := sendOptions{
  107. baseURL: s.client.BaseURL.BatchURL,
  108. uri: "/jobs",
  109. method: http.MethodPost,
  110. optHeader: headers,
  111. body: opt,
  112. result: &res,
  113. }
  114. resp, err := s.client.send(ctx, &sendOpt)
  115. return &res, resp, err
  116. }
  117. type BatchJobFailureReasons struct {
  118. FailureCode string `xml:"FailureCode" header:"-" url:"-"`
  119. FailureReason string `xml:"FailureReason" header:"-" url:"-"`
  120. }
  121. type BatchDescribeJob struct {
  122. ConfirmationRequired string `xml:"ConfirmationRequired,omitempty" header:"-" url:"-"`
  123. CreationTime string `xml:"CreationTime,omitempty" header:"-" url:"-"`
  124. Description string `xml:"Description,omitempty" header:"-" url:"-"`
  125. FailureReasons *BatchJobFailureReasons `xml:"FailureReasons>JobFailure,omitempty" header:"-" url:"-"`
  126. JobId string `xml:"JobId" header:"-" url:"-"`
  127. Manifest *BatchJobManifest `xml:"Manifest" header:"-" url:"-"`
  128. Operation *BatchJobOperation `xml:"Operation" header:"-" url:"-"`
  129. Priority int `xml:"Priority" header:"-" url:"-"`
  130. ProgressSummary *BatchProgressSummary `xml:"ProgressSummary" header:"-" url:"-"`
  131. Report *BatchJobReport `xml:"Report,omitempty" header:"-" url:"-"`
  132. RoleArn string `xml:"RoleArn,omitempty" header:"-" url:"-"`
  133. Status string `xml:"Status,omitempty" header:"-" url:"-"`
  134. StatusUpdateReason string `xml:"StatusUpdateReason,omitempty" header:"-" url:"-"`
  135. SuspendedCause string `xml:"SuspendedCause,omitempty" header:"-" url:"-"`
  136. SuspendedDate string `xml:"SuspendedDate,omitempty" header:"-" url:"-"`
  137. TerminationDate string `xml:"TerminationDate,omitempty" header:"-" url:"-"`
  138. }
  139. type BatchDescribeJobResult struct {
  140. XMLName xml.Name `xml:"DescribeJobResult"`
  141. Job *BatchDescribeJob `xml:"Job,omitempty"`
  142. }
  143. func (s *BatchService) DescribeJob(ctx context.Context, id string, headers *BatchRequestHeaders) (*BatchDescribeJobResult, *Response, error) {
  144. var res BatchDescribeJobResult
  145. u := fmt.Sprintf("/jobs/%s", id)
  146. sendOpt := sendOptions{
  147. baseURL: s.client.BaseURL.BatchURL,
  148. uri: u,
  149. method: http.MethodGet,
  150. optHeader: headers,
  151. result: &res,
  152. }
  153. resp, err := s.client.send(ctx, &sendOpt)
  154. return &res, resp, err
  155. }
  156. type BatchListJobsOptions struct {
  157. JobStatuses string `url:"jobStatuses,omitempty" header:"-" xml:"-"`
  158. MaxResults int `url:"maxResults,omitempty" header:"-" xml:"-"`
  159. NextToken string `url:"nextToken,omitempty" header:"-" xml:"-"`
  160. }
  161. type BatchListJobsMember struct {
  162. CreationTime string `xml:"CreationTime,omitempty" header:"-" url:"-"`
  163. Description string `xml:"Description,omitempty" header:"-" url:"-"`
  164. JobId string `xml:"JobId,omitempty" header:"-" url:"-"`
  165. Operation string `xml:"Operation,omitempty" header:"-" url:"-"`
  166. Priority int `xml:"Priority,omitempty" header:"-" url:"-"`
  167. ProgressSummary *BatchProgressSummary `xml:"ProgressSummary,omitempty" header:"-" url:"-"`
  168. Status string `xml:"Status,omitempty" header:"-" url:"-"`
  169. TerminationDate string `xml:"TerminationDate,omitempty" header:"-" url:"-"`
  170. }
  171. type BatchListJobs struct {
  172. Members []BatchListJobsMember `xml:"member,omitempty" header:"-" url:"-"`
  173. }
  174. type BatchListJobsResult struct {
  175. XMLName xml.Name `xml:"ListJobsResult"`
  176. Jobs *BatchListJobs `xml:"Jobs,omitempty"`
  177. NextToken string `xml:"NextToken,omitempty"`
  178. }
  179. func (s *BatchService) ListJobs(ctx context.Context, opt *BatchListJobsOptions, headers *BatchRequestHeaders) (*BatchListJobsResult, *Response, error) {
  180. var res BatchListJobsResult
  181. sendOpt := sendOptions{
  182. baseURL: s.client.BaseURL.BatchURL,
  183. uri: "/jobs",
  184. method: http.MethodGet,
  185. optQuery: opt,
  186. optHeader: headers,
  187. result: &res,
  188. }
  189. resp, err := s.client.send(ctx, &sendOpt)
  190. return &res, resp, err
  191. }
  192. type BatchUpdatePriorityOptions struct {
  193. JobId string `url:"-" header:"-" xml:"-"`
  194. Priority int `url:"priority" header:"-" xml:"-"`
  195. }
  196. type BatchUpdatePriorityResult struct {
  197. XMLName xml.Name `xml:"UpdateJobPriorityResult"`
  198. JobId string `xml:"JobId,omitempty"`
  199. Priority int `xml:"Priority,omitempty"`
  200. }
  201. func (s *BatchService) UpdateJobPriority(ctx context.Context, opt *BatchUpdatePriorityOptions, headers *BatchRequestHeaders) (*BatchUpdatePriorityResult, *Response, error) {
  202. u := fmt.Sprintf("/jobs/%s/priority", opt.JobId)
  203. var res BatchUpdatePriorityResult
  204. sendOpt := sendOptions{
  205. baseURL: s.client.BaseURL.BatchURL,
  206. uri: u,
  207. method: http.MethodPost,
  208. optQuery: opt,
  209. optHeader: headers,
  210. result: &res,
  211. }
  212. resp, err := s.client.send(ctx, &sendOpt)
  213. return &res, resp, err
  214. }
  215. type BatchUpdateStatusOptions struct {
  216. JobId string `header:"-" url:"-" xml:"-"`
  217. RequestedJobStatus string `url:"requestedJobStatus" header:"-" xml:"-"`
  218. StatusUpdateReason string `url:"statusUpdateReason,omitempty" header:"-" xml:"-"`
  219. }
  220. type BatchUpdateStatusResult struct {
  221. XMLName xml.Name `xml:"UpdateJobStatusResult"`
  222. JobId string `xml:"JobId,omitempty"`
  223. Status string `xml:"Status,omitempty"`
  224. StatusUpdateReason string `xml:"StatusUpdateReason,omitempty"`
  225. }
  226. func (s *BatchService) UpdateJobStatus(ctx context.Context, opt *BatchUpdateStatusOptions, headers *BatchRequestHeaders) (*BatchUpdateStatusResult, *Response, error) {
  227. u := fmt.Sprintf("/jobs/%s/status", opt.JobId)
  228. var res BatchUpdateStatusResult
  229. sendOpt := sendOptions{
  230. baseURL: s.client.BaseURL.BatchURL,
  231. uri: u,
  232. method: http.MethodPost,
  233. optQuery: opt,
  234. optHeader: headers,
  235. result: &res,
  236. }
  237. resp, err := s.client.send(ctx, &sendOpt)
  238. return &res, resp, err
  239. }