Commit cccf0ae5 authored by Eric's avatar Eric

[update] add perm service

parent 907750c9
package service
import (
"fmt"
"cocogo/pkg/logger"
"cocogo/pkg/model"
)
func GetUserAssets(userId string) (assets model.AssetList) {
return model.AssetList{{Id: "xxxxxxxxx", Hostname: "test", Ip: "192.168.244.185", Port: 22}}
func GetUserAssets(userId, cachePolicy string) (assets model.AssetList) {
if cachePolicy == "" {
cachePolicy = "0"
}
params := map[string]string{"cache_policy": cachePolicy}
Url := authClient.ParseUrlQuery(fmt.Sprintf(UserAssetsURL, userId), params)
err := authClient.Get(Url, &assets)
if err != nil {
logger.Error(err)
}
return
}
func GetUserNodes(userId string) (nodes model.NodeList) {
return model.NodeList{{Id: "XXXXXXX", Name: "test"}}
func GetUserNodes(userId, cachePolicy string) (nodes model.NodeList) {
if cachePolicy == "" {
cachePolicy = "0"
}
params := map[string]string{"cache_policy": cachePolicy}
Url := authClient.ParseUrlQuery(fmt.Sprintf(UserNodesAssetsURL, userId), params)
err := authClient.Get(Url, &nodes)
if err != nil {
logger.Error(err)
}
return
}
func ValidateUserAssetPermission(userId, assetId, systemUserId string) bool {
params := map[string]string{
"user_id": userId,
"asset_id": assetId,
"system_user_id": systemUserId,
"cache_policy": "1",
}
Url := authClient.ParseUrlQuery(ValidateUserAssetPermissionURL, params)
err := authClient.Get(Url, nil)
if err != nil {
logger.Error(err)
return false
}
return true
}
......@@ -35,7 +35,8 @@ func TerminalHeartBeat(sIds []string) (res []model.TerminalTask) {
func CreateSession(data map[string]interface{}) bool {
var res map[string]interface{}
err := authClient.Post(SessionListURL, data, &res)
Url := authClient.ParseUrlQuery(SessionListURL, nil)
err := authClient.Post(Url, data, &res)
if err == nil {
return true
}
......
......@@ -19,7 +19,7 @@ func Authenticate(username, password, publicKey, remoteAddr, loginType string) (
User model.User `json:"user"`
}
err := client.Post(baseHost+UserAuthURL, data, &resp)
err := client.Post(UserAuthURL, data, &resp)
if err != nil {
logger.Error(err)
}
......@@ -27,7 +27,7 @@ func Authenticate(username, password, publicKey, remoteAddr, loginType string) (
}
func GetUserProfile(userId string) (user model.User) {
Url := fmt.Sprintf(baseHost+UserUserURL, userId)
Url := fmt.Sprintf(UserUserURL, userId)
err := authClient.Get(Url, &user)
if err != nil {
logger.Error(err)
......@@ -38,7 +38,8 @@ func GetUserProfile(userId string) (user model.User) {
func CheckUserCookie(sessionId, csrfToken string) (user model.User) {
client.SetCookie("csrftoken", csrfToken)
client.SetCookie("sessionid", sessionId)
err := client.Get(baseHost+UserProfileURL, &user)
Url := client.ParseUrlQuery(UserProfileURL, nil)
err := client.Get(Url, &user)
if err != nil {
logger.Error(err)
}
......
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