You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

obs.go 18 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package storage
  5. import (
  6. "errors"
  7. "io"
  8. "net/url"
  9. "path"
  10. "sort"
  11. "strconv"
  12. "strings"
  13. "code.gitea.io/gitea/modules/log"
  14. "code.gitea.io/gitea/modules/obs"
  15. "code.gitea.io/gitea/modules/setting"
  16. "github.com/unknwon/com"
  17. )
  18. type FileInfo struct {
  19. FileName string `json:"FileName"`
  20. ModTime string `json:"ModTime"`
  21. IsDir bool `json:"IsDir"`
  22. Size int64 `json:"Size"`
  23. ParenDir string `json:"ParenDir"`
  24. UUID string `json:"UUID"`
  25. }
  26. type FileInfoList []FileInfo
  27. const MAX_LIST_PARTS = 1000
  28. func (ulist FileInfoList) Swap(i, j int) { ulist[i], ulist[j] = ulist[j], ulist[i] }
  29. func (ulist FileInfoList) Len() int { return len(ulist) }
  30. func (ulist FileInfoList) Less(i, j int) bool {
  31. return strings.Compare(ulist[i].FileName, ulist[j].FileName) > 0
  32. }
  33. //check if has the object
  34. func ObsHasObject(path string) (bool, error) {
  35. hasObject := false
  36. input := &obs.GetObjectMetadataInput{}
  37. input.Bucket = setting.Bucket
  38. input.Key = path
  39. _, err := ObsCli.GetObjectMetadata(input)
  40. if err == nil {
  41. hasObject = true
  42. } else {
  43. if obsError, ok := err.(obs.ObsError); ok {
  44. log.Error("GetObjectMetadata failed(%d): %s", obsError.StatusCode, obsError.Message)
  45. } else {
  46. log.Error("%v", err.Error())
  47. }
  48. }
  49. return hasObject, nil
  50. }
  51. func listAllParts(uuid, uploadID, key string) (output *obs.ListPartsOutput, err error) {
  52. output = &obs.ListPartsOutput{}
  53. partNumberMarker := 0
  54. for {
  55. temp, err := ObsCli.ListParts(&obs.ListPartsInput{
  56. Bucket: setting.Bucket,
  57. Key: key,
  58. UploadId: uploadID,
  59. MaxParts: MAX_LIST_PARTS,
  60. PartNumberMarker: partNumberMarker,
  61. })
  62. if err != nil {
  63. log.Error("ListParts failed:", err.Error())
  64. return output, err
  65. }
  66. partNumberMarker = temp.NextPartNumberMarker
  67. log.Info("uuid:%s, MaxParts:%d, PartNumberMarker:%d, NextPartNumberMarker:%d, len:%d", uuid, temp.MaxParts, temp.PartNumberMarker, temp.NextPartNumberMarker, len(temp.Parts))
  68. for _, partInfo := range temp.Parts {
  69. output.Parts = append(output.Parts, obs.Part{
  70. PartNumber: partInfo.PartNumber,
  71. ETag: partInfo.ETag,
  72. })
  73. }
  74. if !temp.IsTruncated {
  75. break
  76. } else {
  77. continue
  78. }
  79. break
  80. }
  81. return output, nil
  82. }
  83. func GetObsPartInfos(uuid, uploadID, fileName string) (string, error) {
  84. key := strings.TrimPrefix(path.Join(setting.BasePath, path.Join(uuid[0:1], uuid[1:2], uuid, fileName)), "/")
  85. allParts, err := listAllParts(uuid, uploadID, key)
  86. if err != nil {
  87. log.Error("listAllParts failed: %v", err)
  88. return "", err
  89. }
  90. var chunks string
  91. for _, partInfo := range allParts.Parts {
  92. chunks += strconv.Itoa(partInfo.PartNumber) + "-" + partInfo.ETag + ","
  93. }
  94. return chunks, nil
  95. }
  96. func NewObsMultiPartUpload(uuid, fileName string) (string, error) {
  97. input := &obs.InitiateMultipartUploadInput{}
  98. input.Bucket = setting.Bucket
  99. input.Key = strings.TrimPrefix(path.Join(setting.BasePath, path.Join(uuid[0:1], uuid[1:2], uuid, fileName)), "/")
  100. output, err := ObsCli.InitiateMultipartUpload(input)
  101. if err != nil {
  102. log.Error("InitiateMultipartUpload failed:", err.Error())
  103. return "", err
  104. }
  105. return output.UploadId, nil
  106. }
  107. func CompleteObsMultiPartUpload(uuid, uploadID, fileName string, totalChunks int) error {
  108. input := &obs.CompleteMultipartUploadInput{}
  109. input.Bucket = setting.Bucket
  110. input.Key = strings.TrimPrefix(path.Join(setting.BasePath, path.Join(uuid[0:1], uuid[1:2], uuid, fileName)), "/")
  111. input.UploadId = uploadID
  112. allParts, err := listAllParts(uuid, uploadID, input.Key)
  113. if err != nil {
  114. log.Error("listAllParts failed: %v", err)
  115. return err
  116. }
  117. if len(allParts.Parts) != totalChunks {
  118. log.Error("listAllParts number(%d) is not equal the set total chunk number(%d)", len(allParts.Parts), totalChunks)
  119. return errors.New("the parts is not complete")
  120. }
  121. input.Parts = allParts.Parts
  122. output, err := ObsCli.CompleteMultipartUpload(input)
  123. if err != nil {
  124. log.Error("CompleteMultipartUpload failed:", err.Error())
  125. return err
  126. }
  127. log.Info("uuid:%s, RequestId:%s", uuid, output.RequestId)
  128. return nil
  129. }
  130. func ObsMultiPartUpload(uuid string, uploadId string, partNumber int, fileName string, putBody io.ReadCloser) error {
  131. input := &obs.UploadPartInput{}
  132. input.Bucket = setting.Bucket
  133. input.Key = strings.TrimPrefix(path.Join(setting.BasePath, path.Join(uuid[0:1], uuid[1:2], uuid, fileName)), "/")
  134. input.UploadId = uploadId
  135. input.PartNumber = partNumber
  136. input.Body = putBody
  137. output, err := ObsCli.UploadPart(input)
  138. if err == nil {
  139. log.Info("RequestId:%s\n", output.RequestId)
  140. log.Info("ETag:%s\n", output.ETag)
  141. return nil
  142. } else {
  143. if obsError, ok := err.(obs.ObsError); ok {
  144. log.Info(obsError.Code)
  145. log.Info(obsError.Message)
  146. return obsError
  147. } else {
  148. log.Error("error:", err.Error())
  149. return err
  150. }
  151. }
  152. }
  153. //delete all file under the dir path
  154. func ObsRemoveObject(bucket string, path string) error {
  155. log.Info("Bucket=" + bucket + " path=" + path)
  156. if len(path) == 0 {
  157. return errors.New("path canot be null.")
  158. }
  159. input := &obs.ListObjectsInput{}
  160. input.Bucket = bucket
  161. // 设置每页100个对象
  162. input.MaxKeys = 100
  163. input.Prefix = path
  164. index := 1
  165. log.Info("prefix=" + input.Prefix)
  166. for {
  167. output, err := ObsCli.ListObjects(input)
  168. if err == nil {
  169. log.Info("Page:%d\n", index)
  170. index++
  171. for _, val := range output.Contents {
  172. log.Info("delete obs file:" + val.Key)
  173. delObj := &obs.DeleteObjectInput{}
  174. delObj.Bucket = setting.Bucket
  175. delObj.Key = val.Key
  176. ObsCli.DeleteObject(delObj)
  177. }
  178. if output.IsTruncated {
  179. input.Marker = output.NextMarker
  180. } else {
  181. break
  182. }
  183. } else {
  184. if obsError, ok := err.(obs.ObsError); ok {
  185. log.Info("Code:%s\n", obsError.Code)
  186. log.Info("Message:%s\n", obsError.Message)
  187. }
  188. return err
  189. }
  190. }
  191. return nil
  192. }
  193. func ObsDownloadAFile(bucket string, key string) (io.ReadCloser, error) {
  194. input := &obs.GetObjectInput{}
  195. input.Bucket = bucket
  196. input.Key = key
  197. output, err := ObsCli.GetObject(input)
  198. if err == nil {
  199. log.Info("StorageClass:%s, ETag:%s, ContentType:%s, ContentLength:%d, LastModified:%s\n",
  200. output.StorageClass, output.ETag, output.ContentType, output.ContentLength, output.LastModified)
  201. return output.Body, nil
  202. } else if obsError, ok := err.(obs.ObsError); ok {
  203. log.Error("Code:%s, Message:%s", obsError.Code, obsError.Message)
  204. return nil, obsError
  205. } else {
  206. return nil, err
  207. }
  208. }
  209. func ObsDownload(uuid string, fileName string) (io.ReadCloser, error) {
  210. return ObsDownloadAFile(setting.Bucket, strings.TrimPrefix(path.Join(setting.BasePath, path.Join(uuid[0:1], uuid[1:2], uuid, fileName)), "/"))
  211. }
  212. func ObsModelDownload(JobName string, fileName string) (io.ReadCloser, error) {
  213. input := &obs.GetObjectInput{}
  214. input.Bucket = setting.Bucket
  215. input.Key = strings.TrimPrefix(path.Join(setting.TrainJobModelPath, JobName, setting.OutPutPath, fileName), "/")
  216. // input.Key = strings.TrimPrefix(path.Join(setting.BasePath, path.Join(uuid[0:1], uuid[1:2], uuid)), "/")
  217. output, err := ObsCli.GetObject(input)
  218. if err == nil {
  219. log.Info("StorageClass:%s, ETag:%s, ContentType:%s, ContentLength:%d, LastModified:%s\n",
  220. output.StorageClass, output.ETag, output.ContentType, output.ContentLength, output.LastModified)
  221. return output.Body, nil
  222. } else if obsError, ok := err.(obs.ObsError); ok {
  223. log.Error("Code:%s, Message:%s", obsError.Code, obsError.Message)
  224. return nil, obsError
  225. } else {
  226. return nil, err
  227. }
  228. }
  229. func ObsCopyManyFile(srcBucket string, srcPath string, destBucket string, destPath string, Files []string) (int64, error) {
  230. var fileTotalSize int64
  231. for _, file := range Files {
  232. srcKey := srcPath + file
  233. destKey := destPath + file
  234. log.Info("srcKey=" + srcKey + " destKey=" + destKey)
  235. out, err := ObsCli.GetObjectMetadata(&obs.GetObjectMetadataInput{
  236. Bucket: srcBucket,
  237. Key: srcKey,
  238. })
  239. if err != nil {
  240. log.Info("Get File error, error=" + err.Error())
  241. continue
  242. }
  243. obsCopyFile(srcBucket, srcKey, destBucket, destKey)
  244. fileTotalSize += out.ContentLength
  245. }
  246. return fileTotalSize, nil
  247. }
  248. func ObsCopyAllFile(srcBucket string, srcPath string, destBucket string, destPath string) (int64, error) {
  249. input := &obs.ListObjectsInput{}
  250. input.Bucket = srcBucket
  251. // 设置每页100个对象
  252. input.MaxKeys = 100
  253. input.Prefix = srcPath
  254. index := 1
  255. length := len(srcPath)
  256. var fileTotalSize int64
  257. log.Info("prefix=" + input.Prefix)
  258. for {
  259. output, err := ObsCli.ListObjects(input)
  260. if err == nil {
  261. log.Info("Page:%d\n", index)
  262. index++
  263. for _, val := range output.Contents {
  264. destKey := destPath + val.Key[length:]
  265. obsCopyFile(srcBucket, val.Key, destBucket, destKey)
  266. fileTotalSize += val.Size
  267. }
  268. if output.IsTruncated {
  269. input.Marker = output.NextMarker
  270. } else {
  271. break
  272. }
  273. } else {
  274. if obsError, ok := err.(obs.ObsError); ok {
  275. log.Info("Code:%s\n", obsError.Code)
  276. log.Info("Message:%s\n", obsError.Message)
  277. }
  278. return 0, err
  279. }
  280. }
  281. return fileTotalSize, nil
  282. }
  283. func obsCopyFile(srcBucket string, srcKeyName string, destBucket string, destKeyName string) error {
  284. input := &obs.CopyObjectInput{}
  285. input.Bucket = destBucket
  286. input.Key = destKeyName
  287. input.CopySourceBucket = srcBucket
  288. input.CopySourceKey = srcKeyName
  289. _, err := ObsCli.CopyObject(input)
  290. if err == nil {
  291. log.Info("copy success,destBuckName:%s, destkeyname:%s", destBucket, destKeyName)
  292. } else {
  293. log.Info("copy failed,,destBuckName:%s, destkeyname:%s", destBucket, destKeyName)
  294. if obsError, ok := err.(obs.ObsError); ok {
  295. log.Info(obsError.Code)
  296. log.Info(obsError.Message)
  297. }
  298. return err
  299. }
  300. return nil
  301. }
  302. func GetOneLevelAllObjectUnderDir(bucket string, prefixRootPath string, relativePath string) ([]FileInfo, error) {
  303. input := &obs.ListObjectsInput{}
  304. input.Bucket = bucket
  305. input.Prefix = prefixRootPath + relativePath
  306. if !strings.HasSuffix(input.Prefix, "/") {
  307. input.Prefix += "/"
  308. }
  309. output, err := ObsCli.ListObjects(input)
  310. fileInfos := make([]FileInfo, 0)
  311. prefixLen := len(input.Prefix)
  312. fileMap := make(map[string]bool, 0)
  313. if err == nil {
  314. for _, val := range output.Contents {
  315. log.Info("val key=" + val.Key)
  316. var isDir bool
  317. var fileName string
  318. if val.Key == input.Prefix {
  319. continue
  320. }
  321. fileName = val.Key[prefixLen : len(val.Key)-1]
  322. log.Info("fileName =" + fileName)
  323. files := strings.Split(fileName, "/")
  324. if fileMap[files[0]] {
  325. continue
  326. } else {
  327. fileMap[files[0]] = true
  328. }
  329. ParenDir := relativePath
  330. fileName = files[0]
  331. if len(files) > 1 {
  332. isDir = true
  333. ParenDir += fileName
  334. } else {
  335. isDir = false
  336. }
  337. // if strings.Contains(val.Key[prefixLen:len(val.Key)-1], "/") {
  338. // files := strings.Split(fileName, "/")
  339. // fileName = files[0]
  340. // isDir = true
  341. // if fileMap[files[0]] {
  342. // continue
  343. // } else {
  344. // fileMap[files[0]] = true
  345. // }
  346. // } else {
  347. // if strings.HasSuffix(val.Key, "/") {
  348. // isDir = true
  349. // fileName = val.Key[prefixLen : len(val.Key)-1]
  350. // relativePath += val.Key[prefixLen:]
  351. // } else {
  352. // isDir = false
  353. // fileName = val.Key[prefixLen:]
  354. // }
  355. // fileMap[fileName] = true
  356. // }
  357. fileInfo := FileInfo{
  358. ModTime: val.LastModified.Local().Format("2006-01-02 15:04:05"),
  359. FileName: fileName,
  360. Size: val.Size,
  361. IsDir: isDir,
  362. ParenDir: relativePath,
  363. }
  364. fileInfos = append(fileInfos, fileInfo)
  365. }
  366. return fileInfos, err
  367. } else {
  368. if obsError, ok := err.(obs.ObsError); ok {
  369. log.Error("Code:%s, Message:%s", obsError.Code, obsError.Message)
  370. }
  371. return nil, err
  372. }
  373. }
  374. func GetAllObjectByBucketAndPrefix(bucket string, prefix string) ([]FileInfo, error) {
  375. input := &obs.ListObjectsInput{}
  376. input.Bucket = bucket
  377. // 设置每页100个对象
  378. input.MaxKeys = 100
  379. input.Prefix = prefix
  380. index := 1
  381. fileInfoList := FileInfoList{}
  382. prefixLen := len(prefix)
  383. log.Info("prefix=" + input.Prefix)
  384. for {
  385. output, err := ObsCli.ListObjects(input)
  386. if err == nil {
  387. log.Info("Page:%d\n", index)
  388. index++
  389. for _, val := range output.Contents {
  390. var isDir bool
  391. if prefixLen == len(val.Key) {
  392. continue
  393. }
  394. if strings.HasSuffix(val.Key, "/") {
  395. isDir = true
  396. } else {
  397. isDir = false
  398. }
  399. fileInfo := FileInfo{
  400. ModTime: val.LastModified.Format("2006-01-02 15:04:05"),
  401. FileName: val.Key[prefixLen:],
  402. Size: val.Size,
  403. IsDir: isDir,
  404. ParenDir: "",
  405. }
  406. fileInfoList = append(fileInfoList, fileInfo)
  407. }
  408. if output.IsTruncated {
  409. input.Marker = output.NextMarker
  410. } else {
  411. break
  412. }
  413. } else {
  414. if obsError, ok := err.(obs.ObsError); ok {
  415. log.Info("Code:%s\n", obsError.Code)
  416. log.Info("Message:%s\n", obsError.Message)
  417. }
  418. return nil, err
  419. }
  420. }
  421. sort.Sort(fileInfoList)
  422. return fileInfoList, nil
  423. }
  424. func GetObsListObject(jobName, outPutPath, parentDir, versionName string) ([]FileInfo, error) {
  425. input := &obs.ListObjectsInput{}
  426. input.Bucket = setting.Bucket
  427. input.Prefix = strings.TrimPrefix(path.Join(setting.TrainJobModelPath, jobName, outPutPath, versionName, parentDir), "/")
  428. log.Info("bucket=" + input.Bucket + " Prefix=" + input.Prefix)
  429. strPrefix := strings.Split(input.Prefix, "/")
  430. output, err := ObsCli.ListObjects(input)
  431. fileInfos := make([]FileInfo, 0)
  432. if err == nil {
  433. for _, val := range output.Contents {
  434. str1 := strings.Split(val.Key, "/")
  435. var isDir bool
  436. var fileName, nextParentDir string
  437. if strings.HasSuffix(val.Key, "/") {
  438. //dirs in next level dir
  439. if len(str1)-len(strPrefix) > 2 {
  440. continue
  441. }
  442. fileName = str1[len(str1)-2]
  443. isDir = true
  444. if parentDir == "" {
  445. nextParentDir = fileName
  446. } else {
  447. nextParentDir = parentDir + "/" + fileName
  448. }
  449. if fileName == strPrefix[len(strPrefix)-1] || (fileName+"/") == outPutPath {
  450. continue
  451. }
  452. } else {
  453. //files in next level dir
  454. if len(str1)-len(strPrefix) > 1 {
  455. continue
  456. }
  457. fileName = str1[len(str1)-1]
  458. isDir = false
  459. nextParentDir = parentDir
  460. }
  461. fileInfo := FileInfo{
  462. ModTime: val.LastModified.Local().Format("2006-01-02 15:04:05"),
  463. FileName: fileName,
  464. Size: val.Size,
  465. IsDir: isDir,
  466. ParenDir: nextParentDir,
  467. }
  468. fileInfos = append(fileInfos, fileInfo)
  469. }
  470. sort.Slice(fileInfos, func(i, j int) bool {
  471. return fileInfos[i].ModTime > fileInfos[j].ModTime
  472. })
  473. return fileInfos, err
  474. } else {
  475. if obsError, ok := err.(obs.ObsError); ok {
  476. log.Error("Code:%s, Message:%s", obsError.Code, obsError.Message)
  477. }
  478. return nil, err
  479. }
  480. }
  481. func ObsGenMultiPartSignedUrl(uuid string, uploadId string, partNumber int, fileName string) (string, error) {
  482. input := &obs.CreateSignedUrlInput{}
  483. input.Bucket = setting.Bucket
  484. input.Key = strings.TrimPrefix(path.Join(setting.BasePath, path.Join(uuid[0:1], uuid[1:2], uuid, fileName)), "/")
  485. input.Expires = 60 * 60
  486. input.Method = obs.HttpMethodPut
  487. input.QueryParams = map[string]string{
  488. "partNumber": com.ToStr(partNumber, 10),
  489. "uploadId": uploadId,
  490. //"partSize": com.ToStr(partSize,10),
  491. }
  492. output, err := ObsCli.CreateSignedUrl(input)
  493. if err != nil {
  494. log.Error("CreateSignedUrl failed:", err.Error())
  495. return "", err
  496. }
  497. return output.SignedUrl, nil
  498. }
  499. func GetObsCreateSignedUrlByBucketAndKey(bucket, key string) (string, error) {
  500. input := &obs.CreateSignedUrlInput{}
  501. input.Bucket = bucket
  502. input.Key = key
  503. input.Expires = 60 * 60
  504. input.Method = obs.HttpMethodGet
  505. comma := strings.LastIndex(key, "/")
  506. filename := key
  507. if comma != -1 {
  508. filename = key[comma+1:]
  509. }
  510. reqParams := make(map[string]string)
  511. filename = url.PathEscape(filename)
  512. reqParams["response-content-disposition"] = "attachment; filename=\"" + filename + "\""
  513. input.QueryParams = reqParams
  514. output, err := ObsCli.CreateSignedUrl(input)
  515. if err != nil {
  516. log.Error("CreateSignedUrl failed:", err.Error())
  517. return "", err
  518. }
  519. return output.SignedUrl, nil
  520. }
  521. func GetObsCreateSignedUrl(jobName, parentDir, fileName string) (string, error) {
  522. return GetObsCreateSignedUrlByBucketAndKey(setting.Bucket, strings.TrimPrefix(path.Join(setting.TrainJobModelPath, jobName, setting.OutPutPath, parentDir, fileName), "/"))
  523. }
  524. func ObsGetPreSignedUrl(uuid, fileName string) (string, error) {
  525. input := &obs.CreateSignedUrlInput{}
  526. input.Method = obs.HttpMethodGet
  527. input.Key = strings.TrimPrefix(path.Join(setting.BasePath, path.Join(uuid[0:1], uuid[1:2], uuid, fileName)), "/")
  528. input.Bucket = setting.Bucket
  529. input.Expires = 60 * 60
  530. fileName = url.PathEscape(fileName)
  531. reqParams := make(map[string]string)
  532. reqParams["response-content-disposition"] = "attachment; filename=\"" + fileName + "\""
  533. input.QueryParams = reqParams
  534. output, err := ObsCli.CreateSignedUrl(input)
  535. if err != nil {
  536. log.Error("CreateSignedUrl failed:", err.Error())
  537. return "", err
  538. }
  539. return output.SignedUrl, nil
  540. }
  541. func ObsCreateObject(path string) error {
  542. input := &obs.PutObjectInput{}
  543. input.Bucket = setting.Bucket
  544. input.Key = path
  545. _, err := ObsCli.PutObject(input)
  546. if err != nil {
  547. log.Error("PutObject failed:", err.Error())
  548. return err
  549. }
  550. return nil
  551. }
  552. func GetObsLogFileName(prefix string) (string, error) {
  553. input := &obs.ListObjectsInput{}
  554. input.Bucket = setting.Bucket
  555. input.Prefix = prefix
  556. output, err := ObsCli.ListObjects(input)
  557. if err != nil {
  558. log.Error("PutObject failed:", err.Error())
  559. return "", err
  560. }
  561. return output.Contents[0].Key, nil
  562. }