蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

151 lines
5.4 KiB

  1. package aliyun
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. md "applet/app/md/setCenter/oss/aliyun"
  6. "applet/app/utils/cache"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  8. enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  9. "github.com/gin-gonic/gin"
  10. )
  11. // GetBasic
  12. // @Summary 设置中心-对象存储-对象存储设置(获取)
  13. // @Tags 对象存储
  14. // @Description 对象存储设置(获取)
  15. // @Accept json
  16. // @Produce json
  17. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  18. // @Success 200 {object} md.GetBasicResp "设置列表"
  19. // @Failure 400 {object} md.Response "具体错误"
  20. // @Router /api/settCenter/oss/aliYun/getBasic [get]
  21. func GetBasic(c *gin.Context) {
  22. redisConn := cache.GetPool().Get()
  23. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  24. sysCfg, err := sysCfgDb.SysCfgGetAll()
  25. if err != nil {
  26. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  27. return
  28. }
  29. cfgMap := make(map[string]string, len(*sysCfg))
  30. for _, cfg := range *sysCfg {
  31. cfgMap[cfg.Key] = cfg.Val
  32. }
  33. endpoint, ok := cfgMap[enum2.AliyunOssEndpoint]
  34. if !ok {
  35. sysCfgDb.SysCfgInsert(enum2.AliyunOssEndpoint, "", enum2.AliyunOss(enum2.AliyunOssEndpoint).String())
  36. endpoint = ""
  37. }
  38. bucketName, ok := cfgMap[enum2.AliyunOssBucketName]
  39. if !ok {
  40. sysCfgDb.SysCfgInsert(enum2.AliyunOssBucketName, "", enum2.AliyunOss(enum2.AliyunOssBucketName).String())
  41. bucketName = ""
  42. }
  43. bucketScheme, ok := cfgMap[enum2.AliyunOssBucketScheme]
  44. if !ok {
  45. sysCfgDb.SysCfgInsert(enum2.AliyunOssBucketScheme, "", enum2.AliyunOss(enum2.AliyunOssBucketScheme).String())
  46. bucketScheme = ""
  47. }
  48. accessKeyID, ok := cfgMap[enum2.AliyunOssAccessKeyID]
  49. if !ok {
  50. sysCfgDb.SysCfgInsert(enum2.AliyunOssAccessKeyID, "", enum2.AliyunOss(enum2.AliyunOssAccessKeyID).String())
  51. accessKeyID = ""
  52. }
  53. accessKeySecret, ok := cfgMap[enum2.AliyunOssAccessKeySecret]
  54. if !ok {
  55. sysCfgDb.SysCfgInsert(enum2.AliyunOssAccessKeySecret, "", enum2.AliyunOss(enum2.AliyunOssAccessKeySecret).String())
  56. accessKeySecret = ""
  57. }
  58. domain, ok := cfgMap[enum2.AliyunOssDomain]
  59. if !ok {
  60. sysCfgDb.SysCfgInsert(enum2.AliyunOssDomain, "", enum2.AliyunOss(enum2.AliyunOssDomain).String())
  61. domain = ""
  62. }
  63. options, ok := cfgMap[enum2.AliyunOptions]
  64. if !ok {
  65. sysCfgDb.SysCfgInsert(enum2.AliyunOptions, "", enum2.AliyunOss(enum2.AliyunOptions).String())
  66. }
  67. assumeRoleARN, ok := cfgMap[enum2.AliyunOssAssumeRoleARN]
  68. if !ok {
  69. sysCfgDb.SysCfgInsert(enum2.AliyunOssAssumeRoleARN, "", enum2.AliyunOss(enum2.AliyunOssAssumeRoleARN).String())
  70. }
  71. assumeRoleAccessKeySecret, ok := cfgMap[enum2.AliyunOssAssumeRoleAccessKeySecret]
  72. if !ok {
  73. sysCfgDb.SysCfgInsert(enum2.AliyunOssAssumeRoleAccessKeySecret, "", enum2.AliyunOss(enum2.AliyunOssAssumeRoleAccessKeySecret).String())
  74. }
  75. assumeRoleAccessKeyID, ok := cfgMap[enum2.AliyunOssAssumeRoleAccessKeyID]
  76. if !ok {
  77. sysCfgDb.SysCfgInsert(enum2.AliyunOssAssumeRoleAccessKeyID, "", enum2.AliyunOss(enum2.AliyunOssAssumeRoleAccessKeyID).String())
  78. }
  79. resp := md.GetBasicResp{
  80. OssEndpoint: endpoint,
  81. OssBucketName: bucketName,
  82. OssBucketScheme: bucketScheme,
  83. OssAccessKeyId: accessKeyID,
  84. OssAccessKeySecret: accessKeySecret,
  85. OssObjectDomain: domain,
  86. OssOption: options,
  87. OssAssumeRoleAccessKeyID: assumeRoleAccessKeyID,
  88. OssAssumeRoleAccessKeySecret: assumeRoleAccessKeySecret,
  89. OssAssumeRoleARN: assumeRoleARN,
  90. }
  91. e.OutSuc(c, resp, nil)
  92. }
  93. // SetBasic
  94. // @Summary 设置中心-对象存储-对象存储设置(更新)
  95. // @Tags 对象存储
  96. // @Description 对象存储设置(更新)
  97. // @Accept json
  98. // @Produce json
  99. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  100. // @param req body md.SetBasicReq true "上传需要修改的信息"
  101. // @Success 200 {string} "success"
  102. // @Failure 400 {object} md.Response "具体错误"
  103. // @Router /api/settCenter/oss/aliYun/setBasic [post]
  104. func SetBasic(c *gin.Context) {
  105. var req *md.SetBasicReq
  106. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  107. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  108. return
  109. }
  110. redisConn := cache.GetPool().Get()
  111. cfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  112. if req.OssAccessKeyId != "" {
  113. cfgDb.SysCfgUpdate(enum2.AliyunOssAccessKeyID, req.OssAccessKeyId)
  114. }
  115. if req.OssAccessKeySecret != "" {
  116. cfgDb.SysCfgUpdate(enum2.AliyunOssAccessKeySecret, req.OssAccessKeySecret)
  117. }
  118. if req.OssBucketScheme != "" {
  119. cfgDb.SysCfgUpdate(enum2.AliyunOssBucketScheme, req.OssBucketScheme)
  120. }
  121. if req.OssObjectDomain != "" {
  122. cfgDb.SysCfgUpdate(enum2.AliyunOssDomain, req.OssObjectDomain)
  123. }
  124. if req.OssBucketName != "" {
  125. cfgDb.SysCfgUpdate(enum2.AliyunOssBucketName, req.OssBucketName)
  126. }
  127. if req.OssEndpoint != "" {
  128. cfgDb.SysCfgUpdate(enum2.AliyunOssEndpoint, req.OssEndpoint)
  129. }
  130. if req.OssOption != "" {
  131. cfgDb.SysCfgUpdate(enum2.AliyunOptions, req.OssOption)
  132. }
  133. if req.OssAssumeRoleAccessKeyID != "" {
  134. cfgDb.SysCfgUpdate(enum2.AliyunOssAssumeRoleAccessKeyID, req.OssAssumeRoleAccessKeyID)
  135. }
  136. if req.OssAssumeRoleAccessKeySecret != "" {
  137. cfgDb.SysCfgUpdate(enum2.AliyunOssAssumeRoleAccessKeySecret, req.OssAssumeRoleAccessKeySecret)
  138. }
  139. if req.OssAssumeRoleARN != "" {
  140. cfgDb.SysCfgUpdate(enum2.AliyunOssAssumeRoleARN, req.OssAssumeRoleARN)
  141. }
  142. e.OutSuc(c, "success", nil)
  143. }