type.go 51 KB

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