Skip to content

Commit

Permalink
optimize load user
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSen-qn committed Aug 30, 2023
1 parent fd16ee2 commit f1927f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
9 changes: 5 additions & 4 deletions iqshell/common/account/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"strings"

"github.com/qiniu/go-sdk/v7/auth/qbox"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/opt"

"github.com/qiniu/qshell/v2/iqshell/common/config"
"github.com/qiniu/qshell/v2/iqshell/common/data"
"github.com/qiniu/qshell/v2/iqshell/common/log"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/opt"
)

// 保存账户信息到账户文件中
Expand Down Expand Up @@ -98,7 +99,7 @@ func SaveToDB(acc Account, accountOver bool) (err *data.CodeError) {
func getAccount(pt string) (account Account, err *data.CodeError) {
accountFh, openErr := os.Open(pt)
if openErr != nil {
err = data.NewEmptyError().AppendDescF("Open account file error, %s, please use `account` to set Id and SecretKey first", openErr)
err = data.NewEmptyError().AppendDescF("Get account error, %s, please use `account` to set Id and SecretKey first", openErr)
return
}
defer accountFh.Close()
Expand All @@ -116,7 +117,7 @@ func getAccount(pt string) (account Account, err *data.CodeError) {

acc, dErr := decrypt(string(accountBytes))
if dErr != nil {
err = data.NewEmptyError().AppendDescF("Decrypt account bytes: %v", dErr)
err = data.NewEmptyError().AppendDescF("Decrypt account bytes: %s, you can delete account file(%s) and use `account` command to reset the account", dErr, pt)
return
}
account = acc
Expand Down
8 changes: 7 additions & 1 deletion iqshell/common/account/crypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package account

import (
"encoding/base64"
"github.com/qiniu/qshell/v2/iqshell/common/data"
"strings"

"github.com/qiniu/qshell/v2/iqshell/common/data"

"github.com/qiniu/qshell/v2/iqshell/common/utils"
)

Expand All @@ -15,6 +16,11 @@ func splits(joinStr string) []string {
// 对保存在account.json中的文件字符串进行揭秘操作, 返回Account
func decrypt(joinStr string) (acc Account, err *data.CodeError) {
ss := splits(joinStr)
if len(ss) != 3 {
err = data.NewEmptyError().AppendDescF("account json style format error")
return
}

name, accessKey, encryptedKey := ss[0], ss[1], ss[2]
if name == "" || accessKey == "" || encryptedKey == "" {
err = data.NewEmptyError().AppendDescF("name, accessKey and encryptedKey should not be empty")
Expand Down
5 changes: 4 additions & 1 deletion iqshell/common/workspace/load.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package workspace

import (
"path/filepath"

"github.com/qiniu/go-sdk/v7/auth"
"github.com/qiniu/go-sdk/v7/storage"

"github.com/qiniu/qshell/v2/iqshell/common/data"
"path/filepath"

"github.com/qiniu/qshell/v2/iqshell/common/account"
"github.com/qiniu/qshell/v2/iqshell/common/config"
Expand Down Expand Up @@ -151,6 +153,7 @@ func loadUserInfo() {
}
} else {
userDir = filepath.Join(workspaceDir, usersDirName, defaultUserDirName)
log.WarningF("load user error:%s", err)
}

log.DebugF("user dir:%s", userDir)
Expand Down

0 comments on commit f1927f5

Please sign in to comment.