type.go 51 KB

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