Commit 89a10490 authored by ibuler's avatar ibuler

[Update] Merge

parents 747900d3 cd41446b
...@@ -152,7 +152,7 @@ func (c *Client) Do(method, url string, data, res interface{}, params ...map[str ...@@ -152,7 +152,7 @@ func (c *Client) Do(method, url string, data, res interface{}, params ...map[str
return return
} }
func (c *Client) Get(url string, query map[string]string, res interface{}) (err error) { func (c *Client) Get(url string, res interface{}) (err error) {
return c.Do("GET", url, nil, res) return c.Do("GET", url, nil, res)
} }
......
package service package service
import ( import (
"cocogo/pkg/logger"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
...@@ -9,6 +8,7 @@ import ( ...@@ -9,6 +8,7 @@ import (
"strings" "strings"
"cocogo/pkg/common" "cocogo/pkg/common"
"cocogo/pkg/logger"
) )
var ( var (
......
...@@ -3,6 +3,7 @@ package service ...@@ -3,6 +3,7 @@ package service
import ( import (
"cocogo/pkg/logger" "cocogo/pkg/logger"
"cocogo/pkg/model" "cocogo/pkg/model"
"fmt"
) )
// //
...@@ -20,7 +21,8 @@ import ( ...@@ -20,7 +21,8 @@ import (
// //
func GetSystemUserAssetAuthInfo(systemUserID, assetID string) (info model.SystemUserAuthInfo, err error) { func GetSystemUserAssetAuthInfo(systemUserID, assetID string) (info model.SystemUserAuthInfo, err error) {
var authInfo model.SystemUserAuthInfo var authInfo model.SystemUserAuthInfo
err = Client.Get("systemUserAuthInfo", nil, &authInfo) systemUrl := fmt.Sprintf(urls["SystemUserAuthInfo"], systemUserID)
err = Client.Get(systemUrl, &authInfo, true)
if err != nil { if err != nil {
logger.Info("get User Assets Groups err:", err) logger.Info("get User Assets Groups err:", err)
return return
......
package service package service
import ( import (
"net/http"
"path" "path"
"path/filepath" "path/filepath"
"strings"
"cocogo/pkg/common" "cocogo/pkg/common"
"cocogo/pkg/config" "cocogo/pkg/config"
"cocogo/pkg/model"
) )
type ClientAuth interface { type ClientAuth interface {
...@@ -15,36 +14,11 @@ type ClientAuth interface { ...@@ -15,36 +14,11 @@ type ClientAuth interface {
} }
type WrapperClient struct { type WrapperClient struct {
*common.Client Http *common.Client
Auth ClientAuth Auth ClientAuth
BaseHost string BaseHost string
} }
func (c *WrapperClient) SetAuthHeader(r *http.Request) {
if c.Auth != nil {
signature := c.Auth.Sign()
r.Header.Add("Authorization", signature)
}
}
func (c *WrapperClient) ExpandUrl(url string, query map[string]string) string {
return ""
}
func (c *WrapperClient) ParseUrl(url string, params ...map[string]string) string {
var newUrl = ""
if url, ok := urls[url]; ok {
newUrl = url
}
if c.BaseHost != "" {
newUrl = strings.TrimRight(c.BaseHost, "/") + newUrl
}
if len(params) == 1 {
url = c.ParseUrlQuery(url, params[0])
}
return newUrl
}
func (c *WrapperClient) LoadAuth() error { func (c *WrapperClient) LoadAuth() error {
keyPath := config.Conf.AccessKeyFile keyPath := config.Conf.AccessKeyFile
if !path.IsAbs(config.Conf.AccessKeyFile) { if !path.IsAbs(config.Conf.AccessKeyFile) {
...@@ -60,10 +34,18 @@ func (c *WrapperClient) LoadAuth() error { ...@@ -60,10 +34,18 @@ func (c *WrapperClient) LoadAuth() error {
} }
func (c *WrapperClient) CheckAuth() error { func (c *WrapperClient) CheckAuth() error {
//var user model.User var user model.User
//err := c.Get("UserProfileUrl", &user) err := c.Http.Get("UserProfileUrl", &user)
//if err != nil { if err != nil {
// return err return err
//} }
return nil return nil
} }
func (c *WrapperClient) Get(url string, res interface{}, needAuth bool) error {
if needAuth {
c.Http.SetAuth(c.Auth.Sign())
}
return c.Http.Get(c.BaseHost+url, res)
}
...@@ -5,7 +5,7 @@ var urls = map[string]string{ ...@@ -5,7 +5,7 @@ var urls = map[string]string{
"UserProfileUrl": "/api/users/v1/profile/", // 获取当前用户的基本信息 "UserProfileUrl": "/api/users/v1/profile/", // 获取当前用户的基本信息
"SystemUserAssetAuthUrl": "/api/assets/v1/system-user/%s/asset/%s/auth-info/", // 该系统用户对某资产的授权 "SystemUserAssetAuthUrl": "/api/assets/v1/system-user/%s/asset/%s/auth-info/", // 该系统用户对某资产的授权
"SystemUserAuthUrl": "/api/assets/v1/system-user/%s/auth-info/", // 该系统用户的授权 "SystemUserAuthInfo": "/api/assets/v1/system-user/%s/auth-info/", // 该系统用户的授权
"TerminalRegisterUrl": "/api/terminal/v2/terminal-registrations/", // 注册当前coco "TerminalRegisterUrl": "/api/terminal/v2/terminal-registrations/", // 注册当前coco
"TerminalConfigUrl": "/api/terminal/v1/terminal/config/", // 从jumpserver获取coco的配置 "TerminalConfigUrl": "/api/terminal/v1/terminal/config/", // 从jumpserver获取coco的配置
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment