Unverified Commit 00fd5d8a authored by Eric_Lee's avatar Eric_Lee Committed by GitHub

155dev (#163)

 sftp node tree
parent 700af064
...@@ -14,7 +14,6 @@ import ( ...@@ -14,7 +14,6 @@ import (
"github.com/jumpserver/koko/pkg/logger" "github.com/jumpserver/koko/pkg/logger"
"github.com/jumpserver/koko/pkg/model" "github.com/jumpserver/koko/pkg/model"
"github.com/jumpserver/koko/pkg/service"
"github.com/jumpserver/koko/pkg/srvconn" "github.com/jumpserver/koko/pkg/srvconn"
) )
...@@ -46,12 +45,11 @@ func SftpHandler(sess ssh.Session) { ...@@ -46,12 +45,11 @@ func SftpHandler(sess ssh.Session) {
} }
func NewSFTPHandler(user *model.User, addr string) *sftpHandler { func NewSFTPHandler(user *model.User, addr string) *sftpHandler {
assets := service.GetUserAllAssets(user.ID) return &sftpHandler{srvconn.NewUserSftpConn(user, addr)}
return &sftpHandler{srvconn.NewUserSFTP(user, addr, assets...)}
} }
type sftpHandler struct { type sftpHandler struct {
*srvconn.UserSftp *srvconn.UserSftpConn
} }
func (fs *sftpHandler) Filelist(r *sftp.Request) (sftp.ListerAt, error) { func (fs *sftpHandler) Filelist(r *sftp.Request) (sftp.ListerAt, error) {
...@@ -122,7 +120,7 @@ func (fs *sftpHandler) Fileread(r *sftp.Request) (io.ReaderAt, error) { ...@@ -122,7 +120,7 @@ func (fs *sftpHandler) Fileread(r *sftp.Request) (io.ReaderAt, error) {
} }
func (fs *sftpHandler) Close() { func (fs *sftpHandler) Close() {
fs.UserSftp.Close() fs.UserSftpConn.Close()
} }
type listerat []os.FileInfo type listerat []os.FileInfo
......
...@@ -18,14 +18,14 @@ import ( ...@@ -18,14 +18,14 @@ import (
) )
func NewUserVolume(user *model.User, addr, hostId string) *UserVolume { func NewUserVolume(user *model.User, addr, hostId string) *UserVolume {
var assets []model.Asset var userSftp *srvconn.UserSftpConn
homename := "Home" homename := "Home"
basePath := "/" basePath := "/"
switch hostId { switch hostId {
case "": case "":
assets = service.GetUserAllAssets(user.ID) userSftp = srvconn.NewUserSftpConn(user, addr)
default: default:
assets = service.GetUserAssetByID(user.ID, hostId) assets := service.GetUserAssetByID(user.ID, hostId)
if len(assets) == 1 { if len(assets) == 1 {
homename = assets[0].Hostname homename = assets[0].Hostname
if assets[0].OrgID != "" { if assets[0].OrgID != "" {
...@@ -33,11 +33,12 @@ func NewUserVolume(user *model.User, addr, hostId string) *UserVolume { ...@@ -33,11 +33,12 @@ func NewUserVolume(user *model.User, addr, hostId string) *UserVolume {
} }
basePath = filepath.Join("/", homename) basePath = filepath.Join("/", homename)
} }
userSftp = srvconn.NewUserSftpConnWithAssets(user, addr, assets...)
} }
rawID := fmt.Sprintf("%s@%s", user.Username, addr) rawID := fmt.Sprintf("%s@%s", user.Username, addr)
uVolume := &UserVolume{ uVolume := &UserVolume{
Uuid: elfinder.GenerateID(rawID), Uuid: elfinder.GenerateID(rawID),
UserSftp: srvconn.NewUserSFTP(user, addr, assets...), UserSftp: userSftp,
Homename: homename, Homename: homename,
basePath: basePath, basePath: basePath,
chunkFilesMap: make(map[int]*sftp.File), chunkFilesMap: make(map[int]*sftp.File),
...@@ -48,7 +49,7 @@ func NewUserVolume(user *model.User, addr, hostId string) *UserVolume { ...@@ -48,7 +49,7 @@ func NewUserVolume(user *model.User, addr, hostId string) *UserVolume {
type UserVolume struct { type UserVolume struct {
Uuid string Uuid string
*srvconn.UserSftp UserSftp *srvconn.UserSftpConn
Homename string Homename string
basePath string basePath string
...@@ -66,7 +67,7 @@ func (u *UserVolume) Info(path string) (elfinder.FileDir, error) { ...@@ -66,7 +67,7 @@ func (u *UserVolume) Info(path string) (elfinder.FileDir, error) {
if path == "/" { if path == "/" {
return u.RootFileDir(), nil return u.RootFileDir(), nil
} }
originFileInfo, err := u.Stat(filepath.Join(u.basePath, path)) originFileInfo, err := u.UserSftp.Stat(filepath.Join(u.basePath, path))
if err != nil { if err != nil {
return rest, err return rest, err
} }
......
package model
import "encoding/json"
type NodeTreeList []NodeTreeAsset
type NodeTreeAsset struct {
ID string `json:"id"`
Name string `json:"name"`
Title string `json:"title"`
Meta map[string]interface{} `json:"meta"`
}
func ConvertMetaToNode(body []byte) (node Node, err error) {
err = json.Unmarshal(body, &node)
return
}
func ConvertMetaToAsset(body []byte) (asset Asset, err error) {
err = json.Unmarshal(body, &asset)
return
}
...@@ -165,3 +165,20 @@ func ValidateUserAssetPermission(userID, assetID, systemUserID, action string) b ...@@ -165,3 +165,20 @@ func ValidateUserAssetPermission(userID, assetID, systemUserID, action string) b
return res.Msg return res.Msg
} }
func GetUserNodeTreeWithAsset(userID, nodeID, cachePolicy string) (nodeTrees model.NodeTreeList) {
if cachePolicy == "" {
cachePolicy = "1"
}
payload := map[string]string{"cache_policy": cachePolicy}
if nodeID != "" {
payload["id"] = nodeID
}
Url := fmt.Sprintf(NodeTreeWithAssetURL, userID)
_, err := authClient.Get(Url, &nodeTrees, payload)
if err != nil {
logger.Error("Get user node tree error: ", err)
}
return
}
...@@ -43,4 +43,6 @@ const ( ...@@ -43,4 +43,6 @@ const (
const ( const (
UserTokenAuthURL = "/api/v1/authentication/tokens/" // 用户登录验证 UserTokenAuthURL = "/api/v1/authentication/tokens/" // 用户登录验证
UserConfirmAuthURL = "/api/v1/authentication/login-confirm-ticket/status/" UserConfirmAuthURL = "/api/v1/authentication/login-confirm-ticket/status/"
NodeTreeWithAssetURL = "/api/v1/perms/users/%s/nodes/children-with-assets/tree/" // 资产树
) )
This diff is collapsed.
This diff is collapsed.
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