Commit 2e059d9d authored by Eric's avatar Eric

add sftp permssion cache

parent 24dd3c40
...@@ -51,12 +51,15 @@ type sftpHandler struct { ...@@ -51,12 +51,15 @@ type sftpHandler struct {
assets model.AssetList assets model.AssetList
rootPath string // tmp || home || ~ rootPath string // tmp || home || ~
hosts map[string]*HostNameDir hosts map[string]*HostNameDir
permCache map[string]bool
} }
func (fs *sftpHandler) initial() { func (fs *sftpHandler) initial() {
fs.loadAssets() fs.loadAssets()
fs.hosts = make(map[string]*HostNameDir) fs.hosts = make(map[string]*HostNameDir)
fs.rootPath = config.GetConf().SftpRoot fs.rootPath = config.GetConf().SftpRoot
fs.permCache = make(map[string]bool)
for i, item := range fs.assets { for i, item := range fs.assets {
tmpDir := &HostNameDir{ tmpDir := &HostNameDir{
rootPath: fs.rootPath, rootPath: fs.rootPath,
...@@ -401,9 +404,16 @@ func (fs *sftpHandler) Close() { ...@@ -401,9 +404,16 @@ func (fs *sftpHandler) Close() {
} }
func (fs *sftpHandler) validatePermission(aid, suid, operate string) bool { func (fs *sftpHandler) validatePermission(aid, suid, operate string) bool {
return service.ValidateUserAssetPermission( permKey := fmt.Sprintf("%s_%s_%s", aid, suid, operate)
permission, ok := fs.permCache[permKey]
if ok {
return permission
}
permission = service.ValidateUserAssetPermission(
fs.user.ID, aid, suid, operate, fs.user.ID, aid, suid, operate,
) )
fs.permCache[permKey] = permission
return permission
} }
type HostNameDir struct { type HostNameDir struct {
......
...@@ -48,6 +48,8 @@ type UserVolume struct { ...@@ -48,6 +48,8 @@ type UserVolume struct {
hosts map[string]*hostnameVolume hosts map[string]*hostnameVolume
localTmpPath string localTmpPath string
permCache map[string]bool
} }
func (u *UserVolume) initial() { func (u *UserVolume) initial() {
...@@ -55,6 +57,7 @@ func (u *UserVolume) initial() { ...@@ -55,6 +57,7 @@ func (u *UserVolume) initial() {
u.loadAssets() u.loadAssets()
u.rootPath = conf.SftpRoot u.rootPath = conf.SftpRoot
u.localTmpPath = filepath.Join(conf.RootPath, "data", "tmp") u.localTmpPath = filepath.Join(conf.RootPath, "data", "tmp")
u.permCache = make(map[string]bool)
_ = common.EnsureDirExist(u.localTmpPath) _ = common.EnsureDirExist(u.localTmpPath)
u.hosts = make(map[string]*hostnameVolume) u.hosts = make(map[string]*hostnameVolume)
for i, item := range u.assets { for i, item := range u.assets {
...@@ -939,9 +942,16 @@ func (u *UserVolume) CreateFTPLog(data *model.FTPLog) { ...@@ -939,9 +942,16 @@ func (u *UserVolume) CreateFTPLog(data *model.FTPLog) {
} }
func (u *UserVolume) validatePermission(aid, suid, operate string) bool { func (u *UserVolume) validatePermission(aid, suid, operate string) bool {
return service.ValidateUserAssetPermission( permKey := fmt.Sprintf("%s_%s_%s", aid, suid, operate)
permission, ok := u.permCache[permKey]
if ok {
return permission
}
permission = service.ValidateUserAssetPermission(
u.user.ID, aid, suid, operate, u.user.ID, aid, suid, operate,
) )
u.permCache[permKey] = permission
return permission
} }
type hostnameVolume struct { type hostnameVolume struct {
......
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