Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bilibili ,put host config in account.conf #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 39 additions & 29 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions src/qshell/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down