Commit aa1c9a11 authored by Eric's avatar Eric

add wrapper client request method

parent c9b7f9a4
...@@ -44,7 +44,45 @@ func (c *WrapperClient) CheckAuth() error { ...@@ -44,7 +44,45 @@ func (c *WrapperClient) CheckAuth() error {
func (c *WrapperClient) Get(url string, res interface{}, needAuth bool) error { func (c *WrapperClient) Get(url string, res interface{}, needAuth bool) error {
if needAuth { if needAuth {
c.Http.SetAuth(c.Auth.Sign()) c.Http.SetAuth(c.Auth.Sign())
} else {
c.Http.SetAuth("")
} }
return c.Http.Get(c.BaseHost+url, res) return c.Http.Get(c.BaseHost+url, res)
} }
func (c *WrapperClient) Post(url string, data interface{}, res interface{}, needAuth bool) error {
if needAuth {
c.Http.SetAuth(c.Auth.Sign())
} else {
c.Http.SetAuth("")
}
return c.Http.Post(url, data, res)
}
func (c *WrapperClient) Delete(url string, res interface{}, needAuth bool) error {
if needAuth {
c.Http.SetAuth(c.Auth.Sign())
} else {
c.Http.SetAuth("")
}
return c.Http.Delete(url, res)
}
func (c *WrapperClient) Put(url string, data interface{}, res interface{}, needAuth bool) error {
if needAuth {
c.Http.SetAuth(c.Auth.Sign())
} else {
c.Http.SetAuth("")
}
return c.Http.Put(url, data, res)
}
func (c *WrapperClient) Patch(url string, data interface{}, res interface{}, needAuth bool) error {
if needAuth {
c.Http.SetAuth(c.Auth.Sign())
} else {
c.Http.SetAuth("")
}
return c.Http.Patch(url, data, res)
}
package sdk package sdk
var urls = map[string]string{ const (
"UserAuthUrl": "/api/users/v1/auth/", // post 验证用户登陆 UserAuthURL = "/api/users/v1/auth/" // post 验证用户登陆
"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/" // 该系统用户对某资产的授权
"SystemUserAuthInfo": "/api/assets/v1/system-user/%s/auth-info/", // 该系统用户的授权 SystemUserAuthInfoURL = "/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的配置
"SessionList": "/api/terminal/v1/sessions/", //上传创建的资产会话session id SessionListURL = "/api/terminal/v1/sessions/" //上传创建的资产会话session id
"SessionDetail": "/api/terminal/v1/sessions/%s/", // finish session的时候发送 SessionDetailURL = "/api/terminal/v1/sessions/%s/" // finish session的时候发送
"SessionReplay": "/api/terminal/v1/sessions/%s/replay/", //上传录像 SessionReplayURL = "/api/terminal/v1/sessions/%s/replay/" //上传录像
"UserAssetsUrl": "/api/perms/v1/user/%s/assets/", //获取用户授权的所有资产 UserAssetsURL = "/api/perms/v1/user/%s/assets/" //获取用户授权的所有资产
"UserNodesAssetsUrl": "/api/perms/v1/user/%s/nodes-assets/", // 获取用户授权的所有节点信息 节点分组 UserNodesAssetsURL = "/api/perms/v1/user/%s/nodes-assets/" // 获取用户授权的所有节点信息 节点分组
"ValidateUserAssetPermission": "/api/perms/v1/asset-permission/user/validate/", //0不使用缓存 1 使用缓存 2 刷新缓存 ValidateUserAssetPermissionURL = "/api/perms/v1/asset-permission/user/validate/" //0不使用缓存 1 使用缓存 2 刷新缓存
} )
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