type.go 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  1. package oss
  2. import (
  3. "encoding/base64"
  4. "encoding/xml"
  5. "fmt"
  6. "net/url"
  7. "time"
  8. )
  9. // ListBucketsResult defines the result object from ListBuckets request
  10. type ListBucketsResult struct {
  11. XMLName xml.Name `xml:"ListAllMyBucketsResult"`
  12. Prefix string `xml:"Prefix"` // The prefix in this query
  13. Marker string `xml:"Marker"` // The marker filter
  14. MaxKeys int `xml:"MaxKeys"` // The max entry count to return. This information is returned when IsTruncated is true.
  15. IsTruncated bool `xml:"IsTruncated"` // Flag true means there's remaining buckets to return.
  16. NextMarker string `xml:"NextMarker"` // The marker filter for the next list call
  17. Owner Owner `xml:"Owner"` // The owner information
  18. Buckets []BucketProperties `xml:"Buckets>Bucket"` // The bucket list
  19. }
  20. // BucketProperties defines bucket properties
  21. type BucketProperties struct {
  22. XMLName xml.Name `xml:"Bucket"`
  23. Name string `xml:"Name"` // Bucket name
  24. Location string `xml:"Location"` // Bucket datacenter
  25. CreationDate time.Time `xml:"CreationDate"` // Bucket create time
  26. StorageClass string `xml:"StorageClass"` // Bucket storage class
  27. }
  28. // GetBucketACLResult defines GetBucketACL request's result
  29. type GetBucketACLResult struct {
  30. XMLName xml.Name `xml:"AccessControlPolicy"`
  31. ACL string `xml:"AccessControlList>Grant"` // Bucket ACL
  32. Owner Owner `xml:"Owner"` // Bucket owner
  33. }
  34. // LifecycleConfiguration is the Bucket Lifecycle configuration
  35. type LifecycleConfiguration struct {
  36. XMLName xml.Name `xml:"LifecycleConfiguration"`
  37. Rules []LifecycleRule `xml:"Rule"`
  38. }
  39. // LifecycleRule defines Lifecycle rules
  40. type LifecycleRule struct {
  41. XMLName xml.Name `xml:"Rule"`
  42. ID string `xml:"ID,omitempty"` // The rule ID
  43. Prefix string `xml:"Prefix"` // The object key prefix
  44. Status string `xml:"Status"` // The rule status (enabled or not)
  45. Tags []Tag `xml:"Tag,omitempty"` // the tags property
  46. Expiration *LifecycleExpiration `xml:"Expiration,omitempty"` // The expiration property
  47. Transitions []LifecycleTransition `xml:"Transition,omitempty"` // The transition property
  48. AbortMultipartUpload *LifecycleAbortMultipartUpload `xml:"AbortMultipartUpload,omitempty"` // The AbortMultipartUpload property
  49. NonVersionExpiration *LifecycleVersionExpiration `xml:"NoncurrentVersionExpiration,omitempty"`
  50. // Deprecated: Use NonVersionTransitions instead.
  51. NonVersionTransition *LifecycleVersionTransition `xml:"-"` // NonVersionTransition is not suggested to use
  52. NonVersionTransitions []LifecycleVersionTransition `xml:"NoncurrentVersionTransition,omitempty"`
  53. }
  54. // LifecycleExpiration defines the rule's expiration property
  55. type LifecycleExpiration struct {
  56. XMLName xml.Name `xml:"Expiration"`
  57. Days int `xml:"Days,omitempty"` // Relative expiration time: The expiration time in days after the last modified time
  58. Date string `xml:"Date,omitempty"` // Absolute expiration time: The expiration time in date, not recommended
  59. CreatedBeforeDate string `xml:"CreatedBeforeDate,omitempty"` // objects created before the date will be expired
  60. ExpiredObjectDeleteMarker *bool `xml:"ExpiredObjectDeleteMarker,omitempty"` // Specifies whether the expired delete tag is automatically deleted
  61. }
  62. // LifecycleTransition defines the rule's transition propery
  63. type LifecycleTransition struct {
  64. XMLName xml.Name `xml:"Transition"`
  65. Days int `xml:"Days,omitempty"` // Relative transition time: The transition time in days after the last modified time
  66. CreatedBeforeDate string `xml:"CreatedBeforeDate,omitempty"` // objects created before the date will be expired
  67. StorageClass StorageClassType `xml:"StorageClass,omitempty"` // Specifies the target storage type
  68. }
  69. // LifecycleAbortMultipartUpload defines the rule's abort multipart upload propery
  70. type LifecycleAbortMultipartUpload struct {
  71. XMLName xml.Name `xml:"AbortMultipartUpload"`
  72. Days int `xml:"Days,omitempty"` // Relative expiration time: The expiration time in days after the last modified time
  73. CreatedBeforeDate string `xml:"CreatedBeforeDate,omitempty"` // objects created before the date will be expired
  74. }
  75. // LifecycleVersionExpiration defines the rule's NoncurrentVersionExpiration propery
  76. type LifecycleVersionExpiration struct {
  77. XMLName xml.Name `xml:"NoncurrentVersionExpiration"`
  78. NoncurrentDays int `xml:"NoncurrentDays,omitempty"` // How many days after the Object becomes a non-current version
  79. }
  80. // LifecycleVersionTransition defines the rule's NoncurrentVersionTransition propery
  81. type LifecycleVersionTransition struct {
  82. XMLName xml.Name `xml:"NoncurrentVersionTransition"`
  83. NoncurrentDays int `xml:"NoncurrentDays,omitempty"` // How many days after the Object becomes a non-current version
  84. StorageClass StorageClassType `xml:"StorageClass,omitempty"`
  85. }
  86. const iso8601DateFormat = "2006-01-02T15:04:05.000Z"
  87. // BuildLifecycleRuleByDays builds a lifecycle rule objects will expiration in days after the last modified time
  88. func BuildLifecycleRuleByDays(id, prefix string, status bool, days int) LifecycleRule {
  89. var statusStr = "Enabled"
  90. if !status {
  91. statusStr = "Disabled"
  92. }
  93. return LifecycleRule{ID: id, Prefix: prefix, Status: statusStr,
  94. Expiration: &LifecycleExpiration{Days: days}}
  95. }
  96. // BuildLifecycleRuleByDate builds a lifecycle rule objects will expiration in specified date
  97. func BuildLifecycleRuleByDate(id, prefix string, status bool, year, month, day int) LifecycleRule {
  98. var statusStr = "Enabled"
  99. if !status {
  100. statusStr = "Disabled"
  101. }
  102. date := time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC).Format(iso8601DateFormat)
  103. return LifecycleRule{ID: id, Prefix: prefix, Status: statusStr,
  104. Expiration: &LifecycleExpiration{Date: date}}
  105. }
  106. // ValidateLifecycleRule Determine if a lifecycle rule is valid, if it is invalid, it will return an error.
  107. func verifyLifecycleRules(rules []LifecycleRule) error {
  108. if len(rules) == 0 {
  109. return fmt.Errorf("invalid rules, the length of rules is zero")
  110. }
  111. for k, rule := range rules {
  112. if rule.Status != "Enabled" && rule.Status != "Disabled" {
  113. return fmt.Errorf("invalid rule, the value of status must be Enabled or Disabled")
  114. }
  115. abortMPU := rule.AbortMultipartUpload
  116. if abortMPU != nil {
  117. if (abortMPU.Days != 0 && abortMPU.CreatedBeforeDate != "") || (abortMPU.Days == 0 && abortMPU.CreatedBeforeDate == "") {
  118. return fmt.Errorf("invalid abort multipart upload lifecycle, must be set one of CreatedBeforeDate and Days")
  119. }
  120. }
  121. transitions := rule.Transitions
  122. if len(transitions) > 0 {
  123. for _, transition := range transitions {
  124. if (transition.Days != 0 && transition.CreatedBeforeDate != "") || (transition.Days == 0 && transition.CreatedBeforeDate == "") {
  125. return fmt.Errorf("invalid transition lifecycle, must be set one of CreatedBeforeDate and Days")
  126. }
  127. }
  128. }
  129. // NonVersionTransition is not suggested to use
  130. // to keep compatible
  131. if rule.NonVersionTransition != nil && len(rule.NonVersionTransitions) > 0 {
  132. return fmt.Errorf("NonVersionTransition and NonVersionTransitions cannot both have values")
  133. } else if rule.NonVersionTransition != nil {
  134. rules[k].NonVersionTransitions = append(rules[k].NonVersionTransitions, *rule.NonVersionTransition)
  135. }
  136. }
  137. return nil
  138. }
  139. // GetBucketLifecycleResult defines GetBucketLifecycle's result object
  140. type GetBucketLifecycleResult LifecycleConfiguration
  141. // RefererXML defines Referer configuration
  142. type RefererXML struct {
  143. XMLName xml.Name `xml:"RefererConfiguration"`
  144. AllowEmptyReferer bool `xml:"AllowEmptyReferer"` // Allow empty referrer
  145. RefererList []string `xml:"RefererList>Referer"` // Referer whitelist
  146. }
  147. // GetBucketRefererResult defines result object for GetBucketReferer request
  148. type GetBucketRefererResult RefererXML
  149. // LoggingXML defines logging configuration
  150. type LoggingXML struct {
  151. XMLName xml.Name `xml:"BucketLoggingStatus"`
  152. LoggingEnabled LoggingEnabled `xml:"LoggingEnabled"` // The logging configuration information
  153. }
  154. type loggingXMLEmpty struct {
  155. XMLName xml.Name `xml:"BucketLoggingStatus"`
  156. }
  157. // LoggingEnabled defines the logging configuration information
  158. type LoggingEnabled struct {
  159. XMLName xml.Name `xml:"LoggingEnabled"`
  160. TargetBucket string `xml:"TargetBucket"` // The bucket name for storing the log files
  161. TargetPrefix string `xml:"TargetPrefix"` // The log file prefix
  162. }
  163. // GetBucketLoggingResult defines the result from GetBucketLogging request
  164. type GetBucketLoggingResult LoggingXML
  165. // WebsiteXML defines Website configuration
  166. type WebsiteXML struct {
  167. XMLName xml.Name `xml:"WebsiteConfiguration"`
  168. IndexDocument IndexDocument `xml:"IndexDocument,omitempty"` // The index page
  169. ErrorDocument ErrorDocument `xml:"ErrorDocument,omitempty"` // The error page
  170. RoutingRules []RoutingRule `xml:"RoutingRules>RoutingRule,omitempty"` // The routing Rule list
  171. }
  172. // IndexDocument defines the index page info
  173. type IndexDocument struct {
  174. XMLName xml.Name `xml:"IndexDocument"`
  175. Suffix string `xml:"Suffix"` // The file name for the index page
  176. }
  177. // ErrorDocument defines the 404 error page info
  178. type ErrorDocument struct {
  179. XMLName xml.Name `xml:"ErrorDocument"`
  180. Key string `xml:"Key"` // 404 error file name
  181. }
  182. // RoutingRule defines the routing rules
  183. type RoutingRule struct {
  184. XMLName xml.Name `xml:"RoutingRule"`
  185. RuleNumber int `xml:"RuleNumber,omitempty"` // The routing number
  186. Condition Condition `xml:"Condition,omitempty"` // The routing condition
  187. Redirect Redirect `xml:"Redirect,omitempty"` // The routing redirect
  188. }
  189. // Condition defines codition in the RoutingRule
  190. type Condition struct {
  191. XMLName xml.Name `xml:"Condition"`
  192. KeyPrefixEquals string `xml:"KeyPrefixEquals,omitempty"` // Matching objcet prefix
  193. HTTPErrorCodeReturnedEquals int `xml:"HttpErrorCodeReturnedEquals,omitempty"` // The rule is for Accessing to the specified object
  194. IncludeHeader []IncludeHeader `xml:"IncludeHeader"` // The rule is for request which include header
  195. }
  196. // IncludeHeader defines includeHeader in the RoutingRule's Condition
  197. type IncludeHeader struct {
  198. XMLName xml.Name `xml:"IncludeHeader"`
  199. Key string `xml:"Key,omitempty"` // The Include header key
  200. Equals string `xml:"Equals,omitempty"` // The Include header value
  201. }
  202. // Redirect defines redirect in the RoutingRule
  203. type Redirect struct {
  204. XMLName xml.Name `xml:"Redirect"`
  205. RedirectType string `xml:"RedirectType,omitempty"` // The redirect type, it have Mirror,External,Internal,AliCDN
  206. PassQueryString *bool `xml:"PassQueryString"` // Whether to send the specified request's parameters, true or false
  207. MirrorURL string `xml:"MirrorURL,omitempty"` // Mirror of the website address back to the source.
  208. MirrorPassQueryString *bool `xml:"MirrorPassQueryString"` // To Mirror of the website Whether to send the specified request's parameters, true or false
  209. MirrorFollowRedirect *bool `xml:"MirrorFollowRedirect"` // Redirect the location, if the mirror return 3XX
  210. MirrorCheckMd5 *bool `xml:"MirrorCheckMd5"` // Check the mirror is MD5.
  211. MirrorHeaders MirrorHeaders `xml:"MirrorHeaders,omitempty"` // Mirror headers
  212. Protocol string `xml:"Protocol,omitempty"` // The redirect Protocol
  213. HostName string `xml:"HostName,omitempty"` // The redirect HostName
  214. ReplaceKeyPrefixWith string `xml:"ReplaceKeyPrefixWith,omitempty"` // object name'Prefix replace the value
  215. HttpRedirectCode int `xml:"HttpRedirectCode,omitempty"` // THe redirect http code
  216. ReplaceKeyWith string `xml:"ReplaceKeyWith,omitempty"` // object name replace the value
  217. }
  218. // MirrorHeaders defines MirrorHeaders in the Redirect
  219. type MirrorHeaders struct {
  220. XMLName xml.Name `xml:"MirrorHeaders"`
  221. PassAll *bool `xml:"PassAll"` // Penetrating all of headers to source website.
  222. Pass []string `xml:"Pass"` // Penetrating some of headers to source website.
  223. Remove []string `xml:"Remove"` // Prohibit passthrough some of headers to source website
  224. Set []MirrorHeaderSet `xml:"Set"` // Setting some of headers send to source website
  225. }
  226. // MirrorHeaderSet defines Set for Redirect's MirrorHeaders
  227. type MirrorHeaderSet struct {
  228. XMLName xml.Name `xml:"Set"`
  229. Key string `xml:"Key,omitempty"` // The mirror header key
  230. Value string `xml:"Value,omitempty"` // The mirror header value
  231. }
  232. // GetBucketWebsiteResult defines the result from GetBucketWebsite request.
  233. type GetBucketWebsiteResult WebsiteXML
  234. // CORSXML defines CORS configuration
  235. type CORSXML struct {
  236. XMLName xml.Name `xml:"CORSConfiguration"`
  237. CORSRules []CORSRule `xml:"CORSRule"` // CORS rules
  238. }
  239. // CORSRule defines CORS rules
  240. type CORSRule struct {
  241. XMLName xml.Name `xml:"CORSRule"`
  242. AllowedOrigin []string `xml:"AllowedOrigin"` // Allowed origins. By default it's wildcard '*'
  243. AllowedMethod []string `xml:"AllowedMethod"` // Allowed methods
  244. AllowedHeader []string `xml:"AllowedHeader"` // Allowed headers
  245. ExposeHeader []string `xml:"ExposeHeader"` // Allowed response headers
  246. MaxAgeSeconds int `xml:"MaxAgeSeconds"` // Max cache ages in seconds
  247. }
  248. // GetBucketCORSResult defines the result from GetBucketCORS request.
  249. type GetBucketCORSResult CORSXML
  250. // GetBucketInfoResult defines the result from GetBucketInfo request.
  251. type GetBucketInfoResult struct {
  252. XMLName xml.Name `xml:"BucketInfo"`
  253. BucketInfo BucketInfo `xml:"Bucket"`
  254. }
  255. // BucketInfo defines Bucket information
  256. type BucketInfo struct {
  257. XMLName xml.Name `xml:"Bucket"`
  258. Name string `xml:"Name"` // Bucket name
  259. Location string `xml:"Location"` // Bucket datacenter
  260. CreationDate time.Time `xml:"CreationDate"` // Bucket creation time
  261. ExtranetEndpoint string `xml:"ExtranetEndpoint"` // Bucket external endpoint
  262. IntranetEndpoint string `xml:"IntranetEndpoint"` // Bucket internal endpoint
  263. ACL string `xml:"AccessControlList>Grant"` // Bucket ACL
  264. RedundancyType string `xml:"DataRedundancyType"` // Bucket DataRedundancyType
  265. Owner Owner `xml:"Owner"` // Bucket owner
  266. StorageClass string `xml:"StorageClass"` // Bucket storage class
  267. SseRule SSERule `xml:"ServerSideEncryptionRule"` // Bucket ServerSideEncryptionRule
  268. Versioning string `xml:"Versioning"` // Bucket Versioning
  269. }
  270. type SSERule struct {
  271. XMLName xml.Name `xml:"ServerSideEncryptionRule"` // Bucket ServerSideEncryptionRule
  272. KMSMasterKeyID string `xml:"KMSMasterKeyID,omitempty"` // Bucket KMSMasterKeyID
  273. SSEAlgorithm string `xml:"SSEAlgorithm,omitempty"` // Bucket SSEAlgorithm
  274. KMSDataEncryption string `xml:"KMSDataEncryption,omitempty"` //Bucket KMSDataEncryption
  275. }
  276. // ListObjectsResult defines the result from ListObjects request
  277. type ListObjectsResult struct {
  278. XMLName xml.Name `xml:"ListBucketResult"`
  279. Prefix string `xml:"Prefix"` // The object prefix
  280. Marker string `xml:"Marker"` // The marker filter.
  281. MaxKeys int `xml:"MaxKeys"` // Max keys to return
  282. Delimiter string `xml:"Delimiter"` // The delimiter for grouping objects' name
  283. IsTruncated bool `xml:"IsTruncated"` // Flag indicates if all results are returned (when it's false)
  284. NextMarker string `xml:"NextMarker"` // The start point of the next query
  285. Objects []ObjectProperties `xml:"Contents"` // Object list
  286. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // You can think of commonprefixes as "folders" whose names end with the delimiter
  287. }
  288. // ObjectProperties defines Objecct properties
  289. type ObjectProperties struct {
  290. XMLName xml.Name `xml:"Contents"`
  291. Key string `xml:"Key"` // Object key
  292. Type string `xml:"Type"` // Object type
  293. Size int64 `xml:"Size"` // Object size
  294. ETag string `xml:"ETag"` // Object ETag
  295. Owner Owner `xml:"Owner"` // Object owner information
  296. LastModified time.Time `xml:"LastModified"` // Object last modified time
  297. StorageClass string `xml:"StorageClass"` // Object storage class (Standard, IA, Archive)
  298. }
  299. // ListObjectVersionsResult defines the result from ListObjectVersions request
  300. type ListObjectVersionsResult struct {
  301. XMLName xml.Name `xml:"ListVersionsResult"`
  302. Name string `xml:"Name"` // The Bucket Name
  303. Owner Owner `xml:"Owner"` // The owner of bucket
  304. Prefix string `xml:"Prefix"` // The object prefix
  305. KeyMarker string `xml:"KeyMarker"` // The start marker filter.
  306. VersionIdMarker string `xml:"VersionIdMarker"` // The start VersionIdMarker filter.
  307. MaxKeys int `xml:"MaxKeys"` // Max keys to return
  308. Delimiter string `xml:"Delimiter"` // The delimiter for grouping objects' name
  309. IsTruncated bool `xml:"IsTruncated"` // Flag indicates if all results are returned (when it's false)
  310. NextKeyMarker string `xml:"NextKeyMarker"` // The start point of the next query
  311. NextVersionIdMarker string `xml:"NextVersionIdMarker"` // The start point of the next query
  312. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // You can think of commonprefixes as "folders" whose names end with the delimiter
  313. ObjectDeleteMarkers []ObjectDeleteMarkerProperties `xml:"DeleteMarker"` // DeleteMarker list
  314. ObjectVersions []ObjectVersionProperties `xml:"Version"` // version list
  315. }
  316. type ObjectDeleteMarkerProperties struct {
  317. XMLName xml.Name `xml:"DeleteMarker"`
  318. Key string `xml:"Key"` // The Object Key
  319. VersionId string `xml:"VersionId"` // The Object VersionId
  320. IsLatest bool `xml:"IsLatest"` // is current version or not
  321. LastModified time.Time `xml:"LastModified"` // Object last modified time
  322. Owner Owner `xml:"Owner"` // bucket owner element
  323. }
  324. type ObjectVersionProperties struct {
  325. XMLName xml.Name `xml:"Version"`
  326. Key string `xml:"Key"` // The Object Key
  327. VersionId string `xml:"VersionId"` // The Object VersionId
  328. IsLatest bool `xml:"IsLatest"` // is latest version or not
  329. LastModified time.Time `xml:"LastModified"` // Object last modified time
  330. Type string `xml:"Type"` // Object type
  331. Size int64 `xml:"Size"` // Object size
  332. ETag string `xml:"ETag"` // Object ETag
  333. StorageClass string `xml:"StorageClass"` // Object storage class (Standard, IA, Archive)
  334. Owner Owner `xml:"Owner"` // bucket owner element
  335. }
  336. // Owner defines Bucket/Object's owner
  337. type Owner struct {
  338. XMLName xml.Name `xml:"Owner"`
  339. ID string `xml:"ID"` // Owner ID
  340. DisplayName string `xml:"DisplayName"` // Owner's display name
  341. }
  342. // CopyObjectResult defines result object of CopyObject
  343. type CopyObjectResult struct {
  344. XMLName xml.Name `xml:"CopyObjectResult"`
  345. LastModified time.Time `xml:"LastModified"` // New object's last modified time.
  346. ETag string `xml:"ETag"` // New object's ETag
  347. }
  348. // GetObjectACLResult defines result of GetObjectACL request
  349. type GetObjectACLResult GetBucketACLResult
  350. type deleteXML struct {
  351. XMLName xml.Name `xml:"Delete"`
  352. Objects []DeleteObject `xml:"Object"` // Objects to delete
  353. Quiet bool `xml:"Quiet"` // Flag of quiet mode.
  354. }
  355. // DeleteObject defines the struct for deleting object
  356. type DeleteObject struct {
  357. XMLName xml.Name `xml:"Object"`
  358. Key string `xml:"Key"` // Object name
  359. VersionId string `xml:"VersionId,omitempty"` // Object VersionId
  360. }
  361. // DeleteObjectsResult defines result of DeleteObjects request
  362. type DeleteObjectsResult struct {
  363. XMLName xml.Name
  364. DeletedObjects []string // Deleted object key list
  365. }
  366. // DeleteObjectsResult_inner defines result of DeleteObjects request
  367. type DeleteObjectVersionsResult struct {
  368. XMLName xml.Name `xml:"DeleteResult"`
  369. DeletedObjectsDetail []DeletedKeyInfo `xml:"Deleted"` // Deleted object detail info
  370. }
  371. // DeleteKeyInfo defines object delete info
  372. type DeletedKeyInfo struct {
  373. XMLName xml.Name `xml:"Deleted"`
  374. Key string `xml:"Key"` // Object key
  375. VersionId string `xml:"VersionId"` // VersionId
  376. DeleteMarker bool `xml:"DeleteMarker"` // Object DeleteMarker
  377. DeleteMarkerVersionId string `xml:"DeleteMarkerVersionId"` // Object DeleteMarkerVersionId
  378. }
  379. // InitiateMultipartUploadResult defines result of InitiateMultipartUpload request
  380. type InitiateMultipartUploadResult struct {
  381. XMLName xml.Name `xml:"InitiateMultipartUploadResult"`
  382. Bucket string `xml:"Bucket"` // Bucket name
  383. Key string `xml:"Key"` // Object name to upload
  384. UploadID string `xml:"UploadId"` // Generated UploadId
  385. }
  386. // UploadPart defines the upload/copy part
  387. type UploadPart struct {
  388. XMLName xml.Name `xml:"Part"`
  389. PartNumber int `xml:"PartNumber"` // Part number
  390. ETag string `xml:"ETag"` // ETag value of the part's data
  391. }
  392. type UploadParts []UploadPart
  393. func (slice UploadParts) Len() int {
  394. return len(slice)
  395. }
  396. func (slice UploadParts) Less(i, j int) bool {
  397. return slice[i].PartNumber < slice[j].PartNumber
  398. }
  399. func (slice UploadParts) Swap(i, j int) {
  400. slice[i], slice[j] = slice[j], slice[i]
  401. }
  402. // UploadPartCopyResult defines result object of multipart copy request.
  403. type UploadPartCopyResult struct {
  404. XMLName xml.Name `xml:"CopyPartResult"`
  405. LastModified time.Time `xml:"LastModified"` // Last modified time
  406. ETag string `xml:"ETag"` // ETag
  407. }
  408. type completeMultipartUploadXML struct {
  409. XMLName xml.Name `xml:"CompleteMultipartUpload"`
  410. Part []UploadPart `xml:"Part"`
  411. }
  412. // CompleteMultipartUploadResult defines result object of CompleteMultipartUploadRequest
  413. type CompleteMultipartUploadResult struct {
  414. XMLName xml.Name `xml:"CompleteMultipartUploadResult"`
  415. Location string `xml:"Location"` // Object URL
  416. Bucket string `xml:"Bucket"` // Bucket name
  417. ETag string `xml:"ETag"` // Object ETag
  418. Key string `xml:"Key"` // Object name
  419. }
  420. // ListUploadedPartsResult defines result object of ListUploadedParts
  421. type ListUploadedPartsResult struct {
  422. XMLName xml.Name `xml:"ListPartsResult"`
  423. Bucket string `xml:"Bucket"` // Bucket name
  424. Key string `xml:"Key"` // Object name
  425. UploadID string `xml:"UploadId"` // Upload ID
  426. NextPartNumberMarker string `xml:"NextPartNumberMarker"` // Next part number
  427. MaxParts int `xml:"MaxParts"` // Max parts count
  428. IsTruncated bool `xml:"IsTruncated"` // Flag indicates all entries returned.false: all entries returned.
  429. UploadedParts []UploadedPart `xml:"Part"` // Uploaded parts
  430. }
  431. // UploadedPart defines uploaded part
  432. type UploadedPart struct {
  433. XMLName xml.Name `xml:"Part"`
  434. PartNumber int `xml:"PartNumber"` // Part number
  435. LastModified time.Time `xml:"LastModified"` // Last modified time
  436. ETag string `xml:"ETag"` // ETag cache
  437. Size int `xml:"Size"` // Part size
  438. }
  439. // ListMultipartUploadResult defines result object of ListMultipartUpload
  440. type ListMultipartUploadResult struct {
  441. XMLName xml.Name `xml:"ListMultipartUploadsResult"`
  442. Bucket string `xml:"Bucket"` // Bucket name
  443. Delimiter string `xml:"Delimiter"` // Delimiter for grouping object.
  444. Prefix string `xml:"Prefix"` // Object prefix
  445. KeyMarker string `xml:"KeyMarker"` // Object key marker
  446. UploadIDMarker string `xml:"UploadIdMarker"` // UploadId marker
  447. NextKeyMarker string `xml:"NextKeyMarker"` // Next key marker, if not all entries returned.
  448. NextUploadIDMarker string `xml:"NextUploadIdMarker"` // Next uploadId marker, if not all entries returned.
  449. MaxUploads int `xml:"MaxUploads"` // Max uploads to return
  450. IsTruncated bool `xml:"IsTruncated"` // Flag indicates all entries are returned.
  451. Uploads []UncompletedUpload `xml:"Upload"` // Ongoing uploads (not completed, not aborted)
  452. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // Common prefixes list.
  453. }
  454. // UncompletedUpload structure wraps an uncompleted upload task
  455. type UncompletedUpload struct {
  456. XMLName xml.Name `xml:"Upload"`
  457. Key string `xml:"Key"` // Object name
  458. UploadID string `xml:"UploadId"` // The UploadId
  459. Initiated time.Time `xml:"Initiated"` // Initialization time in the format such as 2012-02-23T04:18:23.000Z
  460. }
  461. // ProcessObjectResult defines result object of ProcessObject
  462. type ProcessObjectResult struct {
  463. Bucket string `json:"bucket"`
  464. FileSize int `json:"fileSize"`
  465. Object string `json:"object"`
  466. Status string `json:"status"`
  467. }
  468. // decodeDeleteObjectsResult decodes deleting objects result in URL encoding
  469. func decodeDeleteObjectsResult(result *DeleteObjectVersionsResult) error {
  470. var err error
  471. for i := 0; i < len(result.DeletedObjectsDetail); i++ {
  472. result.DeletedObjectsDetail[i].Key, err = url.QueryUnescape(result.DeletedObjectsDetail[i].Key)
  473. if err != nil {
  474. return err
  475. }
  476. }
  477. return nil
  478. }
  479. // decodeListObjectsResult decodes list objects result in URL encoding
  480. func decodeListObjectsResult(result *ListObjectsResult) error {
  481. var err error
  482. result.Prefix, err = url.QueryUnescape(result.Prefix)
  483. if err != nil {
  484. return err
  485. }
  486. result.Marker, err = url.QueryUnescape(result.Marker)
  487. if err != nil {
  488. return err
  489. }
  490. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  491. if err != nil {
  492. return err
  493. }
  494. result.NextMarker, err = url.QueryUnescape(result.NextMarker)
  495. if err != nil {
  496. return err
  497. }
  498. for i := 0; i < len(result.Objects); i++ {
  499. result.Objects[i].Key, err = url.QueryUnescape(result.Objects[i].Key)
  500. if err != nil {
  501. return err
  502. }
  503. }
  504. for i := 0; i < len(result.CommonPrefixes); i++ {
  505. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  506. if err != nil {
  507. return err
  508. }
  509. }
  510. return nil
  511. }
  512. // decodeListObjectVersionsResult decodes list version objects result in URL encoding
  513. func decodeListObjectVersionsResult(result *ListObjectVersionsResult) error {
  514. var err error
  515. // decode:Delimiter
  516. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  517. if err != nil {
  518. return err
  519. }
  520. // decode Prefix
  521. result.Prefix, err = url.QueryUnescape(result.Prefix)
  522. if err != nil {
  523. return err
  524. }
  525. // decode KeyMarker
  526. result.KeyMarker, err = url.QueryUnescape(result.KeyMarker)
  527. if err != nil {
  528. return err
  529. }
  530. // decode VersionIdMarker
  531. result.VersionIdMarker, err = url.QueryUnescape(result.VersionIdMarker)
  532. if err != nil {
  533. return err
  534. }
  535. // decode NextKeyMarker
  536. result.NextKeyMarker, err = url.QueryUnescape(result.NextKeyMarker)
  537. if err != nil {
  538. return err
  539. }
  540. // decode NextVersionIdMarker
  541. result.NextVersionIdMarker, err = url.QueryUnescape(result.NextVersionIdMarker)
  542. if err != nil {
  543. return err
  544. }
  545. // decode CommonPrefixes
  546. for i := 0; i < len(result.CommonPrefixes); i++ {
  547. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  548. if err != nil {
  549. return err
  550. }
  551. }
  552. // decode deleteMarker
  553. for i := 0; i < len(result.ObjectDeleteMarkers); i++ {
  554. result.ObjectDeleteMarkers[i].Key, err = url.QueryUnescape(result.ObjectDeleteMarkers[i].Key)
  555. if err != nil {
  556. return err
  557. }
  558. }
  559. // decode ObjectVersions
  560. for i := 0; i < len(result.ObjectVersions); i++ {
  561. result.ObjectVersions[i].Key, err = url.QueryUnescape(result.ObjectVersions[i].Key)
  562. if err != nil {
  563. return err
  564. }
  565. }
  566. return nil
  567. }
  568. // decodeListUploadedPartsResult decodes
  569. func decodeListUploadedPartsResult(result *ListUploadedPartsResult) error {
  570. var err error
  571. result.Key, err = url.QueryUnescape(result.Key)
  572. if err != nil {
  573. return err
  574. }
  575. return nil
  576. }
  577. // decodeListMultipartUploadResult decodes list multipart upload result in URL encoding
  578. func decodeListMultipartUploadResult(result *ListMultipartUploadResult) error {
  579. var err error
  580. result.Prefix, err = url.QueryUnescape(result.Prefix)
  581. if err != nil {
  582. return err
  583. }
  584. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  585. if err != nil {
  586. return err
  587. }
  588. result.KeyMarker, err = url.QueryUnescape(result.KeyMarker)
  589. if err != nil {
  590. return err
  591. }
  592. result.NextKeyMarker, err = url.QueryUnescape(result.NextKeyMarker)
  593. if err != nil {
  594. return err
  595. }
  596. for i := 0; i < len(result.Uploads); i++ {
  597. result.Uploads[i].Key, err = url.QueryUnescape(result.Uploads[i].Key)
  598. if err != nil {
  599. return err
  600. }
  601. }
  602. for i := 0; i < len(result.CommonPrefixes); i++ {
  603. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  604. if err != nil {
  605. return err
  606. }
  607. }
  608. return nil
  609. }
  610. // createBucketConfiguration defines the configuration for creating a bucket.
  611. type createBucketConfiguration struct {
  612. XMLName xml.Name `xml:"CreateBucketConfiguration"`
  613. StorageClass StorageClassType `xml:"StorageClass,omitempty"`
  614. DataRedundancyType DataRedundancyType `xml:"DataRedundancyType,omitempty"`
  615. }
  616. // LiveChannelConfiguration defines the configuration for live-channel
  617. type LiveChannelConfiguration struct {
  618. XMLName xml.Name `xml:"LiveChannelConfiguration"`
  619. Description string `xml:"Description,omitempty"` //Description of live-channel, up to 128 bytes
  620. Status string `xml:"Status,omitempty"` //Specify the status of livechannel
  621. Target LiveChannelTarget `xml:"Target"` //target configuration of live-channel
  622. // use point instead of struct to avoid omit empty snapshot
  623. Snapshot *LiveChannelSnapshot `xml:"Snapshot,omitempty"` //snapshot configuration of live-channel
  624. }
  625. // LiveChannelTarget target configuration of live-channel
  626. type LiveChannelTarget struct {
  627. XMLName xml.Name `xml:"Target"`
  628. Type string `xml:"Type"` //the type of object, only supports HLS
  629. FragDuration int `xml:"FragDuration,omitempty"` //the length of each ts object (in seconds), in the range [1,100]
  630. FragCount int `xml:"FragCount,omitempty"` //the number of ts objects in the m3u8 object, in the range of [1,100]
  631. PlaylistName string `xml:"PlaylistName,omitempty"` //the name of m3u8 object, which must end with ".m3u8" and the length range is [6,128]
  632. }
  633. // LiveChannelSnapshot snapshot configuration of live-channel
  634. type LiveChannelSnapshot struct {
  635. XMLName xml.Name `xml:"Snapshot"`
  636. RoleName string `xml:"RoleName,omitempty"` //The role of snapshot operations, it sholud has write permission of DestBucket and the permission to send messages to the NotifyTopic.
  637. DestBucket string `xml:"DestBucket,omitempty"` //Bucket the snapshots will be written to. should be the same owner as the source bucket.
  638. NotifyTopic string `xml:"NotifyTopic,omitempty"` //Topics of MNS for notifying users of high frequency screenshot operation results
  639. Interval int `xml:"Interval,omitempty"` //interval of snapshots, threre is no snapshot if no I-frame during the interval time
  640. }
  641. // CreateLiveChannelResult the result of crete live-channel
  642. type CreateLiveChannelResult struct {
  643. XMLName xml.Name `xml:"CreateLiveChannelResult"`
  644. PublishUrls []string `xml:"PublishUrls>Url"` //push urls list
  645. PlayUrls []string `xml:"PlayUrls>Url"` //play urls list
  646. }
  647. // LiveChannelStat the result of get live-channel state
  648. type LiveChannelStat struct {
  649. XMLName xml.Name `xml:"LiveChannelStat"`
  650. Status string `xml:"Status"` //Current push status of live-channel: Disabled,Live,Idle
  651. ConnectedTime time.Time `xml:"ConnectedTime"` //The time when the client starts pushing, format: ISO8601
  652. RemoteAddr string `xml:"RemoteAddr"` //The ip address of the client
  653. Video LiveChannelVideo `xml:"Video"` //Video stream information
  654. Audio LiveChannelAudio `xml:"Audio"` //Audio stream information
  655. }
  656. // LiveChannelVideo video stream information
  657. type LiveChannelVideo struct {
  658. XMLName xml.Name `xml:"Video"`
  659. Width int `xml:"Width"` //Width (unit: pixels)
  660. Height int `xml:"Height"` //Height (unit: pixels)
  661. FrameRate int `xml:"FrameRate"` //FramRate
  662. Bandwidth int `xml:"Bandwidth"` //Bandwidth (unit: B/s)
  663. }
  664. // LiveChannelAudio audio stream information
  665. type LiveChannelAudio struct {
  666. XMLName xml.Name `xml:"Audio"`
  667. SampleRate int `xml:"SampleRate"` //SampleRate
  668. Bandwidth int `xml:"Bandwidth"` //Bandwidth (unit: B/s)
  669. Codec string `xml:"Codec"` //Encoding forma
  670. }
  671. // LiveChannelHistory the result of GetLiveChannelHistory, at most return up to lastest 10 push records
  672. type LiveChannelHistory struct {
  673. XMLName xml.Name `xml:"LiveChannelHistory"`
  674. Record []LiveRecord `xml:"LiveRecord"` //push records list
  675. }
  676. // LiveRecord push recode
  677. type LiveRecord struct {
  678. XMLName xml.Name `xml:"LiveRecord"`
  679. StartTime time.Time `xml:"StartTime"` //StartTime, format: ISO8601
  680. EndTime time.Time `xml:"EndTime"` //EndTime, format: ISO8601
  681. RemoteAddr string `xml:"RemoteAddr"` //The ip address of remote client
  682. }
  683. // ListLiveChannelResult the result of ListLiveChannel
  684. type ListLiveChannelResult struct {
  685. XMLName xml.Name `xml:"ListLiveChannelResult"`
  686. Prefix string `xml:"Prefix"` //Filter by the name start with the value of "Prefix"
  687. Marker string `xml:"Marker"` //cursor from which starting list
  688. MaxKeys int `xml:"MaxKeys"` //The maximum count returned. the default value is 100. it cannot be greater than 1000.
  689. IsTruncated bool `xml:"IsTruncated"` //Indicates whether all results have been returned, "true" indicates partial results returned while "false" indicates all results have been returned
  690. NextMarker string `xml:"NextMarker"` //NextMarker indicate the Marker value of the next request
  691. LiveChannel []LiveChannelInfo `xml:"LiveChannel"` //The infomation of live-channel
  692. }
  693. // LiveChannelInfo the infomation of live-channel
  694. type LiveChannelInfo struct {
  695. XMLName xml.Name `xml:"LiveChannel"`
  696. Name string `xml:"Name"` //The name of live-channel
  697. Description string `xml:"Description"` //Description of live-channel
  698. Status string `xml:"Status"` //Status: disabled or enabled
  699. LastModified time.Time `xml:"LastModified"` //Last modification time, format: ISO8601
  700. PublishUrls []string `xml:"PublishUrls>Url"` //push urls list
  701. PlayUrls []string `xml:"PlayUrls>Url"` //play urls list
  702. }
  703. // Tag a tag for the object
  704. type Tag struct {
  705. XMLName xml.Name `xml:"Tag"`
  706. Key string `xml:"Key"`
  707. Value string `xml:"Value"`
  708. }
  709. // Tagging tagset for the object
  710. type Tagging struct {
  711. XMLName xml.Name `xml:"Tagging"`
  712. Tags []Tag `xml:"TagSet>Tag,omitempty"`
  713. }
  714. // for GetObjectTagging return value
  715. type GetObjectTaggingResult Tagging
  716. // VersioningConfig for the bucket
  717. type VersioningConfig struct {
  718. XMLName xml.Name `xml:"VersioningConfiguration"`
  719. Status string `xml:"Status"`
  720. }
  721. type GetBucketVersioningResult VersioningConfig
  722. // Server Encryption rule for the bucket
  723. type ServerEncryptionRule struct {
  724. XMLName xml.Name `xml:"ServerSideEncryptionRule"`
  725. SSEDefault SSEDefaultRule `xml:"ApplyServerSideEncryptionByDefault"`
  726. }
  727. // Server Encryption deafult rule for the bucket
  728. type SSEDefaultRule struct {
  729. XMLName xml.Name `xml:"ApplyServerSideEncryptionByDefault"`
  730. SSEAlgorithm string `xml:"SSEAlgorithm,omitempty"`
  731. KMSMasterKeyID string `xml:"KMSMasterKeyID,omitempty"`
  732. KMSDataEncryption string `xml:"KMSDataEncryption,,omitempty"`
  733. }
  734. type GetBucketEncryptionResult ServerEncryptionRule
  735. type GetBucketTaggingResult Tagging
  736. type BucketStat struct {
  737. XMLName xml.Name `xml:"BucketStat"`
  738. Storage int64 `xml:"Storage"`
  739. ObjectCount int64 `xml:"ObjectCount"`
  740. MultipartUploadCount int64 `xml:"MultipartUploadCount"`
  741. }
  742. type GetBucketStatResult BucketStat
  743. // RequestPaymentConfiguration define the request payment configuration
  744. type RequestPaymentConfiguration struct {
  745. XMLName xml.Name `xml:"RequestPaymentConfiguration"`
  746. Payer string `xml:"Payer,omitempty"`
  747. }
  748. // BucketQoSConfiguration define QoS configuration
  749. type BucketQoSConfiguration struct {
  750. XMLName xml.Name `xml:"QoSConfiguration"`
  751. TotalUploadBandwidth *int `xml:"TotalUploadBandwidth"` // Total upload bandwidth
  752. IntranetUploadBandwidth *int `xml:"IntranetUploadBandwidth"` // Intranet upload bandwidth
  753. ExtranetUploadBandwidth *int `xml:"ExtranetUploadBandwidth"` // Extranet upload bandwidth
  754. TotalDownloadBandwidth *int `xml:"TotalDownloadBandwidth"` // Total download bandwidth
  755. IntranetDownloadBandwidth *int `xml:"IntranetDownloadBandwidth"` // Intranet download bandwidth
  756. ExtranetDownloadBandwidth *int `xml:"ExtranetDownloadBandwidth"` // Extranet download bandwidth
  757. TotalQPS *int `xml:"TotalQps"` // Total Qps
  758. IntranetQPS *int `xml:"IntranetQps"` // Intranet Qps
  759. ExtranetQPS *int `xml:"ExtranetQps"` // Extranet Qps
  760. }
  761. // UserQoSConfiguration define QoS and Range configuration
  762. type UserQoSConfiguration struct {
  763. XMLName xml.Name `xml:"QoSConfiguration"`
  764. Region string `xml:"Region,omitempty"` // Effective area of Qos configuration
  765. BucketQoSConfiguration
  766. }
  767. //////////////////////////////////////////////////////////////
  768. /////////////////// Select OBject ////////////////////////////
  769. //////////////////////////////////////////////////////////////
  770. type CsvMetaRequest struct {
  771. XMLName xml.Name `xml:"CsvMetaRequest"`
  772. InputSerialization InputSerialization `xml:"InputSerialization"`
  773. OverwriteIfExists *bool `xml:"OverwriteIfExists,omitempty"`
  774. }
  775. // encodeBase64 encode base64 of the CreateSelectObjectMeta api request params
  776. func (meta *CsvMetaRequest) encodeBase64() {
  777. meta.InputSerialization.CSV.RecordDelimiter =
  778. base64.StdEncoding.EncodeToString([]byte(meta.InputSerialization.CSV.RecordDelimiter))
  779. meta.InputSerialization.CSV.FieldDelimiter =
  780. base64.StdEncoding.EncodeToString([]byte(meta.InputSerialization.CSV.FieldDelimiter))
  781. meta.InputSerialization.CSV.QuoteCharacter =
  782. base64.StdEncoding.EncodeToString([]byte(meta.InputSerialization.CSV.QuoteCharacter))
  783. }
  784. type JsonMetaRequest struct {
  785. XMLName xml.Name `xml:"JsonMetaRequest"`
  786. InputSerialization InputSerialization `xml:"InputSerialization"`
  787. OverwriteIfExists *bool `xml:"OverwriteIfExists,omitempty"`
  788. }
  789. type InputSerialization struct {
  790. XMLName xml.Name `xml:"InputSerialization"`
  791. CSV CSV `xml:CSV,omitempty`
  792. JSON JSON `xml:JSON,omitempty`
  793. CompressionType string `xml:"CompressionType,omitempty"`
  794. }
  795. type CSV struct {
  796. XMLName xml.Name `xml:"CSV"`
  797. RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
  798. FieldDelimiter string `xml:"FieldDelimiter,omitempty"`
  799. QuoteCharacter string `xml:"QuoteCharacter,omitempty"`
  800. }
  801. type JSON struct {
  802. XMLName xml.Name `xml:"JSON"`
  803. JSONType string `xml:"Type,omitempty"`
  804. }
  805. // SelectRequest is for the SelectObject request params of json file
  806. type SelectRequest struct {
  807. XMLName xml.Name `xml:"SelectRequest"`
  808. Expression string `xml:"Expression"`
  809. InputSerializationSelect InputSerializationSelect `xml:"InputSerialization"`
  810. OutputSerializationSelect OutputSerializationSelect `xml:"OutputSerialization"`
  811. SelectOptions SelectOptions `xml:"Options,omitempty"`
  812. }
  813. type InputSerializationSelect struct {
  814. XMLName xml.Name `xml:"InputSerialization"`
  815. CsvBodyInput CSVSelectInput `xml:CSV,omitempty`
  816. JsonBodyInput JSONSelectInput `xml:JSON,omitempty`
  817. CompressionType string `xml:"CompressionType,omitempty"`
  818. }
  819. type CSVSelectInput struct {
  820. XMLName xml.Name `xml:"CSV"`
  821. FileHeaderInfo string `xml:"FileHeaderInfo,omitempty"`
  822. RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
  823. FieldDelimiter string `xml:"FieldDelimiter,omitempty"`
  824. QuoteCharacter string `xml:"QuoteCharacter,omitempty"`
  825. CommentCharacter string `xml:"CommentCharacter,omitempty"`
  826. Range string `xml:"Range,omitempty"`
  827. SplitRange string
  828. }
  829. type JSONSelectInput struct {
  830. XMLName xml.Name `xml:"JSON"`
  831. JSONType string `xml:"Type,omitempty"`
  832. Range string `xml:"Range,omitempty"`
  833. ParseJSONNumberAsString *bool `xml:"ParseJsonNumberAsString"`
  834. SplitRange string
  835. }
  836. func (jsonInput *JSONSelectInput) JsonIsEmpty() bool {
  837. if jsonInput.JSONType != "" {
  838. return false
  839. }
  840. return true
  841. }
  842. type OutputSerializationSelect struct {
  843. XMLName xml.Name `xml:"OutputSerialization"`
  844. CsvBodyOutput CSVSelectOutput `xml:CSV,omitempty`
  845. JsonBodyOutput JSONSelectOutput `xml:JSON,omitempty`
  846. OutputRawData *bool `xml:"OutputRawData,omitempty"`
  847. KeepAllColumns *bool `xml:"KeepAllColumns,omitempty"`
  848. EnablePayloadCrc *bool `xml:"EnablePayloadCrc,omitempty"`
  849. OutputHeader *bool `xml:"OutputHeader,omitempty"`
  850. }
  851. type CSVSelectOutput struct {
  852. XMLName xml.Name `xml:"CSV"`
  853. RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
  854. FieldDelimiter string `xml:"FieldDelimiter,omitempty"`
  855. }
  856. type JSONSelectOutput struct {
  857. XMLName xml.Name `xml:"JSON"`
  858. RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
  859. }
  860. func (selectReq *SelectRequest) encodeBase64() {
  861. if selectReq.InputSerializationSelect.JsonBodyInput.JsonIsEmpty() {
  862. selectReq.csvEncodeBase64()
  863. } else {
  864. selectReq.jsonEncodeBase64()
  865. }
  866. }
  867. // csvEncodeBase64 encode base64 of the SelectObject api request params
  868. func (selectReq *SelectRequest) csvEncodeBase64() {
  869. selectReq.Expression = base64.StdEncoding.EncodeToString([]byte(selectReq.Expression))
  870. selectReq.InputSerializationSelect.CsvBodyInput.RecordDelimiter =
  871. base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.RecordDelimiter))
  872. selectReq.InputSerializationSelect.CsvBodyInput.FieldDelimiter =
  873. base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.FieldDelimiter))
  874. selectReq.InputSerializationSelect.CsvBodyInput.QuoteCharacter =
  875. base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.QuoteCharacter))
  876. selectReq.InputSerializationSelect.CsvBodyInput.CommentCharacter =
  877. base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.CommentCharacter))
  878. selectReq.OutputSerializationSelect.CsvBodyOutput.FieldDelimiter =
  879. base64.StdEncoding.EncodeToString([]byte(selectReq.OutputSerializationSelect.CsvBodyOutput.FieldDelimiter))
  880. selectReq.OutputSerializationSelect.CsvBodyOutput.RecordDelimiter =
  881. base64.StdEncoding.EncodeToString([]byte(selectReq.OutputSerializationSelect.CsvBodyOutput.RecordDelimiter))
  882. // handle Range
  883. if selectReq.InputSerializationSelect.CsvBodyInput.Range != "" {
  884. selectReq.InputSerializationSelect.CsvBodyInput.Range = "line-range=" + selectReq.InputSerializationSelect.CsvBodyInput.Range
  885. }
  886. if selectReq.InputSerializationSelect.CsvBodyInput.SplitRange != "" {
  887. selectReq.InputSerializationSelect.CsvBodyInput.Range = "split-range=" + selectReq.InputSerializationSelect.CsvBodyInput.SplitRange
  888. }
  889. }
  890. // jsonEncodeBase64 encode base64 of the SelectObject api request params
  891. func (selectReq *SelectRequest) jsonEncodeBase64() {
  892. selectReq.Expression = base64.StdEncoding.EncodeToString([]byte(selectReq.Expression))
  893. selectReq.OutputSerializationSelect.JsonBodyOutput.RecordDelimiter =
  894. base64.StdEncoding.EncodeToString([]byte(selectReq.OutputSerializationSelect.JsonBodyOutput.RecordDelimiter))
  895. // handle Range
  896. if selectReq.InputSerializationSelect.JsonBodyInput.Range != "" {
  897. selectReq.InputSerializationSelect.JsonBodyInput.Range = "line-range=" + selectReq.InputSerializationSelect.JsonBodyInput.Range
  898. }
  899. if selectReq.InputSerializationSelect.JsonBodyInput.SplitRange != "" {
  900. selectReq.InputSerializationSelect.JsonBodyInput.Range = "split-range=" + selectReq.InputSerializationSelect.JsonBodyInput.SplitRange
  901. }
  902. }
  903. // CsvOptions is a element in the SelectObject api request's params
  904. type SelectOptions struct {
  905. XMLName xml.Name `xml:"Options"`
  906. SkipPartialDataRecord *bool `xml:"SkipPartialDataRecord,omitempty"`
  907. MaxSkippedRecordsAllowed string `xml:"MaxSkippedRecordsAllowed,omitempty"`
  908. }
  909. // SelectObjectResult is the SelectObject api's return
  910. type SelectObjectResult struct {
  911. Version byte
  912. FrameType int32
  913. PayloadLength int32
  914. HeaderCheckSum uint32
  915. Offset uint64
  916. Data string // DataFrame
  917. EndFrame EndFrame // EndFrame
  918. MetaEndFrameCSV MetaEndFrameCSV // MetaEndFrameCSV
  919. MetaEndFrameJSON MetaEndFrameJSON // MetaEndFrameJSON
  920. PayloadChecksum uint32
  921. ReadFlagInfo
  922. }
  923. // ReadFlagInfo if reading the frame data, recode the reading status
  924. type ReadFlagInfo struct {
  925. OpenLine bool
  926. ConsumedBytesLength int32
  927. EnablePayloadCrc bool
  928. OutputRawData bool
  929. }
  930. // EndFrame is EndFrameType of SelectObject api
  931. type EndFrame struct {
  932. TotalScanned int64
  933. HTTPStatusCode int32
  934. ErrorMsg string
  935. }
  936. // MetaEndFrameCSV is MetaEndFrameCSVType of CreateSelectObjectMeta
  937. type MetaEndFrameCSV struct {
  938. TotalScanned int64
  939. Status int32
  940. SplitsCount int32
  941. RowsCount int64
  942. ColumnsCount int32
  943. ErrorMsg string
  944. }
  945. // MetaEndFrameJSON is MetaEndFrameJSON of CreateSelectObjectMeta
  946. type MetaEndFrameJSON struct {
  947. TotalScanned int64
  948. Status int32
  949. SplitsCount int32
  950. RowsCount int64
  951. ErrorMsg string
  952. }
  953. // InventoryConfiguration is Inventory config
  954. type InventoryConfiguration struct {
  955. XMLName xml.Name `xml:"InventoryConfiguration"`
  956. Id string `xml:"Id,omitempty"`
  957. IsEnabled *bool `xml:"IsEnabled,omitempty"`
  958. Prefix string `xml:"Filter>Prefix,omitempty"`
  959. OSSBucketDestination OSSBucketDestination `xml:"Destination>OSSBucketDestination,omitempty"`
  960. Frequency string `xml:"Schedule>Frequency,omitempty"`
  961. IncludedObjectVersions string `xml:"IncludedObjectVersions,omitempty"`
  962. OptionalFields OptionalFields `xml:OptionalFields,omitempty`
  963. }
  964. type OptionalFields struct {
  965. XMLName xml.Name `xml:"OptionalFields,omitempty`
  966. Field []string `xml:"Field,omitempty`
  967. }
  968. type OSSBucketDestination struct {
  969. XMLName xml.Name `xml:"OSSBucketDestination"`
  970. Format string `xml:"Format,omitempty"`
  971. AccountId string `xml:"AccountId,omitempty"`
  972. RoleArn string `xml:"RoleArn,omitempty"`
  973. Bucket string `xml:"Bucket,omitempty"`
  974. Prefix string `xml:"Prefix,omitempty"`
  975. Encryption *InvEncryption `xml:"Encryption,omitempty"`
  976. }
  977. type InvEncryption struct {
  978. XMLName xml.Name `xml:"Encryption"`
  979. SseOss *InvSseOss `xml:"SSE-OSS"`
  980. SseKms *InvSseKms `xml:"SSE-KMS"`
  981. }
  982. type InvSseOss struct {
  983. XMLName xml.Name `xml:"SSE-OSS"`
  984. }
  985. type InvSseKms struct {
  986. XMLName xml.Name `xml:"SSE-KMS"`
  987. KmsId string `xml:"KeyId,omitempty"`
  988. }
  989. type ListInventoryConfigurationsResult struct {
  990. XMLName xml.Name `xml:"ListInventoryConfigurationsResult"`
  991. InventoryConfiguration []InventoryConfiguration `xml:"InventoryConfiguration,omitempty`
  992. IsTruncated *bool `xml:"IsTruncated,omitempty"`
  993. NextContinuationToken string `xml:"NextContinuationToken,omitempty"`
  994. }
  995. // RestoreConfiguration for RestoreObject
  996. type RestoreConfiguration struct {
  997. XMLName xml.Name `xml:"RestoreRequest"`
  998. Days int32 `xml:"Days,omitempty"`
  999. Tier string `xml:"JobParameters>Tier,omitempty"`
  1000. }
  1001. // AsyncFetchTaskConfiguration for SetBucketAsyncFetchTask
  1002. type AsyncFetchTaskConfiguration struct {
  1003. XMLName xml.Name `xml:"AsyncFetchTaskConfiguration"`
  1004. Url string `xml:"Url,omitempty"`
  1005. Object string `xml:"Object,omitempty"`
  1006. Host string `xml:"Host,omitempty"`
  1007. ContentMD5 string `xml:"ContentMD5,omitempty"`
  1008. Callback string `xml:"Callback,omitempty"`
  1009. StorageClass string `xml:"StorageClass,omitempty"`
  1010. IgnoreSameKey bool `xml:"IgnoreSameKey"`
  1011. }
  1012. // AsyncFetchTaskResult for SetBucketAsyncFetchTask result
  1013. type AsyncFetchTaskResult struct {
  1014. XMLName xml.Name `xml:"AsyncFetchTaskResult"`
  1015. TaskId string `xml:"TaskId,omitempty"`
  1016. }
  1017. // AsynFetchTaskInfo for GetBucketAsyncFetchTask result
  1018. type AsynFetchTaskInfo struct {
  1019. XMLName xml.Name `xml:"AsyncFetchTaskInfo"`
  1020. TaskId string `xml:"TaskId,omitempty"`
  1021. State string `xml:"State,omitempty"`
  1022. ErrorMsg string `xml:"ErrorMsg,omitempty"`
  1023. TaskInfo AsyncTaskInfo `xml:"TaskInfo,omitempty"`
  1024. }
  1025. // AsyncTaskInfo for async task information
  1026. type AsyncTaskInfo struct {
  1027. XMLName xml.Name `xml:"TaskInfo"`
  1028. Url string `xml:"Url,omitempty"`
  1029. Object string `xml:"Object,omitempty"`
  1030. Host string `xml:"Host,omitempty"`
  1031. ContentMD5 string `xml:"ContentMD5,omitempty"`
  1032. Callback string `xml:"Callback,omitempty"`
  1033. StorageClass string `xml:"StorageClass,omitempty"`
  1034. IgnoreSameKey bool `xml:"IgnoreSameKey"`
  1035. }