diff --git a/src/main.go b/src/main.go index 41ce51a7..7e874538 100644 --- a/src/main.go +++ b/src/main.go @@ -5,15 +5,16 @@ import ( "encoding/json" "flag" "fmt" - "github.com/astaxie/beego/logs" "os" "os/user" "path/filepath" - "qiniu/api.v6/conf" "qiniu/rpc" "qshell" "runtime" "strings" + + "github.com/astaxie/beego/logs" + "qiniu/api.v6/conf" ) var supportedCmds = map[string]cli.CliFunc{ @@ -79,6 +80,40 @@ type HostConfig struct { RsfHost string `json:"rsf"` } +func readConfig(confPath string) { + confFp, openErr := os.Open(confPath) + if openErr != nil { + fmt.Println("Error: open specified host file error,", openErr) + os.Exit(qshell.STATUS_HALT) + return + } + + var hostCfg HostConfig + decoder := json.NewDecoder(confFp) + decodeErr := decoder.Decode(&hostCfg) + if decodeErr != nil { + fmt.Println("Error: read host file error,", decodeErr) + os.Exit(qshell.STATUS_HALT) + return + } + + if len(hostCfg.UpHost) == 0 { + return + } + + conf.UP_HOST = hostCfg.UpHost + conf.RS_HOST = hostCfg.RsHost + conf.RSF_HOST = hostCfg.RsfHost + conf.IO_HOST = hostCfg.IoHost + conf.API_HOST = hostCfg.ApiHost + + //bucket domains + qshell.BUCKET_RS_HOST = hostCfg.RsHost + qshell.BUCKET_API_HOST = hostCfg.ApiHost + + cli.IsHostFileSpecified = true +} + func main() { //set cpu count runtime.GOMAXPROCS(runtime.NumCPU()) @@ -151,38 +186,13 @@ func main() { accountName := strings.TrimSuffix(filepath.Base(accountFile), filepath.Ext(accountFile)) qshell.QAccountName = accountName qshell.QAccountFile = accountFile + readConfig(accountFile) } } //read host file if hostFile != "" { - hostFp, openErr := os.Open(hostFile) - if openErr != nil { - fmt.Println("Error: open specified host file error,", openErr) - os.Exit(qshell.STATUS_HALT) - return - } - - var hostCfg HostConfig - decoder := json.NewDecoder(hostFp) - decodeErr := decoder.Decode(&hostCfg) - if decodeErr != nil { - fmt.Println("Error: read host file error,", decodeErr) - os.Exit(qshell.STATUS_HALT) - return - } - - conf.UP_HOST = hostCfg.UpHost - conf.RS_HOST = hostCfg.RsHost - conf.RSF_HOST = hostCfg.RsfHost - conf.IO_HOST = hostCfg.IoHost - conf.API_HOST = hostCfg.ApiHost - - //bucket domains - qshell.BUCKET_RS_HOST = hostCfg.RsHost - qshell.BUCKET_API_HOST = hostCfg.ApiHost - - cli.IsHostFileSpecified = true + readConfig(hostFile) } //set cmd and params diff --git a/src/qshell/account.go b/src/qshell/account.go index 6d4579a3..57d57433 100644 --- a/src/qshell/account.go +++ b/src/qshell/account.go @@ -4,10 +4,11 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/astaxie/beego/logs" "io/ioutil" "os" "path/filepath" + + "github.com/astaxie/beego/logs" ) type Account struct { @@ -104,12 +105,7 @@ func GetAccount() (account Account, err error) { } // backwards compatible with old version of qshell, which encrypt ak/sk based on existing ak/sk - if len(account.SecretKey) == 40 { - setErr := SetAccount(account.AccessKey, account.SecretKey) - if setErr != nil { - return - } - } else { + if len(account.SecretKey) != 40 { aesKey := Md5Hex(account.AccessKey) encryptedSecretKeyBytes, decodeErr := base64.URLEncoding.DecodeString(account.SecretKey) if decodeErr != nil {