浏览代码

fix:鉴权调整

Roc 1 年之前
父节点
当前提交
534634a3f8
共有 2 个文件被更改,包括 21 次插入12 次删除
  1. 13 11
      config/config.go
  2. 8 1
      services/xiangyu/index.go

+ 13 - 11
config/config.go

@@ -97,15 +97,17 @@ type Smm struct {
 
 // Xiangyu 象屿的配置
 type Xiangyu struct {
-	SystemCode           string `mapstructure:"system-code" json:"system-code" yaml:"system-code" description:"系统编码"`
-	UserSyncTarget       string `mapstructure:"user-sync-target" json:"user-sync-target" yaml:"user-sync-target" description:"用户同步平台编码"`
-	UserSyncHost         string `mapstructure:"user-sync-host" json:"user-sync-host" yaml:"user-sync-host" description:"用户同步平台地址"`
-	UserSyncAuthUserName string `mapstructure:"user-sync-auth-user-name" json:"user-sync-auth-user-name" yaml:"user-sync-auth-user-name" description:"用户统一身份的鉴权username"`
-	UserSyncAuthPwd      string `mapstructure:"user-sync-auth-pwd" json:"user-sync-auth-pwd" yaml:"user-sync-auth-pwd" description:"用户统一身份的鉴权password"`
-	UserAuthHost         string `mapstructure:"user-auth-host" json:"user-auth-host" yaml:"user-auth-host" description:"用户认证平台地址"`
-	UserKey              string `mapstructure:"user-key" json:"user-key" yaml:"user-key" description:"统一平台秘钥"`
-	DefaultRoleId        int    `mapstructure:"default-role-id" json:"default-role-id" yaml:"default-role-id" description:"默认的角色id"`
-	IndexSyncHost        string `mapstructure:"index-sync-host" json:"index-sync-host" yaml:"index-sync-host" description:"指标同步平台地址"`
-	IndexSyncAuth        string `mapstructure:"index-sync-auth" json:"index-sync-auth" yaml:"index-sync-auth" description:"指标同步平台鉴权token"`
-	IndexSyncTarget      string `mapstructure:"index-sync-target" json:"index-sync-target" yaml:"index-sync-target" description:"指标同步平台编码"`
+	SystemCode            string `mapstructure:"system-code" json:"system-code" yaml:"system-code" description:"系统编码"`
+	UserSyncTarget        string `mapstructure:"user-sync-target" json:"user-sync-target" yaml:"user-sync-target" description:"用户同步平台编码"`
+	UserSyncHost          string `mapstructure:"user-sync-host" json:"user-sync-host" yaml:"user-sync-host" description:"用户同步平台地址"`
+	UserAuthHost          string `mapstructure:"user-auth-host" json:"user-auth-host" yaml:"user-auth-host" description:"用户认证平台地址"`
+	UserSyncAuthUserName  string `mapstructure:"user-sync-auth-user-name" json:"user-sync-auth-user-name" yaml:"user-sync-auth-user-name" description:"用户统一身份的鉴权username"`
+	UserSyncAuthPwd       string `mapstructure:"user-sync-auth-pwd" json:"user-sync-auth-pwd" yaml:"user-sync-auth-pwd" description:"用户统一身份的鉴权password"`
+	UserKey               string `mapstructure:"user-key" json:"user-key" yaml:"user-key" description:"统一平台秘钥"`
+	DefaultRoleId         int    `mapstructure:"default-role-id" json:"default-role-id" yaml:"default-role-id" description:"默认的角色id"`
+	IndexSyncHost         string `mapstructure:"index-sync-host" json:"index-sync-host" yaml:"index-sync-host" description:"指标同步平台地址"`
+	IndexSyncAuthUserName string `mapstructure:"index-sync-auth-user-name" json:"index-sync-auth-user-name" yaml:"index-sync-auth-user-name" description:"用户统一身份的鉴权username"`
+	IndexSyncAuthPwd      string `mapstructure:"index-sync-auth-pwd" json:"index-sync-auth-pwd" yaml:"index-sync-auth-pwd" description:"用户统一身份的鉴权password"`
+	IndexKey              string `mapstructure:"index-key" json:"index-key" yaml:"index-key" description:"统一平台秘钥"`
+	IndexSyncTarget       string `mapstructure:"index-sync-target" json:"index-sync-target" yaml:"index-sync-target" description:"指标同步平台编码"`
 }

+ 8 - 1
services/xiangyu/index.go

@@ -371,7 +371,14 @@ func HttpPostIndex(urlPath, postData string) ([]byte, error) {
 	req.Header.Set("content-Type", "application/json; charset=utf-8")
 	req.Header.Set("Accept-Encoding", "application/json; charset=utf-8")
 	req.Header.Set("Accept", "application/json; charset=utf-8")
-	req.Header.Set("Authorization", global.CONFIG.Xiangyu.IndexSyncAuth)
+
+	// 鉴权
+	req.SetBasicAuth(global.CONFIG.Xiangyu.IndexSyncAuthUserName, global.CONFIG.Xiangyu.IndexSyncAuthPwd)
+
+	// 秘钥
+	if global.CONFIG.Xiangyu.IndexKey != `` {
+		req.Header.Set("deipaaskeyauth", global.CONFIG.Xiangyu.IndexKey)
+	}
 
 	resp, err := client.Do(req)
 	if err != nil {