type.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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"` // The index page
  159. ErrorDocument ErrorDocument `xml:"ErrorDocument"` // The error page
  160. }
  161. // IndexDocument defines the index page info
  162. type IndexDocument struct {
  163. XMLName xml.Name `xml:"IndexDocument"`
  164. Suffix string `xml:"Suffix"` // The file name for the index page
  165. }
  166. // ErrorDocument defines the 404 error page info
  167. type ErrorDocument struct {
  168. XMLName xml.Name `xml:"ErrorDocument"`
  169. Key string `xml:"Key"` // 404 error file name
  170. }
  171. // GetBucketWebsiteResult defines the result from GetBucketWebsite request.
  172. type GetBucketWebsiteResult WebsiteXML
  173. // CORSXML defines CORS configuration
  174. type CORSXML struct {
  175. XMLName xml.Name `xml:"CORSConfiguration"`
  176. CORSRules []CORSRule `xml:"CORSRule"` // CORS rules
  177. }
  178. // CORSRule defines CORS rules
  179. type CORSRule struct {
  180. XMLName xml.Name `xml:"CORSRule"`
  181. AllowedOrigin []string `xml:"AllowedOrigin"` // Allowed origins. By default it's wildcard '*'
  182. AllowedMethod []string `xml:"AllowedMethod"` // Allowed methods
  183. AllowedHeader []string `xml:"AllowedHeader"` // Allowed headers
  184. ExposeHeader []string `xml:"ExposeHeader"` // Allowed response headers
  185. MaxAgeSeconds int `xml:"MaxAgeSeconds"` // Max cache ages in seconds
  186. }
  187. // GetBucketCORSResult defines the result from GetBucketCORS request.
  188. type GetBucketCORSResult CORSXML
  189. // GetBucketInfoResult defines the result from GetBucketInfo request.
  190. type GetBucketInfoResult struct {
  191. XMLName xml.Name `xml:"BucketInfo"`
  192. BucketInfo BucketInfo `xml:"Bucket"`
  193. }
  194. // BucketInfo defines Bucket information
  195. type BucketInfo struct {
  196. XMLName xml.Name `xml:"Bucket"`
  197. Name string `xml:"Name"` // Bucket name
  198. Location string `xml:"Location"` // Bucket datacenter
  199. CreationDate time.Time `xml:"CreationDate"` // Bucket creation time
  200. ExtranetEndpoint string `xml:"ExtranetEndpoint"` // Bucket external endpoint
  201. IntranetEndpoint string `xml:"IntranetEndpoint"` // Bucket internal endpoint
  202. ACL string `xml:"AccessControlList>Grant"` // Bucket ACL
  203. Owner Owner `xml:"Owner"` // Bucket owner
  204. StorageClass string `xml:"StorageClass"` // Bucket storage class
  205. SseRule SSERule `xml:"ServerSideEncryptionRule"` // Bucket ServerSideEncryptionRule
  206. }
  207. type SSERule struct {
  208. XMLName xml.Name `xml:"ServerSideEncryptionRule"` // Bucket ServerSideEncryptionRule
  209. KMSMasterKeyID string `xml:"KMSMasterKeyID"` // Bucket KMSMasterKeyID
  210. SSEAlgorithm string `xml:"SSEAlgorithm"` // Bucket SSEAlgorithm
  211. }
  212. // ListObjectsResult defines the result from ListObjects request
  213. type ListObjectsResult struct {
  214. XMLName xml.Name `xml:"ListBucketResult"`
  215. Prefix string `xml:"Prefix"` // The object prefix
  216. Marker string `xml:"Marker"` // The marker filter.
  217. MaxKeys int `xml:"MaxKeys"` // Max keys to return
  218. Delimiter string `xml:"Delimiter"` // The delimiter for grouping objects' name
  219. IsTruncated bool `xml:"IsTruncated"` // Flag indicates if all results are returned (when it's false)
  220. NextMarker string `xml:"NextMarker"` // The start point of the next query
  221. Objects []ObjectProperties `xml:"Contents"` // Object list
  222. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // You can think of commonprefixes as "folders" whose names end with the delimiter
  223. }
  224. // ObjectProperties defines Objecct properties
  225. type ObjectProperties struct {
  226. XMLName xml.Name `xml:"Contents"`
  227. Key string `xml:"Key"` // Object key
  228. Type string `xml:"Type"` // Object type
  229. Size int64 `xml:"Size"` // Object size
  230. ETag string `xml:"ETag"` // Object ETag
  231. Owner Owner `xml:"Owner"` // Object owner information
  232. LastModified time.Time `xml:"LastModified"` // Object last modified time
  233. StorageClass string `xml:"StorageClass"` // Object storage class (Standard, IA, Archive)
  234. }
  235. // Owner defines Bucket/Object's owner
  236. type Owner struct {
  237. XMLName xml.Name `xml:"Owner"`
  238. ID string `xml:"ID"` // Owner ID
  239. DisplayName string `xml:"DisplayName"` // Owner's display name
  240. }
  241. // CopyObjectResult defines result object of CopyObject
  242. type CopyObjectResult struct {
  243. XMLName xml.Name `xml:"CopyObjectResult"`
  244. LastModified time.Time `xml:"LastModified"` // New object's last modified time.
  245. ETag string `xml:"ETag"` // New object's ETag
  246. }
  247. // GetObjectACLResult defines result of GetObjectACL request
  248. type GetObjectACLResult GetBucketACLResult
  249. type deleteXML struct {
  250. XMLName xml.Name `xml:"Delete"`
  251. Objects []DeleteObject `xml:"Object"` // Objects to delete
  252. Quiet bool `xml:"Quiet"` // Flag of quiet mode.
  253. }
  254. // DeleteObject defines the struct for deleting object
  255. type DeleteObject struct {
  256. XMLName xml.Name `xml:"Object"`
  257. Key string `xml:"Key"` // Object name
  258. }
  259. // DeleteObjectsResult defines result of DeleteObjects request
  260. type DeleteObjectsResult struct {
  261. XMLName xml.Name `xml:"DeleteResult"`
  262. DeletedObjects []string `xml:"Deleted>Key"` // Deleted object list
  263. }
  264. // InitiateMultipartUploadResult defines result of InitiateMultipartUpload request
  265. type InitiateMultipartUploadResult struct {
  266. XMLName xml.Name `xml:"InitiateMultipartUploadResult"`
  267. Bucket string `xml:"Bucket"` // Bucket name
  268. Key string `xml:"Key"` // Object name to upload
  269. UploadID string `xml:"UploadId"` // Generated UploadId
  270. }
  271. // UploadPart defines the upload/copy part
  272. type UploadPart struct {
  273. XMLName xml.Name `xml:"Part"`
  274. PartNumber int `xml:"PartNumber"` // Part number
  275. ETag string `xml:"ETag"` // ETag value of the part's data
  276. }
  277. type uploadParts []UploadPart
  278. func (slice uploadParts) Len() int {
  279. return len(slice)
  280. }
  281. func (slice uploadParts) Less(i, j int) bool {
  282. return slice[i].PartNumber < slice[j].PartNumber
  283. }
  284. func (slice uploadParts) Swap(i, j int) {
  285. slice[i], slice[j] = slice[j], slice[i]
  286. }
  287. // UploadPartCopyResult defines result object of multipart copy request.
  288. type UploadPartCopyResult struct {
  289. XMLName xml.Name `xml:"CopyPartResult"`
  290. LastModified time.Time `xml:"LastModified"` // Last modified time
  291. ETag string `xml:"ETag"` // ETag
  292. }
  293. type completeMultipartUploadXML struct {
  294. XMLName xml.Name `xml:"CompleteMultipartUpload"`
  295. Part []UploadPart `xml:"Part"`
  296. }
  297. // CompleteMultipartUploadResult defines result object of CompleteMultipartUploadRequest
  298. type CompleteMultipartUploadResult struct {
  299. XMLName xml.Name `xml:"CompleteMultipartUploadResult"`
  300. Location string `xml:"Location"` // Object URL
  301. Bucket string `xml:"Bucket"` // Bucket name
  302. ETag string `xml:"ETag"` // Object ETag
  303. Key string `xml:"Key"` // Object name
  304. }
  305. // ListUploadedPartsResult defines result object of ListUploadedParts
  306. type ListUploadedPartsResult struct {
  307. XMLName xml.Name `xml:"ListPartsResult"`
  308. Bucket string `xml:"Bucket"` // Bucket name
  309. Key string `xml:"Key"` // Object name
  310. UploadID string `xml:"UploadId"` // Upload ID
  311. NextPartNumberMarker string `xml:"NextPartNumberMarker"` // Next part number
  312. MaxParts int `xml:"MaxParts"` // Max parts count
  313. IsTruncated bool `xml:"IsTruncated"` // Flag indicates all entries returned.false: all entries returned.
  314. UploadedParts []UploadedPart `xml:"Part"` // Uploaded parts
  315. }
  316. // UploadedPart defines uploaded part
  317. type UploadedPart struct {
  318. XMLName xml.Name `xml:"Part"`
  319. PartNumber int `xml:"PartNumber"` // Part number
  320. LastModified time.Time `xml:"LastModified"` // Last modified time
  321. ETag string `xml:"ETag"` // ETag cache
  322. Size int `xml:"Size"` // Part size
  323. }
  324. // ListMultipartUploadResult defines result object of ListMultipartUpload
  325. type ListMultipartUploadResult struct {
  326. XMLName xml.Name `xml:"ListMultipartUploadsResult"`
  327. Bucket string `xml:"Bucket"` // Bucket name
  328. Delimiter string `xml:"Delimiter"` // Delimiter for grouping object.
  329. Prefix string `xml:"Prefix"` // Object prefix
  330. KeyMarker string `xml:"KeyMarker"` // Object key marker
  331. UploadIDMarker string `xml:"UploadIdMarker"` // UploadId marker
  332. NextKeyMarker string `xml:"NextKeyMarker"` // Next key marker, if not all entries returned.
  333. NextUploadIDMarker string `xml:"NextUploadIdMarker"` // Next uploadId marker, if not all entries returned.
  334. MaxUploads int `xml:"MaxUploads"` // Max uploads to return
  335. IsTruncated bool `xml:"IsTruncated"` // Flag indicates all entries are returned.
  336. Uploads []UncompletedUpload `xml:"Upload"` // Ongoing uploads (not completed, not aborted)
  337. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // Common prefixes list.
  338. }
  339. // UncompletedUpload structure wraps an uncompleted upload task
  340. type UncompletedUpload struct {
  341. XMLName xml.Name `xml:"Upload"`
  342. Key string `xml:"Key"` // Object name
  343. UploadID string `xml:"UploadId"` // The UploadId
  344. Initiated time.Time `xml:"Initiated"` // Initialization time in the format such as 2012-02-23T04:18:23.000Z
  345. }
  346. // ProcessObjectResult defines result object of ProcessObject
  347. type ProcessObjectResult struct {
  348. Bucket string `json:"bucket"`
  349. FileSize int `json:"fileSize"`
  350. Object string `json:"object"`
  351. Status string `json:"status"`
  352. }
  353. // decodeDeleteObjectsResult decodes deleting objects result in URL encoding
  354. func decodeDeleteObjectsResult(result *DeleteObjectsResult) error {
  355. var err error
  356. for i := 0; i < len(result.DeletedObjects); i++ {
  357. result.DeletedObjects[i], err = url.QueryUnescape(result.DeletedObjects[i])
  358. if err != nil {
  359. return err
  360. }
  361. }
  362. return nil
  363. }
  364. // decodeListObjectsResult decodes list objects result in URL encoding
  365. func decodeListObjectsResult(result *ListObjectsResult) error {
  366. var err error
  367. result.Prefix, err = url.QueryUnescape(result.Prefix)
  368. if err != nil {
  369. return err
  370. }
  371. result.Marker, err = url.QueryUnescape(result.Marker)
  372. if err != nil {
  373. return err
  374. }
  375. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  376. if err != nil {
  377. return err
  378. }
  379. result.NextMarker, err = url.QueryUnescape(result.NextMarker)
  380. if err != nil {
  381. return err
  382. }
  383. for i := 0; i < len(result.Objects); i++ {
  384. result.Objects[i].Key, err = url.QueryUnescape(result.Objects[i].Key)
  385. if err != nil {
  386. return err
  387. }
  388. }
  389. for i := 0; i < len(result.CommonPrefixes); i++ {
  390. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  391. if err != nil {
  392. return err
  393. }
  394. }
  395. return nil
  396. }
  397. // decodeListUploadedPartsResult decodes
  398. func decodeListUploadedPartsResult(result *ListUploadedPartsResult) error {
  399. var err error
  400. result.Key, err = url.QueryUnescape(result.Key)
  401. if err != nil {
  402. return err
  403. }
  404. return nil
  405. }
  406. // decodeListMultipartUploadResult decodes list multipart upload result in URL encoding
  407. func decodeListMultipartUploadResult(result *ListMultipartUploadResult) error {
  408. var err error
  409. result.Prefix, err = url.QueryUnescape(result.Prefix)
  410. if err != nil {
  411. return err
  412. }
  413. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  414. if err != nil {
  415. return err
  416. }
  417. result.KeyMarker, err = url.QueryUnescape(result.KeyMarker)
  418. if err != nil {
  419. return err
  420. }
  421. result.NextKeyMarker, err = url.QueryUnescape(result.NextKeyMarker)
  422. if err != nil {
  423. return err
  424. }
  425. for i := 0; i < len(result.Uploads); i++ {
  426. result.Uploads[i].Key, err = url.QueryUnescape(result.Uploads[i].Key)
  427. if err != nil {
  428. return err
  429. }
  430. }
  431. for i := 0; i < len(result.CommonPrefixes); i++ {
  432. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  433. if err != nil {
  434. return err
  435. }
  436. }
  437. return nil
  438. }
  439. // createBucketConfiguration defines the configuration for creating a bucket.
  440. type createBucketConfiguration struct {
  441. XMLName xml.Name `xml:"CreateBucketConfiguration"`
  442. StorageClass StorageClassType `xml:"StorageClass,omitempty"`
  443. }
  444. // LiveChannelConfiguration defines the configuration for live-channel
  445. type LiveChannelConfiguration struct {
  446. XMLName xml.Name `xml:"LiveChannelConfiguration"`
  447. Description string `xml:"Description,omitempty"` //Description of live-channel, up to 128 bytes
  448. Status string `xml:"Status,omitempty"` //Specify the status of livechannel
  449. Target LiveChannelTarget `xml:"Target"` //target configuration of live-channel
  450. // use point instead of struct to avoid omit empty snapshot
  451. Snapshot *LiveChannelSnapshot `xml:"Snapshot,omitempty"` //snapshot configuration of live-channel
  452. }
  453. // LiveChannelTarget target configuration of live-channel
  454. type LiveChannelTarget struct {
  455. XMLName xml.Name `xml:"Target"`
  456. Type string `xml:"Type"` //the type of object, only supports HLS
  457. FragDuration int `xml:"FragDuration,omitempty"` //the length of each ts object (in seconds), in the range [1,100]
  458. FragCount int `xml:"FragCount,omitempty"` //the number of ts objects in the m3u8 object, in the range of [1,100]
  459. PlaylistName string `xml:"PlaylistName,omitempty"` //the name of m3u8 object, which must end with ".m3u8" and the length range is [6,128]
  460. }
  461. // LiveChannelSnapshot snapshot configuration of live-channel
  462. type LiveChannelSnapshot struct {
  463. XMLName xml.Name `xml:"Snapshot"`
  464. 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.
  465. DestBucket string `xml:"DestBucket,omitempty"` //Bucket the snapshots will be written to. should be the same owner as the source bucket.
  466. NotifyTopic string `xml:"NotifyTopic,omitempty"` //Topics of MNS for notifying users of high frequency screenshot operation results
  467. Interval int `xml:"Interval,omitempty"` //interval of snapshots, threre is no snapshot if no I-frame during the interval time
  468. }
  469. // CreateLiveChannelResult the result of crete live-channel
  470. type CreateLiveChannelResult struct {
  471. XMLName xml.Name `xml:"CreateLiveChannelResult"`
  472. PublishUrls []string `xml:"PublishUrls>Url"` //push urls list
  473. PlayUrls []string `xml:"PlayUrls>Url"` //play urls list
  474. }
  475. // LiveChannelStat the result of get live-channel state
  476. type LiveChannelStat struct {
  477. XMLName xml.Name `xml:"LiveChannelStat"`
  478. Status string `xml:"Status"` //Current push status of live-channel: Disabled,Live,Idle
  479. ConnectedTime time.Time `xml:"ConnectedTime"` //The time when the client starts pushing, format: ISO8601
  480. RemoteAddr string `xml:"RemoteAddr"` //The ip address of the client
  481. Video LiveChannelVideo `xml:"Video"` //Video stream information
  482. Audio LiveChannelAudio `xml:"Audio"` //Audio stream information
  483. }
  484. // LiveChannelVideo video stream information
  485. type LiveChannelVideo struct {
  486. XMLName xml.Name `xml:"Video"`
  487. Width int `xml:"Width"` //Width (unit: pixels)
  488. Height int `xml:"Height"` //Height (unit: pixels)
  489. FrameRate int `xml:"FrameRate"` //FramRate
  490. Bandwidth int `xml:"Bandwidth"` //Bandwidth (unit: B/s)
  491. }
  492. // LiveChannelAudio audio stream information
  493. type LiveChannelAudio struct {
  494. XMLName xml.Name `xml:"Audio"`
  495. SampleRate int `xml:"SampleRate"` //SampleRate
  496. Bandwidth int `xml:"Bandwidth"` //Bandwidth (unit: B/s)
  497. Codec string `xml:"Codec"` //Encoding forma
  498. }
  499. // LiveChannelHistory the result of GetLiveChannelHistory, at most return up to lastest 10 push records
  500. type LiveChannelHistory struct {
  501. XMLName xml.Name `xml:"LiveChannelHistory"`
  502. Record []LiveRecord `xml:"LiveRecord"` //push records list
  503. }
  504. // LiveRecord push recode
  505. type LiveRecord struct {
  506. XMLName xml.Name `xml:"LiveRecord"`
  507. StartTime time.Time `xml:"StartTime"` //StartTime, format: ISO8601
  508. EndTime time.Time `xml:"EndTime"` //EndTime, format: ISO8601
  509. RemoteAddr string `xml:"RemoteAddr"` //The ip address of remote client
  510. }
  511. // ListLiveChannelResult the result of ListLiveChannel
  512. type ListLiveChannelResult struct {
  513. XMLName xml.Name `xml:"ListLiveChannelResult"`
  514. Prefix string `xml:"Prefix"` //Filter by the name start with the value of "Prefix"
  515. Marker string `xml:"Marker"` //cursor from which starting list
  516. MaxKeys int `xml:"MaxKeys"` //The maximum count returned. the default value is 100. it cannot be greater than 1000.
  517. IsTruncated bool `xml:"IsTruncated"` //Indicates whether all results have been returned, "true" indicates partial results returned while "false" indicates all results have been returned
  518. NextMarker string `xml:"NextMarker"` //NextMarker indicate the Marker value of the next request
  519. LiveChannel []LiveChannelInfo `xml:"LiveChannel"` //The infomation of live-channel
  520. }
  521. // LiveChannelInfo the infomation of live-channel
  522. type LiveChannelInfo struct {
  523. XMLName xml.Name `xml:"LiveChannel"`
  524. Name string `xml:"Name"` //The name of live-channel
  525. Description string `xml:"Description"` //Description of live-channel
  526. Status string `xml:"Status"` //Status: disabled or enabled
  527. LastModified time.Time `xml:"LastModified"` //Last modification time, format: ISO8601
  528. PublishUrls []string `xml:"PublishUrls>Url"` //push urls list
  529. PlayUrls []string `xml:"PlayUrls>Url"` //play urls list
  530. }
  531. // Tag a tag for the object
  532. type Tag struct {
  533. XMLName xml.Name `xml:"Tag"`
  534. Key string `xml:"Key"`
  535. Value string `xml:"Value"`
  536. }
  537. // ObjectTagging tagset for the object
  538. type Tagging struct {
  539. XMLName xml.Name `xml:"Tagging"`
  540. Tags []Tag `xml:"TagSet>Tag,omitempty"`
  541. }
  542. type GetObjectTaggingResult Tagging
  543. // Server Encryption rule for the bucket
  544. type ServerEncryptionRule struct {
  545. XMLName xml.Name `xml:"ServerSideEncryptionRule"`
  546. SSEDefault SSEDefaultRule `xml:"ApplyServerSideEncryptionByDefault"`
  547. }
  548. // Server Encryption deafult rule for the bucket
  549. type SSEDefaultRule struct {
  550. XMLName xml.Name `xml:"ApplyServerSideEncryptionByDefault"`
  551. SSEAlgorithm string `xml:"SSEAlgorithm"`
  552. KMSMasterKeyID string `xml:"KMSMasterKeyID"`
  553. }
  554. type GetBucketEncryptionResult ServerEncryptionRule
  555. type BucketStat struct {
  556. XMLName xml.Name `xml:"BucketStat"`
  557. Storage int64 `xml:"Storage"`
  558. ObjectCount int64 `xml:ObjectCount`
  559. MultipartUploadCount int64 `xml:MultipartUploadCount`
  560. }
  561. type GetBucketStatResult BucketStat