type.go 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. package oss
  2. import (
  3. "encoding/xml"
  4. "fmt"
  5. "net/url"
  6. "time"
  7. )
  8. // ListBucketsResult defines the result object from ListBuckets request
  9. type ListBucketsResult struct {
  10. XMLName xml.Name `xml:"ListAllMyBucketsResult"`
  11. Prefix string `xml:"Prefix"` // The prefix in this query
  12. Marker string `xml:"Marker"` // The marker filter
  13. MaxKeys int `xml:"MaxKeys"` // The max entry count to return. This information is returned when IsTruncated is true.
  14. IsTruncated bool `xml:"IsTruncated"` // Flag true means there's remaining buckets to return.
  15. NextMarker string `xml:"NextMarker"` // The marker filter for the next list call
  16. Owner Owner `xml:"Owner"` // The owner information
  17. Buckets []BucketProperties `xml:"Buckets>Bucket"` // The bucket list
  18. }
  19. // BucketProperties defines bucket properties
  20. type BucketProperties struct {
  21. XMLName xml.Name `xml:"Bucket"`
  22. Name string `xml:"Name"` // Bucket name
  23. Location string `xml:"Location"` // Bucket datacenter
  24. CreationDate time.Time `xml:"CreationDate"` // Bucket create time
  25. StorageClass string `xml:"StorageClass"` // Bucket storage class
  26. }
  27. // GetBucketACLResult defines GetBucketACL request's result
  28. type GetBucketACLResult struct {
  29. XMLName xml.Name `xml:"AccessControlPolicy"`
  30. ACL string `xml:"AccessControlList>Grant"` // Bucket ACL
  31. Owner Owner `xml:"Owner"` // Bucket owner
  32. }
  33. // LifecycleConfiguration is the Bucket Lifecycle configuration
  34. type LifecycleConfiguration struct {
  35. XMLName xml.Name `xml:"LifecycleConfiguration"`
  36. Rules []LifecycleRule `xml:"Rule"`
  37. }
  38. // LifecycleRule defines Lifecycle rules
  39. type LifecycleRule struct {
  40. XMLName xml.Name `xml:"Rule"`
  41. ID string `xml:"ID,omitempty"` // The rule ID
  42. Prefix string `xml:"Prefix"` // The object key prefix
  43. Status string `xml:"Status"` // The rule status (enabled or not)
  44. Tags []Tag `xml:"Tag,omitempty"` // the tags property
  45. Expiration *LifecycleExpiration `xml:"Expiration,omitempty"` // The expiration property
  46. Transitions []LifecycleTransition `xml:"Transition,omitempty"` // The transition property
  47. AbortMultipartUpload *LifecycleAbortMultipartUpload `xml:"AbortMultipartUpload,omitempty"` // The AbortMultipartUpload property
  48. }
  49. // LifecycleExpiration defines the rule's expiration property
  50. type LifecycleExpiration struct {
  51. XMLName xml.Name `xml:"Expiration"`
  52. Days int `xml:"Days,omitempty"` // Relative expiration time: The expiration time in days after the last modified time
  53. Date string `xml:"Date,omitempty"` // Absolute expiration time: The expiration time in date, not recommended
  54. CreatedBeforeDate string `xml:"CreatedBeforeDate,omitempty"` // objects created before the date will be expired
  55. }
  56. // LifecycleTransition defines the rule's transition propery
  57. type LifecycleTransition struct {
  58. XMLName xml.Name `xml:"Transition"`
  59. Days int `xml:"Days,omitempty"` // Relative transition time: The transition time in days after the last modified time
  60. CreatedBeforeDate string `xml:"CreatedBeforeDate,omitempty"` // objects created before the date will be expired
  61. StorageClass StorageClassType `xml:"StorageClass,omitempty"` // Specifies the target storage type
  62. }
  63. // LifecycleAbortMultipartUpload defines the rule's abort multipart upload propery
  64. type LifecycleAbortMultipartUpload struct {
  65. XMLName xml.Name `xml:"AbortMultipartUpload"`
  66. Days int `xml:"Days,omitempty"` // Relative expiration time: The expiration time in days after the last modified time
  67. CreatedBeforeDate string `xml:"CreatedBeforeDate,omitempty"` // objects created before the date will be expired
  68. }
  69. const iso8601DateFormat = "2006-01-02T15:04:05.000Z"
  70. // BuildLifecycleRuleByDays builds a lifecycle rule objects will expiration in days after the last modified time
  71. func BuildLifecycleRuleByDays(id, prefix string, status bool, days int) LifecycleRule {
  72. var statusStr = "Enabled"
  73. if !status {
  74. statusStr = "Disabled"
  75. }
  76. return LifecycleRule{ID: id, Prefix: prefix, Status: statusStr,
  77. Expiration: &LifecycleExpiration{Days: days}}
  78. }
  79. // BuildLifecycleRuleByDate builds a lifecycle rule objects will expiration in specified date
  80. func BuildLifecycleRuleByDate(id, prefix string, status bool, year, month, day int) LifecycleRule {
  81. var statusStr = "Enabled"
  82. if !status {
  83. statusStr = "Disabled"
  84. }
  85. date := time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC).Format(iso8601DateFormat)
  86. return LifecycleRule{ID: id, Prefix: prefix, Status: statusStr,
  87. Expiration: &LifecycleExpiration{Date: date}}
  88. }
  89. // ValidateLifecycleRule Determine if a lifecycle rule is valid, if it is invalid, it will return an error.
  90. func verifyLifecycleRules(rules []LifecycleRule) error {
  91. if len(rules) == 0 {
  92. return fmt.Errorf("invalid rules, the length of rules is zero")
  93. }
  94. for _, rule := range rules {
  95. if rule.Status != "Enabled" && rule.Status != "Disabled" {
  96. return fmt.Errorf("invalid rule, the value of status must be Enabled or Disabled")
  97. }
  98. expiration := rule.Expiration
  99. if expiration != nil {
  100. if (expiration.Days != 0 && expiration.CreatedBeforeDate != "") || (expiration.Days != 0 && expiration.Date != "") || (expiration.CreatedBeforeDate != "" && expiration.Date != "") || (expiration.Days == 0 && expiration.CreatedBeforeDate == "" && expiration.Date == "") {
  101. return fmt.Errorf("invalid expiration lifecycle, must be set one of CreatedBeforeDate, Days and Date")
  102. }
  103. }
  104. abortMPU := rule.AbortMultipartUpload
  105. if abortMPU != nil {
  106. if (abortMPU.Days != 0 && abortMPU.CreatedBeforeDate != "") || (abortMPU.Days == 0 && abortMPU.CreatedBeforeDate == "") {
  107. return fmt.Errorf("invalid abort multipart upload lifecycle, must be set one of CreatedBeforeDate and Days")
  108. }
  109. }
  110. transitions := rule.Transitions
  111. if len(transitions) > 0 {
  112. if len(transitions) > 2 {
  113. return fmt.Errorf("invalid count of transition lifecycles, the count must than less than 3")
  114. }
  115. for _, transition := range transitions {
  116. if (transition.Days != 0 && transition.CreatedBeforeDate != "") || (transition.Days == 0 && transition.CreatedBeforeDate == "") {
  117. return fmt.Errorf("invalid transition lifecycle, must be set one of CreatedBeforeDate and Days")
  118. }
  119. if transition.StorageClass != StorageIA && transition.StorageClass != StorageArchive {
  120. return fmt.Errorf("invalid transition lifecylce, the value of storage class must be IA or Archive")
  121. }
  122. }
  123. } else if expiration == nil && abortMPU == nil {
  124. return fmt.Errorf("invalid rule, must set one of Expiration, AbortMultipartUplaod and Transitions")
  125. }
  126. }
  127. return nil
  128. }
  129. // GetBucketLifecycleResult defines GetBucketLifecycle's result object
  130. type GetBucketLifecycleResult LifecycleConfiguration
  131. // RefererXML defines Referer configuration
  132. type RefererXML struct {
  133. XMLName xml.Name `xml:"RefererConfiguration"`
  134. AllowEmptyReferer bool `xml:"AllowEmptyReferer"` // Allow empty referrer
  135. RefererList []string `xml:"RefererList>Referer"` // Referer whitelist
  136. }
  137. // GetBucketRefererResult defines result object for GetBucketReferer request
  138. type GetBucketRefererResult RefererXML
  139. // LoggingXML defines logging configuration
  140. type LoggingXML struct {
  141. XMLName xml.Name `xml:"BucketLoggingStatus"`
  142. LoggingEnabled LoggingEnabled `xml:"LoggingEnabled"` // The logging configuration information
  143. }
  144. type loggingXMLEmpty struct {
  145. XMLName xml.Name `xml:"BucketLoggingStatus"`
  146. }
  147. // LoggingEnabled defines the logging configuration information
  148. type LoggingEnabled struct {
  149. XMLName xml.Name `xml:"LoggingEnabled"`
  150. TargetBucket string `xml:"TargetBucket"` // The bucket name for storing the log files
  151. TargetPrefix string `xml:"TargetPrefix"` // The log file prefix
  152. }
  153. // GetBucketLoggingResult defines the result from GetBucketLogging request
  154. type GetBucketLoggingResult LoggingXML
  155. // WebsiteXML defines Website configuration
  156. type WebsiteXML struct {
  157. XMLName xml.Name `xml:"WebsiteConfiguration"`
  158. IndexDocument IndexDocument `xml:"IndexDocument,omitempty"` // The index page
  159. ErrorDocument ErrorDocument `xml:"ErrorDocument,omitempty"` // The error page
  160. RoutingRules []RoutingRule `xml:"RoutingRules>RoutingRule,omitempty"` // The routing Rule list
  161. }
  162. // IndexDocument defines the index page info
  163. type IndexDocument struct {
  164. XMLName xml.Name `xml:"IndexDocument"`
  165. Suffix string `xml:"Suffix"` // The file name for the index page
  166. }
  167. // ErrorDocument defines the 404 error page info
  168. type ErrorDocument struct {
  169. XMLName xml.Name `xml:"ErrorDocument"`
  170. Key string `xml:"Key"` // 404 error file name
  171. }
  172. // RoutingRule defines the routing rules
  173. type RoutingRule struct {
  174. XMLName xml.Name `xml:"RoutingRule"`
  175. RuleNumber int `xml:"RuleNumber,omitempty"` // The routing number
  176. Condition Condition `xml:"Condition,omitempty"` // The routing condition
  177. Redirect Redirect `xml:"Redirect,omitempty"` // The routing redirect
  178. }
  179. // Condition defines codition in the RoutingRule
  180. type Condition struct {
  181. XMLName xml.Name `xml:"Condition"`
  182. KeyPrefixEquals string `xml:"KeyPrefixEquals,omitempty"` // Matching objcet prefix
  183. HTTPErrorCodeReturnedEquals int `xml:"HttpErrorCodeReturnedEquals,omitempty"` // The rule is for Accessing to the specified object
  184. IncludeHeader []IncludeHeader `xml:"IncludeHeader"` // The rule is for request which include header
  185. }
  186. // IncludeHeader defines includeHeader in the RoutingRule's Condition
  187. type IncludeHeader struct {
  188. XMLName xml.Name `xml:"IncludeHeader"`
  189. Key string `xml:"Key,omitempty"` // The Include header key
  190. Equals string `xml:"Equals,omitempty"` // The Include header value
  191. }
  192. // Redirect defines redirect in the RoutingRule
  193. type Redirect struct {
  194. XMLName xml.Name `xml:"Redirect"`
  195. RedirectType string `xml:"RedirectType,omitempty"` // The redirect type, it have Mirror,External,Internal,AliCDN
  196. PassQueryString *bool `xml:"PassQueryString"` // Whether to send the specified request's parameters, true or false
  197. MirrorURL string `xml:"MirrorURL,omitempty"` // Mirror of the website address back to the source.
  198. MirrorPassQueryString *bool `xml:"MirrorPassQueryString"` // To Mirror of the website Whether to send the specified request's parameters, true or false
  199. MirrorFollowRedirect *bool `xml:"MirrorFollowRedirect"` // Redirect the location, if the mirror return 3XX
  200. MirrorCheckMd5 *bool `xml:"MirrorCheckMd5"` // Check the mirror is MD5.
  201. MirrorHeaders MirrorHeaders `xml:"MirrorHeaders,omitempty"` // Mirror headers
  202. Protocol string `xml:"Protocol,omitempty"` // The redirect Protocol
  203. HostName string `xml:"HostName,omitempty"` // The redirect HostName
  204. ReplaceKeyPrefixWith string `xml:"ReplaceKeyPrefixWith,omitempty"` // object name'Prefix replace the value
  205. HttpRedirectCode int `xml:"HttpRedirectCode,omitempty"` // THe redirect http code
  206. ReplaceKeyWith string `xml:"ReplaceKeyWith,omitempty"` // object name replace the value
  207. }
  208. // MirrorHeaders defines MirrorHeaders in the Redirect
  209. type MirrorHeaders struct {
  210. XMLName xml.Name `xml:"MirrorHeaders"`
  211. PassAll *bool `xml:"PassAll"` // Penetrating all of headers to source website.
  212. Pass []string `xml:"Pass"` // Penetrating some of headers to source website.
  213. Remove []string `xml:"Remove"` // Prohibit passthrough some of headers to source website
  214. Set []MirrorHeaderSet `xml:"Set"` // Setting some of headers send to source website
  215. }
  216. // MirrorHeaderSet defines Set for Redirect's MirrorHeaders
  217. type MirrorHeaderSet struct {
  218. XMLName xml.Name `xml:"Set"`
  219. Key string `xml:"Key,omitempty"` // The mirror header key
  220. Value string `xml:"Value,omitempty"` // The mirror header value
  221. }
  222. // GetBucketWebsiteResult defines the result from GetBucketWebsite request.
  223. type GetBucketWebsiteResult WebsiteXML
  224. // CORSXML defines CORS configuration
  225. type CORSXML struct {
  226. XMLName xml.Name `xml:"CORSConfiguration"`
  227. CORSRules []CORSRule `xml:"CORSRule"` // CORS rules
  228. }
  229. // CORSRule defines CORS rules
  230. type CORSRule struct {
  231. XMLName xml.Name `xml:"CORSRule"`
  232. AllowedOrigin []string `xml:"AllowedOrigin"` // Allowed origins. By default it's wildcard '*'
  233. AllowedMethod []string `xml:"AllowedMethod"` // Allowed methods
  234. AllowedHeader []string `xml:"AllowedHeader"` // Allowed headers
  235. ExposeHeader []string `xml:"ExposeHeader"` // Allowed response headers
  236. MaxAgeSeconds int `xml:"MaxAgeSeconds"` // Max cache ages in seconds
  237. }
  238. // GetBucketCORSResult defines the result from GetBucketCORS request.
  239. type GetBucketCORSResult CORSXML
  240. // GetBucketInfoResult defines the result from GetBucketInfo request.
  241. type GetBucketInfoResult struct {
  242. XMLName xml.Name `xml:"BucketInfo"`
  243. BucketInfo BucketInfo `xml:"Bucket"`
  244. }
  245. // BucketInfo defines Bucket information
  246. type BucketInfo struct {
  247. XMLName xml.Name `xml:"Bucket"`
  248. Name string `xml:"Name"` // Bucket name
  249. Location string `xml:"Location"` // Bucket datacenter
  250. CreationDate time.Time `xml:"CreationDate"` // Bucket creation time
  251. ExtranetEndpoint string `xml:"ExtranetEndpoint"` // Bucket external endpoint
  252. IntranetEndpoint string `xml:"IntranetEndpoint"` // Bucket internal endpoint
  253. ACL string `xml:"AccessControlList>Grant"` // Bucket ACL
  254. Owner Owner `xml:"Owner"` // Bucket owner
  255. StorageClass string `xml:"StorageClass"` // Bucket storage class
  256. SseRule SSERule `xml:"ServerSideEncryptionRule"` // Bucket ServerSideEncryptionRule
  257. Versioning string `xml:"Versioning"` // Bucket Versioning
  258. }
  259. type SSERule struct {
  260. XMLName xml.Name `xml:"ServerSideEncryptionRule"` // Bucket ServerSideEncryptionRule
  261. KMSMasterKeyID string `xml:"KMSMasterKeyID"` // Bucket KMSMasterKeyID
  262. SSEAlgorithm string `xml:"SSEAlgorithm"` // Bucket SSEAlgorithm
  263. }
  264. // ListObjectsResult defines the result from ListObjects request
  265. type ListObjectsResult struct {
  266. XMLName xml.Name `xml:"ListBucketResult"`
  267. Prefix string `xml:"Prefix"` // The object prefix
  268. Marker string `xml:"Marker"` // The marker filter.
  269. MaxKeys int `xml:"MaxKeys"` // Max keys to return
  270. Delimiter string `xml:"Delimiter"` // The delimiter for grouping objects' name
  271. IsTruncated bool `xml:"IsTruncated"` // Flag indicates if all results are returned (when it's false)
  272. NextMarker string `xml:"NextMarker"` // The start point of the next query
  273. Objects []ObjectProperties `xml:"Contents"` // Object list
  274. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // You can think of commonprefixes as "folders" whose names end with the delimiter
  275. }
  276. // ObjectProperties defines Objecct properties
  277. type ObjectProperties struct {
  278. XMLName xml.Name `xml:"Contents"`
  279. Key string `xml:"Key"` // Object key
  280. Type string `xml:"Type"` // Object type
  281. Size int64 `xml:"Size"` // Object size
  282. ETag string `xml:"ETag"` // Object ETag
  283. Owner Owner `xml:"Owner"` // Object owner information
  284. LastModified time.Time `xml:"LastModified"` // Object last modified time
  285. StorageClass string `xml:"StorageClass"` // Object storage class (Standard, IA, Archive)
  286. }
  287. // ListObjectVersionsResult defines the result from ListObjectVersions request
  288. type ListObjectVersionsResult struct {
  289. XMLName xml.Name `xml:"ListVersionsResult"`
  290. Name string `xml:"Name"` // The Bucket Name
  291. Owner Owner `xml:"Owner"` // The owner of bucket
  292. Prefix string `xml:"Prefix"` // The object prefix
  293. KeyMarker string `xml:"KeyMarker"` // The start marker filter.
  294. VersionIdMarker string `xml:"VersionIdMarker"` // The start VersionIdMarker filter.
  295. MaxKeys int `xml:"MaxKeys"` // Max keys to return
  296. Delimiter string `xml:"Delimiter"` // The delimiter for grouping objects' name
  297. IsTruncated bool `xml:"IsTruncated"` // Flag indicates if all results are returned (when it's false)
  298. NextKeyMarker string `xml:"NextKeyMarker"` // The start point of the next query
  299. NextVersionIdMarker string `xml:"NextVersionIdMarker"` // The start point of the next query
  300. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // You can think of commonprefixes as "folders" whose names end with the delimiter
  301. ObjectDeleteMarkers []ObjectDeleteMarkerProperties `xml:"DeleteMarker"` // DeleteMarker list
  302. ObjectVersions []ObjectVersionProperties `xml:"Version"` // version list
  303. }
  304. type ObjectDeleteMarkerProperties struct {
  305. XMLName xml.Name `xml:"DeleteMarker"`
  306. Key string `xml:"Key"` // The Object Key
  307. VersionId string `xml:"VersionId"` // The Object VersionId
  308. IsLatest bool `xml:"IsLatest"` // is current version or not
  309. LastModified time.Time `xml:"LastModified"` // Object last modified time
  310. Owner Owner `xml:"Owner"` // bucket owner element
  311. }
  312. type ObjectVersionProperties struct {
  313. XMLName xml.Name `xml:"Version"`
  314. Key string `xml:"Key"` // The Object Key
  315. VersionId string `xml:"VersionId"` // The Object VersionId
  316. IsLatest bool `xml:"IsLatest"` // is latest version or not
  317. LastModified time.Time `xml:"LastModified"` // Object last modified time
  318. Type string `xml:"Type"` // Object type
  319. Size int64 `xml:"Size"` // Object size
  320. ETag string `xml:"ETag"` // Object ETag
  321. StorageClass string `xml:"StorageClass"` // Object storage class (Standard, IA, Archive)
  322. Owner Owner `xml:"Owner"` // bucket owner element
  323. }
  324. // Owner defines Bucket/Object's owner
  325. type Owner struct {
  326. XMLName xml.Name `xml:"Owner"`
  327. ID string `xml:"ID"` // Owner ID
  328. DisplayName string `xml:"DisplayName"` // Owner's display name
  329. }
  330. // CopyObjectResult defines result object of CopyObject
  331. type CopyObjectResult struct {
  332. XMLName xml.Name `xml:"CopyObjectResult"`
  333. LastModified time.Time `xml:"LastModified"` // New object's last modified time.
  334. ETag string `xml:"ETag"` // New object's ETag
  335. }
  336. // GetObjectACLResult defines result of GetObjectACL request
  337. type GetObjectACLResult GetBucketACLResult
  338. type deleteXML struct {
  339. XMLName xml.Name `xml:"Delete"`
  340. Objects []DeleteObject `xml:"Object"` // Objects to delete
  341. Quiet bool `xml:"Quiet"` // Flag of quiet mode.
  342. }
  343. // DeleteObject defines the struct for deleting object
  344. type DeleteObject struct {
  345. XMLName xml.Name `xml:"Object"`
  346. Key string `xml:"Key"` // Object name
  347. VersionId string `xml:"VersionId,omitempty"` // Object VersionId
  348. }
  349. // DeleteObjectsResult defines result of DeleteObjects request
  350. type DeleteObjectsResult struct {
  351. XMLName xml.Name
  352. DeletedObjects []string // Deleted object key list
  353. }
  354. // DeleteObjectsResult_inner defines result of DeleteObjects request
  355. type DeleteObjectVersionsResult struct {
  356. XMLName xml.Name `xml:"DeleteResult"`
  357. DeletedObjectsDetail []DeletedKeyInfo `xml:"Deleted"` // Deleted object detail info
  358. }
  359. // DeleteKeyInfo defines object delete info
  360. type DeletedKeyInfo struct {
  361. XMLName xml.Name `xml:"Deleted"`
  362. Key string `xml:"Key"` // Object key
  363. VersionId string `xml:"VersionId"` // VersionId
  364. DeleteMarker bool `xml:"DeleteMarker"` // Object DeleteMarker
  365. DeleteMarkerVersionId string `xml:"DeleteMarkerVersionId"` // Object DeleteMarkerVersionId
  366. }
  367. // InitiateMultipartUploadResult defines result of InitiateMultipartUpload request
  368. type InitiateMultipartUploadResult struct {
  369. XMLName xml.Name `xml:"InitiateMultipartUploadResult"`
  370. Bucket string `xml:"Bucket"` // Bucket name
  371. Key string `xml:"Key"` // Object name to upload
  372. UploadID string `xml:"UploadId"` // Generated UploadId
  373. }
  374. // UploadPart defines the upload/copy part
  375. type UploadPart struct {
  376. XMLName xml.Name `xml:"Part"`
  377. PartNumber int `xml:"PartNumber"` // Part number
  378. ETag string `xml:"ETag"` // ETag value of the part's data
  379. }
  380. type uploadParts []UploadPart
  381. func (slice uploadParts) Len() int {
  382. return len(slice)
  383. }
  384. func (slice uploadParts) Less(i, j int) bool {
  385. return slice[i].PartNumber < slice[j].PartNumber
  386. }
  387. func (slice uploadParts) Swap(i, j int) {
  388. slice[i], slice[j] = slice[j], slice[i]
  389. }
  390. // UploadPartCopyResult defines result object of multipart copy request.
  391. type UploadPartCopyResult struct {
  392. XMLName xml.Name `xml:"CopyPartResult"`
  393. LastModified time.Time `xml:"LastModified"` // Last modified time
  394. ETag string `xml:"ETag"` // ETag
  395. }
  396. type completeMultipartUploadXML struct {
  397. XMLName xml.Name `xml:"CompleteMultipartUpload"`
  398. Part []UploadPart `xml:"Part"`
  399. }
  400. // CompleteMultipartUploadResult defines result object of CompleteMultipartUploadRequest
  401. type CompleteMultipartUploadResult struct {
  402. XMLName xml.Name `xml:"CompleteMultipartUploadResult"`
  403. Location string `xml:"Location"` // Object URL
  404. Bucket string `xml:"Bucket"` // Bucket name
  405. ETag string `xml:"ETag"` // Object ETag
  406. Key string `xml:"Key"` // Object name
  407. }
  408. // ListUploadedPartsResult defines result object of ListUploadedParts
  409. type ListUploadedPartsResult struct {
  410. XMLName xml.Name `xml:"ListPartsResult"`
  411. Bucket string `xml:"Bucket"` // Bucket name
  412. Key string `xml:"Key"` // Object name
  413. UploadID string `xml:"UploadId"` // Upload ID
  414. NextPartNumberMarker string `xml:"NextPartNumberMarker"` // Next part number
  415. MaxParts int `xml:"MaxParts"` // Max parts count
  416. IsTruncated bool `xml:"IsTruncated"` // Flag indicates all entries returned.false: all entries returned.
  417. UploadedParts []UploadedPart `xml:"Part"` // Uploaded parts
  418. }
  419. // UploadedPart defines uploaded part
  420. type UploadedPart struct {
  421. XMLName xml.Name `xml:"Part"`
  422. PartNumber int `xml:"PartNumber"` // Part number
  423. LastModified time.Time `xml:"LastModified"` // Last modified time
  424. ETag string `xml:"ETag"` // ETag cache
  425. Size int `xml:"Size"` // Part size
  426. }
  427. // ListMultipartUploadResult defines result object of ListMultipartUpload
  428. type ListMultipartUploadResult struct {
  429. XMLName xml.Name `xml:"ListMultipartUploadsResult"`
  430. Bucket string `xml:"Bucket"` // Bucket name
  431. Delimiter string `xml:"Delimiter"` // Delimiter for grouping object.
  432. Prefix string `xml:"Prefix"` // Object prefix
  433. KeyMarker string `xml:"KeyMarker"` // Object key marker
  434. UploadIDMarker string `xml:"UploadIdMarker"` // UploadId marker
  435. NextKeyMarker string `xml:"NextKeyMarker"` // Next key marker, if not all entries returned.
  436. NextUploadIDMarker string `xml:"NextUploadIdMarker"` // Next uploadId marker, if not all entries returned.
  437. MaxUploads int `xml:"MaxUploads"` // Max uploads to return
  438. IsTruncated bool `xml:"IsTruncated"` // Flag indicates all entries are returned.
  439. Uploads []UncompletedUpload `xml:"Upload"` // Ongoing uploads (not completed, not aborted)
  440. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // Common prefixes list.
  441. }
  442. // UncompletedUpload structure wraps an uncompleted upload task
  443. type UncompletedUpload struct {
  444. XMLName xml.Name `xml:"Upload"`
  445. Key string `xml:"Key"` // Object name
  446. UploadID string `xml:"UploadId"` // The UploadId
  447. Initiated time.Time `xml:"Initiated"` // Initialization time in the format such as 2012-02-23T04:18:23.000Z
  448. }
  449. // ProcessObjectResult defines result object of ProcessObject
  450. type ProcessObjectResult struct {
  451. Bucket string `json:"bucket"`
  452. FileSize int `json:"fileSize"`
  453. Object string `json:"object"`
  454. Status string `json:"status"`
  455. }
  456. // decodeDeleteObjectsResult decodes deleting objects result in URL encoding
  457. func decodeDeleteObjectsResult(result *DeleteObjectVersionsResult) error {
  458. var err error
  459. for i := 0; i < len(result.DeletedObjectsDetail); i++ {
  460. result.DeletedObjectsDetail[i].Key, err = url.QueryUnescape(result.DeletedObjectsDetail[i].Key)
  461. if err != nil {
  462. return err
  463. }
  464. }
  465. return nil
  466. }
  467. // decodeListObjectsResult decodes list objects result in URL encoding
  468. func decodeListObjectsResult(result *ListObjectsResult) error {
  469. var err error
  470. result.Prefix, err = url.QueryUnescape(result.Prefix)
  471. if err != nil {
  472. return err
  473. }
  474. result.Marker, err = url.QueryUnescape(result.Marker)
  475. if err != nil {
  476. return err
  477. }
  478. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  479. if err != nil {
  480. return err
  481. }
  482. result.NextMarker, err = url.QueryUnescape(result.NextMarker)
  483. if err != nil {
  484. return err
  485. }
  486. for i := 0; i < len(result.Objects); i++ {
  487. result.Objects[i].Key, err = url.QueryUnescape(result.Objects[i].Key)
  488. if err != nil {
  489. return err
  490. }
  491. }
  492. for i := 0; i < len(result.CommonPrefixes); i++ {
  493. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  494. if err != nil {
  495. return err
  496. }
  497. }
  498. return nil
  499. }
  500. // decodeListObjectVersionsResult decodes list version objects result in URL encoding
  501. func decodeListObjectVersionsResult(result *ListObjectVersionsResult) error {
  502. var err error
  503. // decode:Delimiter
  504. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  505. if err != nil {
  506. return err
  507. }
  508. // decode Prefix
  509. result.Prefix, err = url.QueryUnescape(result.Prefix)
  510. if err != nil {
  511. return err
  512. }
  513. // decode KeyMarker
  514. result.KeyMarker, err = url.QueryUnescape(result.KeyMarker)
  515. if err != nil {
  516. return err
  517. }
  518. // decode VersionIdMarker
  519. result.VersionIdMarker, err = url.QueryUnescape(result.VersionIdMarker)
  520. if err != nil {
  521. return err
  522. }
  523. // decode NextKeyMarker
  524. result.NextKeyMarker, err = url.QueryUnescape(result.NextKeyMarker)
  525. if err != nil {
  526. return err
  527. }
  528. // decode NextVersionIdMarker
  529. result.NextVersionIdMarker, err = url.QueryUnescape(result.NextVersionIdMarker)
  530. if err != nil {
  531. return err
  532. }
  533. // decode CommonPrefixes
  534. for i := 0; i < len(result.CommonPrefixes); i++ {
  535. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  536. if err != nil {
  537. return err
  538. }
  539. }
  540. // decode deleteMarker
  541. for i := 0; i < len(result.ObjectDeleteMarkers); i++ {
  542. result.ObjectDeleteMarkers[i].Key, err = url.QueryUnescape(result.ObjectDeleteMarkers[i].Key)
  543. if err != nil {
  544. return err
  545. }
  546. }
  547. // decode ObjectVersions
  548. for i := 0; i < len(result.ObjectVersions); i++ {
  549. result.ObjectVersions[i].Key, err = url.QueryUnescape(result.ObjectVersions[i].Key)
  550. if err != nil {
  551. return err
  552. }
  553. }
  554. return nil
  555. }
  556. // decodeListUploadedPartsResult decodes
  557. func decodeListUploadedPartsResult(result *ListUploadedPartsResult) error {
  558. var err error
  559. result.Key, err = url.QueryUnescape(result.Key)
  560. if err != nil {
  561. return err
  562. }
  563. return nil
  564. }
  565. // decodeListMultipartUploadResult decodes list multipart upload result in URL encoding
  566. func decodeListMultipartUploadResult(result *ListMultipartUploadResult) error {
  567. var err error
  568. result.Prefix, err = url.QueryUnescape(result.Prefix)
  569. if err != nil {
  570. return err
  571. }
  572. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  573. if err != nil {
  574. return err
  575. }
  576. result.KeyMarker, err = url.QueryUnescape(result.KeyMarker)
  577. if err != nil {
  578. return err
  579. }
  580. result.NextKeyMarker, err = url.QueryUnescape(result.NextKeyMarker)
  581. if err != nil {
  582. return err
  583. }
  584. for i := 0; i < len(result.Uploads); i++ {
  585. result.Uploads[i].Key, err = url.QueryUnescape(result.Uploads[i].Key)
  586. if err != nil {
  587. return err
  588. }
  589. }
  590. for i := 0; i < len(result.CommonPrefixes); i++ {
  591. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  592. if err != nil {
  593. return err
  594. }
  595. }
  596. return nil
  597. }
  598. // createBucketConfiguration defines the configuration for creating a bucket.
  599. type createBucketConfiguration struct {
  600. XMLName xml.Name `xml:"CreateBucketConfiguration"`
  601. StorageClass StorageClassType `xml:"StorageClass,omitempty"`
  602. }
  603. // LiveChannelConfiguration defines the configuration for live-channel
  604. type LiveChannelConfiguration struct {
  605. XMLName xml.Name `xml:"LiveChannelConfiguration"`
  606. Description string `xml:"Description,omitempty"` //Description of live-channel, up to 128 bytes
  607. Status string `xml:"Status,omitempty"` //Specify the status of livechannel
  608. Target LiveChannelTarget `xml:"Target"` //target configuration of live-channel
  609. // use point instead of struct to avoid omit empty snapshot
  610. Snapshot *LiveChannelSnapshot `xml:"Snapshot,omitempty"` //snapshot configuration of live-channel
  611. }
  612. // LiveChannelTarget target configuration of live-channel
  613. type LiveChannelTarget struct {
  614. XMLName xml.Name `xml:"Target"`
  615. Type string `xml:"Type"` //the type of object, only supports HLS
  616. FragDuration int `xml:"FragDuration,omitempty"` //the length of each ts object (in seconds), in the range [1,100]
  617. FragCount int `xml:"FragCount,omitempty"` //the number of ts objects in the m3u8 object, in the range of [1,100]
  618. PlaylistName string `xml:"PlaylistName,omitempty"` //the name of m3u8 object, which must end with ".m3u8" and the length range is [6,128]
  619. }
  620. // LiveChannelSnapshot snapshot configuration of live-channel
  621. type LiveChannelSnapshot struct {
  622. XMLName xml.Name `xml:"Snapshot"`
  623. 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.
  624. DestBucket string `xml:"DestBucket,omitempty"` //Bucket the snapshots will be written to. should be the same owner as the source bucket.
  625. NotifyTopic string `xml:"NotifyTopic,omitempty"` //Topics of MNS for notifying users of high frequency screenshot operation results
  626. Interval int `xml:"Interval,omitempty"` //interval of snapshots, threre is no snapshot if no I-frame during the interval time
  627. }
  628. // CreateLiveChannelResult the result of crete live-channel
  629. type CreateLiveChannelResult struct {
  630. XMLName xml.Name `xml:"CreateLiveChannelResult"`
  631. PublishUrls []string `xml:"PublishUrls>Url"` //push urls list
  632. PlayUrls []string `xml:"PlayUrls>Url"` //play urls list
  633. }
  634. // LiveChannelStat the result of get live-channel state
  635. type LiveChannelStat struct {
  636. XMLName xml.Name `xml:"LiveChannelStat"`
  637. Status string `xml:"Status"` //Current push status of live-channel: Disabled,Live,Idle
  638. ConnectedTime time.Time `xml:"ConnectedTime"` //The time when the client starts pushing, format: ISO8601
  639. RemoteAddr string `xml:"RemoteAddr"` //The ip address of the client
  640. Video LiveChannelVideo `xml:"Video"` //Video stream information
  641. Audio LiveChannelAudio `xml:"Audio"` //Audio stream information
  642. }
  643. // LiveChannelVideo video stream information
  644. type LiveChannelVideo struct {
  645. XMLName xml.Name `xml:"Video"`
  646. Width int `xml:"Width"` //Width (unit: pixels)
  647. Height int `xml:"Height"` //Height (unit: pixels)
  648. FrameRate int `xml:"FrameRate"` //FramRate
  649. Bandwidth int `xml:"Bandwidth"` //Bandwidth (unit: B/s)
  650. }
  651. // LiveChannelAudio audio stream information
  652. type LiveChannelAudio struct {
  653. XMLName xml.Name `xml:"Audio"`
  654. SampleRate int `xml:"SampleRate"` //SampleRate
  655. Bandwidth int `xml:"Bandwidth"` //Bandwidth (unit: B/s)
  656. Codec string `xml:"Codec"` //Encoding forma
  657. }
  658. // LiveChannelHistory the result of GetLiveChannelHistory, at most return up to lastest 10 push records
  659. type LiveChannelHistory struct {
  660. XMLName xml.Name `xml:"LiveChannelHistory"`
  661. Record []LiveRecord `xml:"LiveRecord"` //push records list
  662. }
  663. // LiveRecord push recode
  664. type LiveRecord struct {
  665. XMLName xml.Name `xml:"LiveRecord"`
  666. StartTime time.Time `xml:"StartTime"` //StartTime, format: ISO8601
  667. EndTime time.Time `xml:"EndTime"` //EndTime, format: ISO8601
  668. RemoteAddr string `xml:"RemoteAddr"` //The ip address of remote client
  669. }
  670. // ListLiveChannelResult the result of ListLiveChannel
  671. type ListLiveChannelResult struct {
  672. XMLName xml.Name `xml:"ListLiveChannelResult"`
  673. Prefix string `xml:"Prefix"` //Filter by the name start with the value of "Prefix"
  674. Marker string `xml:"Marker"` //cursor from which starting list
  675. MaxKeys int `xml:"MaxKeys"` //The maximum count returned. the default value is 100. it cannot be greater than 1000.
  676. IsTruncated bool `xml:"IsTruncated"` //Indicates whether all results have been returned, "true" indicates partial results returned while "false" indicates all results have been returned
  677. NextMarker string `xml:"NextMarker"` //NextMarker indicate the Marker value of the next request
  678. LiveChannel []LiveChannelInfo `xml:"LiveChannel"` //The infomation of live-channel
  679. }
  680. // LiveChannelInfo the infomation of live-channel
  681. type LiveChannelInfo struct {
  682. XMLName xml.Name `xml:"LiveChannel"`
  683. Name string `xml:"Name"` //The name of live-channel
  684. Description string `xml:"Description"` //Description of live-channel
  685. Status string `xml:"Status"` //Status: disabled or enabled
  686. LastModified time.Time `xml:"LastModified"` //Last modification time, format: ISO8601
  687. PublishUrls []string `xml:"PublishUrls>Url"` //push urls list
  688. PlayUrls []string `xml:"PlayUrls>Url"` //play urls list
  689. }
  690. // Tag a tag for the object
  691. type Tag struct {
  692. XMLName xml.Name `xml:"Tag"`
  693. Key string `xml:"Key"`
  694. Value string `xml:"Value"`
  695. }
  696. // Tagging tagset for the object
  697. type Tagging struct {
  698. XMLName xml.Name `xml:"Tagging"`
  699. Tags []Tag `xml:"TagSet>Tag,omitempty"`
  700. }
  701. // for GetObjectTagging return value
  702. type GetObjectTaggingResult Tagging
  703. // VersioningConfig for the bucket
  704. type VersioningConfig struct {
  705. XMLName xml.Name `xml:"VersioningConfiguration"`
  706. Status string `xml:"Status"`
  707. }
  708. type GetBucketVersioningResult VersioningConfig
  709. // Server Encryption rule for the bucket
  710. type ServerEncryptionRule struct {
  711. XMLName xml.Name `xml:"ServerSideEncryptionRule"`
  712. SSEDefault SSEDefaultRule `xml:"ApplyServerSideEncryptionByDefault"`
  713. }
  714. // Server Encryption deafult rule for the bucket
  715. type SSEDefaultRule struct {
  716. XMLName xml.Name `xml:"ApplyServerSideEncryptionByDefault"`
  717. SSEAlgorithm string `xml:"SSEAlgorithm"`
  718. KMSMasterKeyID string `xml:"KMSMasterKeyID"`
  719. }
  720. type GetBucketEncryptionResult ServerEncryptionRule
  721. type GetBucketTaggingResult Tagging
  722. type BucketStat struct {
  723. XMLName xml.Name `xml:"BucketStat"`
  724. Storage int64 `xml:"Storage"`
  725. ObjectCount int64 `xml:"ObjectCount"`
  726. MultipartUploadCount int64 `xml:"MultipartUploadCount"`
  727. }
  728. type GetBucketStatResult BucketStat
  729. // RequestPaymentConfiguration define the request payment configuration
  730. type RequestPaymentConfiguration struct {
  731. XMLName xml.Name `xml:"RequestPaymentConfiguration"`
  732. Payer string `xml:"Payer,omitempty"`
  733. }
  734. // BucketQoSConfiguration define QoS configuration
  735. type BucketQoSConfiguration struct {
  736. XMLName xml.Name `xml:"QoSConfiguration"`
  737. TotalUploadBandwidth *int `xml:"TotalUploadBandwidth"` // Total upload bandwidth
  738. IntranetUploadBandwidth *int `xml:"IntranetUploadBandwidth"` // Intranet upload bandwidth
  739. ExtranetUploadBandwidth *int `xml:"ExtranetUploadBandwidth"` // Extranet upload bandwidth
  740. TotalDownloadBandwidth *int `xml:"TotalDownloadBandwidth"` // Total download bandwidth
  741. IntranetDownloadBandwidth *int `xml:"IntranetDownloadBandwidth"` // Intranet download bandwidth
  742. ExtranetDownloadBandwidth *int `xml:"ExtranetDownloadBandwidth"` // Extranet download bandwidth
  743. TotalQPS *int `xml:"TotalQps"` // Total Qps
  744. IntranetQPS *int `xml:"IntranetQps"` // Intranet Qps
  745. ExtranetQPS *int `xml:"ExtranetQps"` // Extranet Qps
  746. }
  747. // UserQoSConfiguration define QoS and Range configuration
  748. type UserQoSConfiguration struct {
  749. XMLName xml.Name `xml:"QoSConfiguration"`
  750. Region string `xml:"Region,omitempty"` // Effective area of Qos configuration
  751. BucketQoSConfiguration
  752. }