type.go 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226
  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. // ListObjectsResultV2 defines the result from ListObjectsV2 request
  300. type ListObjectsResultV2 struct {
  301. XMLName xml.Name `xml:"ListBucketResult"`
  302. Prefix string `xml:"Prefix"` // The object prefix
  303. StartAfter string `xml:"StartAfter"` // the input StartAfter
  304. ContinuationToken string `xml:"ContinuationToken"` // the input ContinuationToken
  305. MaxKeys int `xml:"MaxKeys"` // Max keys to return
  306. Delimiter string `xml:"Delimiter"` // The delimiter for grouping objects' name
  307. IsTruncated bool `xml:"IsTruncated"` // Flag indicates if all results are returned (when it's false)
  308. NextContinuationToken string `xml:"NextContinuationToken"` // The start point of the next NextContinuationToken
  309. Objects []ObjectProperties `xml:"Contents"` // Object list
  310. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // You can think of commonprefixes as "folders" whose names end with the delimiter
  311. }
  312. // ListObjectVersionsResult defines the result from ListObjectVersions request
  313. type ListObjectVersionsResult struct {
  314. XMLName xml.Name `xml:"ListVersionsResult"`
  315. Name string `xml:"Name"` // The Bucket Name
  316. Owner Owner `xml:"Owner"` // The owner of bucket
  317. Prefix string `xml:"Prefix"` // The object prefix
  318. KeyMarker string `xml:"KeyMarker"` // The start marker filter.
  319. VersionIdMarker string `xml:"VersionIdMarker"` // The start VersionIdMarker filter.
  320. MaxKeys int `xml:"MaxKeys"` // Max keys to return
  321. Delimiter string `xml:"Delimiter"` // The delimiter for grouping objects' name
  322. IsTruncated bool `xml:"IsTruncated"` // Flag indicates if all results are returned (when it's false)
  323. NextKeyMarker string `xml:"NextKeyMarker"` // The start point of the next query
  324. NextVersionIdMarker string `xml:"NextVersionIdMarker"` // The start point of the next query
  325. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // You can think of commonprefixes as "folders" whose names end with the delimiter
  326. ObjectDeleteMarkers []ObjectDeleteMarkerProperties `xml:"DeleteMarker"` // DeleteMarker list
  327. ObjectVersions []ObjectVersionProperties `xml:"Version"` // version list
  328. }
  329. type ObjectDeleteMarkerProperties struct {
  330. XMLName xml.Name `xml:"DeleteMarker"`
  331. Key string `xml:"Key"` // The Object Key
  332. VersionId string `xml:"VersionId"` // The Object VersionId
  333. IsLatest bool `xml:"IsLatest"` // is current version or not
  334. LastModified time.Time `xml:"LastModified"` // Object last modified time
  335. Owner Owner `xml:"Owner"` // bucket owner element
  336. }
  337. type ObjectVersionProperties struct {
  338. XMLName xml.Name `xml:"Version"`
  339. Key string `xml:"Key"` // The Object Key
  340. VersionId string `xml:"VersionId"` // The Object VersionId
  341. IsLatest bool `xml:"IsLatest"` // is latest version or not
  342. LastModified time.Time `xml:"LastModified"` // Object last modified time
  343. Type string `xml:"Type"` // Object type
  344. Size int64 `xml:"Size"` // Object size
  345. ETag string `xml:"ETag"` // Object ETag
  346. StorageClass string `xml:"StorageClass"` // Object storage class (Standard, IA, Archive)
  347. Owner Owner `xml:"Owner"` // bucket owner element
  348. }
  349. // Owner defines Bucket/Object's owner
  350. type Owner struct {
  351. XMLName xml.Name `xml:"Owner"`
  352. ID string `xml:"ID"` // Owner ID
  353. DisplayName string `xml:"DisplayName"` // Owner's display name
  354. }
  355. // CopyObjectResult defines result object of CopyObject
  356. type CopyObjectResult struct {
  357. XMLName xml.Name `xml:"CopyObjectResult"`
  358. LastModified time.Time `xml:"LastModified"` // New object's last modified time.
  359. ETag string `xml:"ETag"` // New object's ETag
  360. }
  361. // GetObjectACLResult defines result of GetObjectACL request
  362. type GetObjectACLResult GetBucketACLResult
  363. type deleteXML struct {
  364. XMLName xml.Name `xml:"Delete"`
  365. Objects []DeleteObject `xml:"Object"` // Objects to delete
  366. Quiet bool `xml:"Quiet"` // Flag of quiet mode.
  367. }
  368. // DeleteObject defines the struct for deleting object
  369. type DeleteObject struct {
  370. XMLName xml.Name `xml:"Object"`
  371. Key string `xml:"Key"` // Object name
  372. VersionId string `xml:"VersionId,omitempty"` // Object VersionId
  373. }
  374. // DeleteObjectsResult defines result of DeleteObjects request
  375. type DeleteObjectsResult struct {
  376. XMLName xml.Name
  377. DeletedObjects []string // Deleted object key list
  378. }
  379. // DeleteObjectsResult_inner defines result of DeleteObjects request
  380. type DeleteObjectVersionsResult struct {
  381. XMLName xml.Name `xml:"DeleteResult"`
  382. DeletedObjectsDetail []DeletedKeyInfo `xml:"Deleted"` // Deleted object detail info
  383. }
  384. // DeleteKeyInfo defines object delete info
  385. type DeletedKeyInfo struct {
  386. XMLName xml.Name `xml:"Deleted"`
  387. Key string `xml:"Key"` // Object key
  388. VersionId string `xml:"VersionId"` // VersionId
  389. DeleteMarker bool `xml:"DeleteMarker"` // Object DeleteMarker
  390. DeleteMarkerVersionId string `xml:"DeleteMarkerVersionId"` // Object DeleteMarkerVersionId
  391. }
  392. // InitiateMultipartUploadResult defines result of InitiateMultipartUpload request
  393. type InitiateMultipartUploadResult struct {
  394. XMLName xml.Name `xml:"InitiateMultipartUploadResult"`
  395. Bucket string `xml:"Bucket"` // Bucket name
  396. Key string `xml:"Key"` // Object name to upload
  397. UploadID string `xml:"UploadId"` // Generated UploadId
  398. }
  399. // UploadPart defines the upload/copy part
  400. type UploadPart struct {
  401. XMLName xml.Name `xml:"Part"`
  402. PartNumber int `xml:"PartNumber"` // Part number
  403. ETag string `xml:"ETag"` // ETag value of the part's data
  404. }
  405. type UploadParts []UploadPart
  406. func (slice UploadParts) Len() int {
  407. return len(slice)
  408. }
  409. func (slice UploadParts) Less(i, j int) bool {
  410. return slice[i].PartNumber < slice[j].PartNumber
  411. }
  412. func (slice UploadParts) Swap(i, j int) {
  413. slice[i], slice[j] = slice[j], slice[i]
  414. }
  415. // UploadPartCopyResult defines result object of multipart copy request.
  416. type UploadPartCopyResult struct {
  417. XMLName xml.Name `xml:"CopyPartResult"`
  418. LastModified time.Time `xml:"LastModified"` // Last modified time
  419. ETag string `xml:"ETag"` // ETag
  420. }
  421. type completeMultipartUploadXML struct {
  422. XMLName xml.Name `xml:"CompleteMultipartUpload"`
  423. Part []UploadPart `xml:"Part"`
  424. }
  425. // CompleteMultipartUploadResult defines result object of CompleteMultipartUploadRequest
  426. type CompleteMultipartUploadResult struct {
  427. XMLName xml.Name `xml:"CompleteMultipartUploadResult"`
  428. Location string `xml:"Location"` // Object URL
  429. Bucket string `xml:"Bucket"` // Bucket name
  430. ETag string `xml:"ETag"` // Object ETag
  431. Key string `xml:"Key"` // Object name
  432. }
  433. // ListUploadedPartsResult defines result object of ListUploadedParts
  434. type ListUploadedPartsResult struct {
  435. XMLName xml.Name `xml:"ListPartsResult"`
  436. Bucket string `xml:"Bucket"` // Bucket name
  437. Key string `xml:"Key"` // Object name
  438. UploadID string `xml:"UploadId"` // Upload ID
  439. NextPartNumberMarker string `xml:"NextPartNumberMarker"` // Next part number
  440. MaxParts int `xml:"MaxParts"` // Max parts count
  441. IsTruncated bool `xml:"IsTruncated"` // Flag indicates all entries returned.false: all entries returned.
  442. UploadedParts []UploadedPart `xml:"Part"` // Uploaded parts
  443. }
  444. // UploadedPart defines uploaded part
  445. type UploadedPart struct {
  446. XMLName xml.Name `xml:"Part"`
  447. PartNumber int `xml:"PartNumber"` // Part number
  448. LastModified time.Time `xml:"LastModified"` // Last modified time
  449. ETag string `xml:"ETag"` // ETag cache
  450. Size int `xml:"Size"` // Part size
  451. }
  452. // ListMultipartUploadResult defines result object of ListMultipartUpload
  453. type ListMultipartUploadResult struct {
  454. XMLName xml.Name `xml:"ListMultipartUploadsResult"`
  455. Bucket string `xml:"Bucket"` // Bucket name
  456. Delimiter string `xml:"Delimiter"` // Delimiter for grouping object.
  457. Prefix string `xml:"Prefix"` // Object prefix
  458. KeyMarker string `xml:"KeyMarker"` // Object key marker
  459. UploadIDMarker string `xml:"UploadIdMarker"` // UploadId marker
  460. NextKeyMarker string `xml:"NextKeyMarker"` // Next key marker, if not all entries returned.
  461. NextUploadIDMarker string `xml:"NextUploadIdMarker"` // Next uploadId marker, if not all entries returned.
  462. MaxUploads int `xml:"MaxUploads"` // Max uploads to return
  463. IsTruncated bool `xml:"IsTruncated"` // Flag indicates all entries are returned.
  464. Uploads []UncompletedUpload `xml:"Upload"` // Ongoing uploads (not completed, not aborted)
  465. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // Common prefixes list.
  466. }
  467. // UncompletedUpload structure wraps an uncompleted upload task
  468. type UncompletedUpload struct {
  469. XMLName xml.Name `xml:"Upload"`
  470. Key string `xml:"Key"` // Object name
  471. UploadID string `xml:"UploadId"` // The UploadId
  472. Initiated time.Time `xml:"Initiated"` // Initialization time in the format such as 2012-02-23T04:18:23.000Z
  473. }
  474. // ProcessObjectResult defines result object of ProcessObject
  475. type ProcessObjectResult struct {
  476. Bucket string `json:"bucket"`
  477. FileSize int `json:"fileSize"`
  478. Object string `json:"object"`
  479. Status string `json:"status"`
  480. }
  481. // decodeDeleteObjectsResult decodes deleting objects result in URL encoding
  482. func decodeDeleteObjectsResult(result *DeleteObjectVersionsResult) error {
  483. var err error
  484. for i := 0; i < len(result.DeletedObjectsDetail); i++ {
  485. result.DeletedObjectsDetail[i].Key, err = url.QueryUnescape(result.DeletedObjectsDetail[i].Key)
  486. if err != nil {
  487. return err
  488. }
  489. }
  490. return nil
  491. }
  492. // decodeListObjectsResult decodes list objects result in URL encoding
  493. func decodeListObjectsResult(result *ListObjectsResult) error {
  494. var err error
  495. result.Prefix, err = url.QueryUnescape(result.Prefix)
  496. if err != nil {
  497. return err
  498. }
  499. result.Marker, err = url.QueryUnescape(result.Marker)
  500. if err != nil {
  501. return err
  502. }
  503. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  504. if err != nil {
  505. return err
  506. }
  507. result.NextMarker, err = url.QueryUnescape(result.NextMarker)
  508. if err != nil {
  509. return err
  510. }
  511. for i := 0; i < len(result.Objects); i++ {
  512. result.Objects[i].Key, err = url.QueryUnescape(result.Objects[i].Key)
  513. if err != nil {
  514. return err
  515. }
  516. }
  517. for i := 0; i < len(result.CommonPrefixes); i++ {
  518. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  519. if err != nil {
  520. return err
  521. }
  522. }
  523. return nil
  524. }
  525. // decodeListObjectsResult decodes list objects result in URL encoding
  526. func decodeListObjectsResultV2(result *ListObjectsResultV2) error {
  527. var err error
  528. result.Prefix, err = url.QueryUnescape(result.Prefix)
  529. if err != nil {
  530. return err
  531. }
  532. result.StartAfter, err = url.QueryUnescape(result.StartAfter)
  533. if err != nil {
  534. return err
  535. }
  536. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  537. if err != nil {
  538. return err
  539. }
  540. result.NextContinuationToken, err = url.QueryUnescape(result.NextContinuationToken)
  541. if err != nil {
  542. return err
  543. }
  544. for i := 0; i < len(result.Objects); i++ {
  545. result.Objects[i].Key, err = url.QueryUnescape(result.Objects[i].Key)
  546. if err != nil {
  547. return err
  548. }
  549. }
  550. for i := 0; i < len(result.CommonPrefixes); i++ {
  551. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  552. if err != nil {
  553. return err
  554. }
  555. }
  556. return nil
  557. }
  558. // decodeListObjectVersionsResult decodes list version objects result in URL encoding
  559. func decodeListObjectVersionsResult(result *ListObjectVersionsResult) error {
  560. var err error
  561. // decode:Delimiter
  562. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  563. if err != nil {
  564. return err
  565. }
  566. // decode Prefix
  567. result.Prefix, err = url.QueryUnescape(result.Prefix)
  568. if err != nil {
  569. return err
  570. }
  571. // decode KeyMarker
  572. result.KeyMarker, err = url.QueryUnescape(result.KeyMarker)
  573. if err != nil {
  574. return err
  575. }
  576. // decode VersionIdMarker
  577. result.VersionIdMarker, err = url.QueryUnescape(result.VersionIdMarker)
  578. if err != nil {
  579. return err
  580. }
  581. // decode NextKeyMarker
  582. result.NextKeyMarker, err = url.QueryUnescape(result.NextKeyMarker)
  583. if err != nil {
  584. return err
  585. }
  586. // decode NextVersionIdMarker
  587. result.NextVersionIdMarker, err = url.QueryUnescape(result.NextVersionIdMarker)
  588. if err != nil {
  589. return err
  590. }
  591. // decode CommonPrefixes
  592. for i := 0; i < len(result.CommonPrefixes); i++ {
  593. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  594. if err != nil {
  595. return err
  596. }
  597. }
  598. // decode deleteMarker
  599. for i := 0; i < len(result.ObjectDeleteMarkers); i++ {
  600. result.ObjectDeleteMarkers[i].Key, err = url.QueryUnescape(result.ObjectDeleteMarkers[i].Key)
  601. if err != nil {
  602. return err
  603. }
  604. }
  605. // decode ObjectVersions
  606. for i := 0; i < len(result.ObjectVersions); i++ {
  607. result.ObjectVersions[i].Key, err = url.QueryUnescape(result.ObjectVersions[i].Key)
  608. if err != nil {
  609. return err
  610. }
  611. }
  612. return nil
  613. }
  614. // decodeListUploadedPartsResult decodes
  615. func decodeListUploadedPartsResult(result *ListUploadedPartsResult) error {
  616. var err error
  617. result.Key, err = url.QueryUnescape(result.Key)
  618. if err != nil {
  619. return err
  620. }
  621. return nil
  622. }
  623. // decodeListMultipartUploadResult decodes list multipart upload result in URL encoding
  624. func decodeListMultipartUploadResult(result *ListMultipartUploadResult) error {
  625. var err error
  626. result.Prefix, err = url.QueryUnescape(result.Prefix)
  627. if err != nil {
  628. return err
  629. }
  630. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  631. if err != nil {
  632. return err
  633. }
  634. result.KeyMarker, err = url.QueryUnescape(result.KeyMarker)
  635. if err != nil {
  636. return err
  637. }
  638. result.NextKeyMarker, err = url.QueryUnescape(result.NextKeyMarker)
  639. if err != nil {
  640. return err
  641. }
  642. for i := 0; i < len(result.Uploads); i++ {
  643. result.Uploads[i].Key, err = url.QueryUnescape(result.Uploads[i].Key)
  644. if err != nil {
  645. return err
  646. }
  647. }
  648. for i := 0; i < len(result.CommonPrefixes); i++ {
  649. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  650. if err != nil {
  651. return err
  652. }
  653. }
  654. return nil
  655. }
  656. // createBucketConfiguration defines the configuration for creating a bucket.
  657. type createBucketConfiguration struct {
  658. XMLName xml.Name `xml:"CreateBucketConfiguration"`
  659. StorageClass StorageClassType `xml:"StorageClass,omitempty"`
  660. DataRedundancyType DataRedundancyType `xml:"DataRedundancyType,omitempty"`
  661. }
  662. // LiveChannelConfiguration defines the configuration for live-channel
  663. type LiveChannelConfiguration struct {
  664. XMLName xml.Name `xml:"LiveChannelConfiguration"`
  665. Description string `xml:"Description,omitempty"` //Description of live-channel, up to 128 bytes
  666. Status string `xml:"Status,omitempty"` //Specify the status of livechannel
  667. Target LiveChannelTarget `xml:"Target"` //target configuration of live-channel
  668. // use point instead of struct to avoid omit empty snapshot
  669. Snapshot *LiveChannelSnapshot `xml:"Snapshot,omitempty"` //snapshot configuration of live-channel
  670. }
  671. // LiveChannelTarget target configuration of live-channel
  672. type LiveChannelTarget struct {
  673. XMLName xml.Name `xml:"Target"`
  674. Type string `xml:"Type"` //the type of object, only supports HLS
  675. FragDuration int `xml:"FragDuration,omitempty"` //the length of each ts object (in seconds), in the range [1,100]
  676. FragCount int `xml:"FragCount,omitempty"` //the number of ts objects in the m3u8 object, in the range of [1,100]
  677. PlaylistName string `xml:"PlaylistName,omitempty"` //the name of m3u8 object, which must end with ".m3u8" and the length range is [6,128]
  678. }
  679. // LiveChannelSnapshot snapshot configuration of live-channel
  680. type LiveChannelSnapshot struct {
  681. XMLName xml.Name `xml:"Snapshot"`
  682. 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.
  683. DestBucket string `xml:"DestBucket,omitempty"` //Bucket the snapshots will be written to. should be the same owner as the source bucket.
  684. NotifyTopic string `xml:"NotifyTopic,omitempty"` //Topics of MNS for notifying users of high frequency screenshot operation results
  685. Interval int `xml:"Interval,omitempty"` //interval of snapshots, threre is no snapshot if no I-frame during the interval time
  686. }
  687. // CreateLiveChannelResult the result of crete live-channel
  688. type CreateLiveChannelResult struct {
  689. XMLName xml.Name `xml:"CreateLiveChannelResult"`
  690. PublishUrls []string `xml:"PublishUrls>Url"` //push urls list
  691. PlayUrls []string `xml:"PlayUrls>Url"` //play urls list
  692. }
  693. // LiveChannelStat the result of get live-channel state
  694. type LiveChannelStat struct {
  695. XMLName xml.Name `xml:"LiveChannelStat"`
  696. Status string `xml:"Status"` //Current push status of live-channel: Disabled,Live,Idle
  697. ConnectedTime time.Time `xml:"ConnectedTime"` //The time when the client starts pushing, format: ISO8601
  698. RemoteAddr string `xml:"RemoteAddr"` //The ip address of the client
  699. Video LiveChannelVideo `xml:"Video"` //Video stream information
  700. Audio LiveChannelAudio `xml:"Audio"` //Audio stream information
  701. }
  702. // LiveChannelVideo video stream information
  703. type LiveChannelVideo struct {
  704. XMLName xml.Name `xml:"Video"`
  705. Width int `xml:"Width"` //Width (unit: pixels)
  706. Height int `xml:"Height"` //Height (unit: pixels)
  707. FrameRate int `xml:"FrameRate"` //FramRate
  708. Bandwidth int `xml:"Bandwidth"` //Bandwidth (unit: B/s)
  709. }
  710. // LiveChannelAudio audio stream information
  711. type LiveChannelAudio struct {
  712. XMLName xml.Name `xml:"Audio"`
  713. SampleRate int `xml:"SampleRate"` //SampleRate
  714. Bandwidth int `xml:"Bandwidth"` //Bandwidth (unit: B/s)
  715. Codec string `xml:"Codec"` //Encoding forma
  716. }
  717. // LiveChannelHistory the result of GetLiveChannelHistory, at most return up to lastest 10 push records
  718. type LiveChannelHistory struct {
  719. XMLName xml.Name `xml:"LiveChannelHistory"`
  720. Record []LiveRecord `xml:"LiveRecord"` //push records list
  721. }
  722. // LiveRecord push recode
  723. type LiveRecord struct {
  724. XMLName xml.Name `xml:"LiveRecord"`
  725. StartTime time.Time `xml:"StartTime"` //StartTime, format: ISO8601
  726. EndTime time.Time `xml:"EndTime"` //EndTime, format: ISO8601
  727. RemoteAddr string `xml:"RemoteAddr"` //The ip address of remote client
  728. }
  729. // ListLiveChannelResult the result of ListLiveChannel
  730. type ListLiveChannelResult struct {
  731. XMLName xml.Name `xml:"ListLiveChannelResult"`
  732. Prefix string `xml:"Prefix"` //Filter by the name start with the value of "Prefix"
  733. Marker string `xml:"Marker"` //cursor from which starting list
  734. MaxKeys int `xml:"MaxKeys"` //The maximum count returned. the default value is 100. it cannot be greater than 1000.
  735. IsTruncated bool `xml:"IsTruncated"` //Indicates whether all results have been returned, "true" indicates partial results returned while "false" indicates all results have been returned
  736. NextMarker string `xml:"NextMarker"` //NextMarker indicate the Marker value of the next request
  737. LiveChannel []LiveChannelInfo `xml:"LiveChannel"` //The infomation of live-channel
  738. }
  739. // LiveChannelInfo the infomation of live-channel
  740. type LiveChannelInfo struct {
  741. XMLName xml.Name `xml:"LiveChannel"`
  742. Name string `xml:"Name"` //The name of live-channel
  743. Description string `xml:"Description"` //Description of live-channel
  744. Status string `xml:"Status"` //Status: disabled or enabled
  745. LastModified time.Time `xml:"LastModified"` //Last modification time, format: ISO8601
  746. PublishUrls []string `xml:"PublishUrls>Url"` //push urls list
  747. PlayUrls []string `xml:"PlayUrls>Url"` //play urls list
  748. }
  749. // Tag a tag for the object
  750. type Tag struct {
  751. XMLName xml.Name `xml:"Tag"`
  752. Key string `xml:"Key"`
  753. Value string `xml:"Value"`
  754. }
  755. // Tagging tagset for the object
  756. type Tagging struct {
  757. XMLName xml.Name `xml:"Tagging"`
  758. Tags []Tag `xml:"TagSet>Tag,omitempty"`
  759. }
  760. // for GetObjectTagging return value
  761. type GetObjectTaggingResult Tagging
  762. // VersioningConfig for the bucket
  763. type VersioningConfig struct {
  764. XMLName xml.Name `xml:"VersioningConfiguration"`
  765. Status string `xml:"Status"`
  766. }
  767. type GetBucketVersioningResult VersioningConfig
  768. // Server Encryption rule for the bucket
  769. type ServerEncryptionRule struct {
  770. XMLName xml.Name `xml:"ServerSideEncryptionRule"`
  771. SSEDefault SSEDefaultRule `xml:"ApplyServerSideEncryptionByDefault"`
  772. }
  773. // Server Encryption deafult rule for the bucket
  774. type SSEDefaultRule struct {
  775. XMLName xml.Name `xml:"ApplyServerSideEncryptionByDefault"`
  776. SSEAlgorithm string `xml:"SSEAlgorithm,omitempty"`
  777. KMSMasterKeyID string `xml:"KMSMasterKeyID,omitempty"`
  778. KMSDataEncryption string `xml:"KMSDataEncryption,,omitempty"`
  779. }
  780. type GetBucketEncryptionResult ServerEncryptionRule
  781. type GetBucketTaggingResult Tagging
  782. type BucketStat struct {
  783. XMLName xml.Name `xml:"BucketStat"`
  784. Storage int64 `xml:"Storage"`
  785. ObjectCount int64 `xml:"ObjectCount"`
  786. MultipartUploadCount int64 `xml:"MultipartUploadCount"`
  787. }
  788. type GetBucketStatResult BucketStat
  789. // RequestPaymentConfiguration define the request payment configuration
  790. type RequestPaymentConfiguration struct {
  791. XMLName xml.Name `xml:"RequestPaymentConfiguration"`
  792. Payer string `xml:"Payer,omitempty"`
  793. }
  794. // BucketQoSConfiguration define QoS configuration
  795. type BucketQoSConfiguration struct {
  796. XMLName xml.Name `xml:"QoSConfiguration"`
  797. TotalUploadBandwidth *int `xml:"TotalUploadBandwidth"` // Total upload bandwidth
  798. IntranetUploadBandwidth *int `xml:"IntranetUploadBandwidth"` // Intranet upload bandwidth
  799. ExtranetUploadBandwidth *int `xml:"ExtranetUploadBandwidth"` // Extranet upload bandwidth
  800. TotalDownloadBandwidth *int `xml:"TotalDownloadBandwidth"` // Total download bandwidth
  801. IntranetDownloadBandwidth *int `xml:"IntranetDownloadBandwidth"` // Intranet download bandwidth
  802. ExtranetDownloadBandwidth *int `xml:"ExtranetDownloadBandwidth"` // Extranet download bandwidth
  803. TotalQPS *int `xml:"TotalQps"` // Total Qps
  804. IntranetQPS *int `xml:"IntranetQps"` // Intranet Qps
  805. ExtranetQPS *int `xml:"ExtranetQps"` // Extranet Qps
  806. }
  807. // UserQoSConfiguration define QoS and Range configuration
  808. type UserQoSConfiguration struct {
  809. XMLName xml.Name `xml:"QoSConfiguration"`
  810. Region string `xml:"Region,omitempty"` // Effective area of Qos configuration
  811. BucketQoSConfiguration
  812. }
  813. //////////////////////////////////////////////////////////////
  814. /////////////////// Select OBject ////////////////////////////
  815. //////////////////////////////////////////////////////////////
  816. type CsvMetaRequest struct {
  817. XMLName xml.Name `xml:"CsvMetaRequest"`
  818. InputSerialization InputSerialization `xml:"InputSerialization"`
  819. OverwriteIfExists *bool `xml:"OverwriteIfExists,omitempty"`
  820. }
  821. // encodeBase64 encode base64 of the CreateSelectObjectMeta api request params
  822. func (meta *CsvMetaRequest) encodeBase64() {
  823. meta.InputSerialization.CSV.RecordDelimiter =
  824. base64.StdEncoding.EncodeToString([]byte(meta.InputSerialization.CSV.RecordDelimiter))
  825. meta.InputSerialization.CSV.FieldDelimiter =
  826. base64.StdEncoding.EncodeToString([]byte(meta.InputSerialization.CSV.FieldDelimiter))
  827. meta.InputSerialization.CSV.QuoteCharacter =
  828. base64.StdEncoding.EncodeToString([]byte(meta.InputSerialization.CSV.QuoteCharacter))
  829. }
  830. type JsonMetaRequest struct {
  831. XMLName xml.Name `xml:"JsonMetaRequest"`
  832. InputSerialization InputSerialization `xml:"InputSerialization"`
  833. OverwriteIfExists *bool `xml:"OverwriteIfExists,omitempty"`
  834. }
  835. type InputSerialization struct {
  836. XMLName xml.Name `xml:"InputSerialization"`
  837. CSV CSV `xml:CSV,omitempty`
  838. JSON JSON `xml:JSON,omitempty`
  839. CompressionType string `xml:"CompressionType,omitempty"`
  840. }
  841. type CSV struct {
  842. XMLName xml.Name `xml:"CSV"`
  843. RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
  844. FieldDelimiter string `xml:"FieldDelimiter,omitempty"`
  845. QuoteCharacter string `xml:"QuoteCharacter,omitempty"`
  846. }
  847. type JSON struct {
  848. XMLName xml.Name `xml:"JSON"`
  849. JSONType string `xml:"Type,omitempty"`
  850. }
  851. // SelectRequest is for the SelectObject request params of json file
  852. type SelectRequest struct {
  853. XMLName xml.Name `xml:"SelectRequest"`
  854. Expression string `xml:"Expression"`
  855. InputSerializationSelect InputSerializationSelect `xml:"InputSerialization"`
  856. OutputSerializationSelect OutputSerializationSelect `xml:"OutputSerialization"`
  857. SelectOptions SelectOptions `xml:"Options,omitempty"`
  858. }
  859. type InputSerializationSelect struct {
  860. XMLName xml.Name `xml:"InputSerialization"`
  861. CsvBodyInput CSVSelectInput `xml:CSV,omitempty`
  862. JsonBodyInput JSONSelectInput `xml:JSON,omitempty`
  863. CompressionType string `xml:"CompressionType,omitempty"`
  864. }
  865. type CSVSelectInput struct {
  866. XMLName xml.Name `xml:"CSV"`
  867. FileHeaderInfo string `xml:"FileHeaderInfo,omitempty"`
  868. RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
  869. FieldDelimiter string `xml:"FieldDelimiter,omitempty"`
  870. QuoteCharacter string `xml:"QuoteCharacter,omitempty"`
  871. CommentCharacter string `xml:"CommentCharacter,omitempty"`
  872. Range string `xml:"Range,omitempty"`
  873. SplitRange string
  874. }
  875. type JSONSelectInput struct {
  876. XMLName xml.Name `xml:"JSON"`
  877. JSONType string `xml:"Type,omitempty"`
  878. Range string `xml:"Range,omitempty"`
  879. ParseJSONNumberAsString *bool `xml:"ParseJsonNumberAsString"`
  880. SplitRange string
  881. }
  882. func (jsonInput *JSONSelectInput) JsonIsEmpty() bool {
  883. if jsonInput.JSONType != "" {
  884. return false
  885. }
  886. return true
  887. }
  888. type OutputSerializationSelect struct {
  889. XMLName xml.Name `xml:"OutputSerialization"`
  890. CsvBodyOutput CSVSelectOutput `xml:CSV,omitempty`
  891. JsonBodyOutput JSONSelectOutput `xml:JSON,omitempty`
  892. OutputRawData *bool `xml:"OutputRawData,omitempty"`
  893. KeepAllColumns *bool `xml:"KeepAllColumns,omitempty"`
  894. EnablePayloadCrc *bool `xml:"EnablePayloadCrc,omitempty"`
  895. OutputHeader *bool `xml:"OutputHeader,omitempty"`
  896. }
  897. type CSVSelectOutput struct {
  898. XMLName xml.Name `xml:"CSV"`
  899. RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
  900. FieldDelimiter string `xml:"FieldDelimiter,omitempty"`
  901. }
  902. type JSONSelectOutput struct {
  903. XMLName xml.Name `xml:"JSON"`
  904. RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
  905. }
  906. func (selectReq *SelectRequest) encodeBase64() {
  907. if selectReq.InputSerializationSelect.JsonBodyInput.JsonIsEmpty() {
  908. selectReq.csvEncodeBase64()
  909. } else {
  910. selectReq.jsonEncodeBase64()
  911. }
  912. }
  913. // csvEncodeBase64 encode base64 of the SelectObject api request params
  914. func (selectReq *SelectRequest) csvEncodeBase64() {
  915. selectReq.Expression = base64.StdEncoding.EncodeToString([]byte(selectReq.Expression))
  916. selectReq.InputSerializationSelect.CsvBodyInput.RecordDelimiter =
  917. base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.RecordDelimiter))
  918. selectReq.InputSerializationSelect.CsvBodyInput.FieldDelimiter =
  919. base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.FieldDelimiter))
  920. selectReq.InputSerializationSelect.CsvBodyInput.QuoteCharacter =
  921. base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.QuoteCharacter))
  922. selectReq.InputSerializationSelect.CsvBodyInput.CommentCharacter =
  923. base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.CommentCharacter))
  924. selectReq.OutputSerializationSelect.CsvBodyOutput.FieldDelimiter =
  925. base64.StdEncoding.EncodeToString([]byte(selectReq.OutputSerializationSelect.CsvBodyOutput.FieldDelimiter))
  926. selectReq.OutputSerializationSelect.CsvBodyOutput.RecordDelimiter =
  927. base64.StdEncoding.EncodeToString([]byte(selectReq.OutputSerializationSelect.CsvBodyOutput.RecordDelimiter))
  928. // handle Range
  929. if selectReq.InputSerializationSelect.CsvBodyInput.Range != "" {
  930. selectReq.InputSerializationSelect.CsvBodyInput.Range = "line-range=" + selectReq.InputSerializationSelect.CsvBodyInput.Range
  931. }
  932. if selectReq.InputSerializationSelect.CsvBodyInput.SplitRange != "" {
  933. selectReq.InputSerializationSelect.CsvBodyInput.Range = "split-range=" + selectReq.InputSerializationSelect.CsvBodyInput.SplitRange
  934. }
  935. }
  936. // jsonEncodeBase64 encode base64 of the SelectObject api request params
  937. func (selectReq *SelectRequest) jsonEncodeBase64() {
  938. selectReq.Expression = base64.StdEncoding.EncodeToString([]byte(selectReq.Expression))
  939. selectReq.OutputSerializationSelect.JsonBodyOutput.RecordDelimiter =
  940. base64.StdEncoding.EncodeToString([]byte(selectReq.OutputSerializationSelect.JsonBodyOutput.RecordDelimiter))
  941. // handle Range
  942. if selectReq.InputSerializationSelect.JsonBodyInput.Range != "" {
  943. selectReq.InputSerializationSelect.JsonBodyInput.Range = "line-range=" + selectReq.InputSerializationSelect.JsonBodyInput.Range
  944. }
  945. if selectReq.InputSerializationSelect.JsonBodyInput.SplitRange != "" {
  946. selectReq.InputSerializationSelect.JsonBodyInput.Range = "split-range=" + selectReq.InputSerializationSelect.JsonBodyInput.SplitRange
  947. }
  948. }
  949. // CsvOptions is a element in the SelectObject api request's params
  950. type SelectOptions struct {
  951. XMLName xml.Name `xml:"Options"`
  952. SkipPartialDataRecord *bool `xml:"SkipPartialDataRecord,omitempty"`
  953. MaxSkippedRecordsAllowed string `xml:"MaxSkippedRecordsAllowed,omitempty"`
  954. }
  955. // SelectObjectResult is the SelectObject api's return
  956. type SelectObjectResult struct {
  957. Version byte
  958. FrameType int32
  959. PayloadLength int32
  960. HeaderCheckSum uint32
  961. Offset uint64
  962. Data string // DataFrame
  963. EndFrame EndFrame // EndFrame
  964. MetaEndFrameCSV MetaEndFrameCSV // MetaEndFrameCSV
  965. MetaEndFrameJSON MetaEndFrameJSON // MetaEndFrameJSON
  966. PayloadChecksum uint32
  967. ReadFlagInfo
  968. }
  969. // ReadFlagInfo if reading the frame data, recode the reading status
  970. type ReadFlagInfo struct {
  971. OpenLine bool
  972. ConsumedBytesLength int32
  973. EnablePayloadCrc bool
  974. OutputRawData bool
  975. }
  976. // EndFrame is EndFrameType of SelectObject api
  977. type EndFrame struct {
  978. TotalScanned int64
  979. HTTPStatusCode int32
  980. ErrorMsg string
  981. }
  982. // MetaEndFrameCSV is MetaEndFrameCSVType of CreateSelectObjectMeta
  983. type MetaEndFrameCSV struct {
  984. TotalScanned int64
  985. Status int32
  986. SplitsCount int32
  987. RowsCount int64
  988. ColumnsCount int32
  989. ErrorMsg string
  990. }
  991. // MetaEndFrameJSON is MetaEndFrameJSON of CreateSelectObjectMeta
  992. type MetaEndFrameJSON struct {
  993. TotalScanned int64
  994. Status int32
  995. SplitsCount int32
  996. RowsCount int64
  997. ErrorMsg string
  998. }
  999. // InventoryConfiguration is Inventory config
  1000. type InventoryConfiguration struct {
  1001. XMLName xml.Name `xml:"InventoryConfiguration"`
  1002. Id string `xml:"Id,omitempty"`
  1003. IsEnabled *bool `xml:"IsEnabled,omitempty"`
  1004. Prefix string `xml:"Filter>Prefix,omitempty"`
  1005. OSSBucketDestination OSSBucketDestination `xml:"Destination>OSSBucketDestination,omitempty"`
  1006. Frequency string `xml:"Schedule>Frequency,omitempty"`
  1007. IncludedObjectVersions string `xml:"IncludedObjectVersions,omitempty"`
  1008. OptionalFields OptionalFields `xml:OptionalFields,omitempty`
  1009. }
  1010. type OptionalFields struct {
  1011. XMLName xml.Name `xml:"OptionalFields,omitempty`
  1012. Field []string `xml:"Field,omitempty`
  1013. }
  1014. type OSSBucketDestination struct {
  1015. XMLName xml.Name `xml:"OSSBucketDestination"`
  1016. Format string `xml:"Format,omitempty"`
  1017. AccountId string `xml:"AccountId,omitempty"`
  1018. RoleArn string `xml:"RoleArn,omitempty"`
  1019. Bucket string `xml:"Bucket,omitempty"`
  1020. Prefix string `xml:"Prefix,omitempty"`
  1021. Encryption *InvEncryption `xml:"Encryption,omitempty"`
  1022. }
  1023. type InvEncryption struct {
  1024. XMLName xml.Name `xml:"Encryption"`
  1025. SseOss *InvSseOss `xml:"SSE-OSS"`
  1026. SseKms *InvSseKms `xml:"SSE-KMS"`
  1027. }
  1028. type InvSseOss struct {
  1029. XMLName xml.Name `xml:"SSE-OSS"`
  1030. }
  1031. type InvSseKms struct {
  1032. XMLName xml.Name `xml:"SSE-KMS"`
  1033. KmsId string `xml:"KeyId,omitempty"`
  1034. }
  1035. type ListInventoryConfigurationsResult struct {
  1036. XMLName xml.Name `xml:"ListInventoryConfigurationsResult"`
  1037. InventoryConfiguration []InventoryConfiguration `xml:"InventoryConfiguration,omitempty`
  1038. IsTruncated *bool `xml:"IsTruncated,omitempty"`
  1039. NextContinuationToken string `xml:"NextContinuationToken,omitempty"`
  1040. }
  1041. // RestoreConfiguration for RestoreObject
  1042. type RestoreConfiguration struct {
  1043. XMLName xml.Name `xml:"RestoreRequest"`
  1044. Days int32 `xml:"Days,omitempty"`
  1045. Tier string `xml:"JobParameters>Tier,omitempty"`
  1046. }
  1047. // AsyncFetchTaskConfiguration for SetBucketAsyncFetchTask
  1048. type AsyncFetchTaskConfiguration struct {
  1049. XMLName xml.Name `xml:"AsyncFetchTaskConfiguration"`
  1050. Url string `xml:"Url,omitempty"`
  1051. Object string `xml:"Object,omitempty"`
  1052. Host string `xml:"Host,omitempty"`
  1053. ContentMD5 string `xml:"ContentMD5,omitempty"`
  1054. Callback string `xml:"Callback,omitempty"`
  1055. StorageClass string `xml:"StorageClass,omitempty"`
  1056. IgnoreSameKey bool `xml:"IgnoreSameKey"`
  1057. }
  1058. // AsyncFetchTaskResult for SetBucketAsyncFetchTask result
  1059. type AsyncFetchTaskResult struct {
  1060. XMLName xml.Name `xml:"AsyncFetchTaskResult"`
  1061. TaskId string `xml:"TaskId,omitempty"`
  1062. }
  1063. // AsynFetchTaskInfo for GetBucketAsyncFetchTask result
  1064. type AsynFetchTaskInfo struct {
  1065. XMLName xml.Name `xml:"AsyncFetchTaskInfo"`
  1066. TaskId string `xml:"TaskId,omitempty"`
  1067. State string `xml:"State,omitempty"`
  1068. ErrorMsg string `xml:"ErrorMsg,omitempty"`
  1069. TaskInfo AsyncTaskInfo `xml:"TaskInfo,omitempty"`
  1070. }
  1071. // AsyncTaskInfo for async task information
  1072. type AsyncTaskInfo struct {
  1073. XMLName xml.Name `xml:"TaskInfo"`
  1074. Url string `xml:"Url,omitempty"`
  1075. Object string `xml:"Object,omitempty"`
  1076. Host string `xml:"Host,omitempty"`
  1077. ContentMD5 string `xml:"ContentMD5,omitempty"`
  1078. Callback string `xml:"Callback,omitempty"`
  1079. StorageClass string `xml:"StorageClass,omitempty"`
  1080. IgnoreSameKey bool `xml:"IgnoreSameKey"`
  1081. }