package aliyun import ( "applet/app/db" "applet/app/e" md "applet/app/md/setCenter/oss/aliyun" "applet/app/svc/sys_cfg" enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" "github.com/gin-gonic/gin" ) // GetBasic // @Summary 设置中心-对象存储-对象存储设置(获取) // @Tags 对象存储 // @Description 对象存储设置(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Success 200 {object} md.GetBasicResp "设置列表" // @Failure 400 {object} md.Response "具体错误" // @Router /api/settCenter/oss/aliYun/getBasic [get] func GetBasic(c *gin.Context) { sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) sysCfg, err := sysCfgDb.SysCfgGetAll() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } cfgMap := make(map[string]string, len(*sysCfg)) for _, cfg := range *sysCfg { cfgMap[cfg.Key] = cfg.Val } endpoint, ok := cfgMap[enum2.AliyunOssEndpoint] if !ok { sysCfgDb.SysCfgInsert(enum2.AliyunOssEndpoint, "", enum2.AliyunOss(enum2.AliyunOssEndpoint).String()) endpoint = "" } bucketName, ok := cfgMap[enum2.AliyunOssBucketName] if !ok { sysCfgDb.SysCfgInsert(enum2.AliyunOssBucketName, "", enum2.AliyunOss(enum2.AliyunOssBucketName).String()) bucketName = "" } bucketScheme, ok := cfgMap[enum2.AliyunOssBucketScheme] if !ok { sysCfgDb.SysCfgInsert(enum2.AliyunOssBucketScheme, "", enum2.AliyunOss(enum2.AliyunOssBucketScheme).String()) bucketScheme = "" } accessKeyID, ok := cfgMap[enum2.AliyunOssAccessKeyID] if !ok { sysCfgDb.SysCfgInsert(enum2.AliyunOssAccessKeyID, "", enum2.AliyunOss(enum2.AliyunOssAccessKeyID).String()) accessKeyID = "" } accessKeySecret, ok := cfgMap[enum2.AliyunOssAccessKeySecret] if !ok { sysCfgDb.SysCfgInsert(enum2.AliyunOssAccessKeySecret, "", enum2.AliyunOss(enum2.AliyunOssAccessKeySecret).String()) accessKeySecret = "" } domain, ok := cfgMap[enum2.AliyunOssDomain] if !ok { sysCfgDb.SysCfgInsert(enum2.AliyunOssDomain, "", enum2.AliyunOss(enum2.AliyunOssDomain).String()) domain = "" } options, ok := cfgMap[enum2.AliyunOptions] if !ok { sysCfgDb.SysCfgInsert(enum2.AliyunOptions, "", enum2.AliyunOss(enum2.AliyunOptions).String()) } assumeRoleARN, ok := cfgMap[enum2.AliyunOssAssumeRoleARN] if !ok { sysCfgDb.SysCfgInsert(enum2.AliyunOssAssumeRoleARN, "", enum2.AliyunOss(enum2.AliyunOssAssumeRoleARN).String()) } assumeRoleAccessKeySecret, ok := cfgMap[enum2.AliyunOssAssumeRoleAccessKeySecret] if !ok { sysCfgDb.SysCfgInsert(enum2.AliyunOssAssumeRoleAccessKeySecret, "", enum2.AliyunOss(enum2.AliyunOssAssumeRoleAccessKeySecret).String()) } assumeRoleAccessKeyID, ok := cfgMap[enum2.AliyunOssAssumeRoleAccessKeyID] if !ok { sysCfgDb.SysCfgInsert(enum2.AliyunOssAssumeRoleAccessKeyID, "", enum2.AliyunOss(enum2.AliyunOssAssumeRoleAccessKeyID).String()) } resp := md.GetBasicResp{ OssEndpoint: endpoint, OssBucketName: bucketName, OssBucketScheme: bucketScheme, OssAccessKeyId: accessKeyID, OssAccessKeySecret: accessKeySecret, OssObjectDomain: domain, OssOption: options, OssAssumeRoleAccessKeyID: assumeRoleAccessKeyID, OssAssumeRoleAccessKeySecret: assumeRoleAccessKeySecret, OssAssumeRoleARN: assumeRoleARN, } e.OutSuc(c, resp, nil) } // SetBasic // @Summary 设置中心-对象存储-对象存储设置(更新) // @Tags 对象存储 // @Description 对象存储设置(更新) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @param req body md.SetBasicReq true "上传需要修改的信息" // @Success 200 {string} "success" // @Failure 400 {object} md.Response "具体错误" // @Router /api/settCenter/oss/aliYun/setBasic [post] func SetBasic(c *gin.Context) { var req *md.SetBasicReq if err1 := c.ShouldBindJSON(&req); err1 != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error()) return } cfgDb := sys_cfg.NewSysCfgDb(db.Db) if req.OssAccessKeyId != "" { cfgDb.SysCfgUpdate(enum2.AliyunOssAccessKeyID, req.OssAccessKeyId) } if req.OssAccessKeySecret != "" { cfgDb.SysCfgUpdate(enum2.AliyunOssAccessKeySecret, req.OssAccessKeySecret) } if req.OssBucketScheme != "" { cfgDb.SysCfgUpdate(enum2.AliyunOssBucketScheme, req.OssBucketScheme) } if req.OssObjectDomain != "" { cfgDb.SysCfgUpdate(enum2.AliyunOssDomain, req.OssObjectDomain) } if req.OssBucketName != "" { cfgDb.SysCfgUpdate(enum2.AliyunOssBucketName, req.OssBucketName) } if req.OssEndpoint != "" { cfgDb.SysCfgUpdate(enum2.AliyunOssEndpoint, req.OssEndpoint) } if req.OssOption != "" { cfgDb.SysCfgUpdate(enum2.AliyunOptions, req.OssOption) } if req.OssAssumeRoleAccessKeyID != "" { cfgDb.SysCfgUpdate(enum2.AliyunOssAssumeRoleAccessKeyID, req.OssAssumeRoleAccessKeyID) } if req.OssAssumeRoleAccessKeySecret != "" { cfgDb.SysCfgUpdate(enum2.AliyunOssAssumeRoleAccessKeySecret, req.OssAssumeRoleAccessKeySecret) } if req.OssAssumeRoleARN != "" { cfgDb.SysCfgUpdate(enum2.AliyunOssAssumeRoleARN, req.OssAssumeRoleARN) } e.OutSuc(c, "success", nil) }