From eca5859e95f0d5eaebc0dcf57169233973e69255 Mon Sep 17 00:00:00 2001 From: yangsen Date: Fri, 2 Jul 2021 10:29:06 +0800 Subject: [PATCH 1/3] uc host check scheme --- iqshell/config.go | 11 ++++++++--- iqshell/utils.go | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/iqshell/config.go b/iqshell/config.go index 55027065..da417bd8 100644 --- a/iqshell/config.go +++ b/iqshell/config.go @@ -4,6 +4,7 @@ import ( "github.com/spf13/pflag" "github.com/spf13/viper" "path/filepath" + "strings" ) const ( @@ -241,10 +242,14 @@ func SetDefaultApiHost(val string) { func UcHost() string { host := viper.GetString(HOST_UC[0]) - if host != "" { - return host + if host == "" { + host = viper.GetString(HOST_UC[1]) + } + + if !strings.Contains(host, "://") { + host = Endpoint(true, host) } - return viper.GetString(HOST_UC[1]) + return host } func SetUcHost(val string) { diff --git a/iqshell/utils.go b/iqshell/utils.go index 757d9b04..d9ee0631 100644 --- a/iqshell/utils.go +++ b/iqshell/utils.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/json" "errors" + "fmt" "io" "net/url" "os" @@ -285,3 +286,17 @@ func SimpleUnescape(s *string) string { `\'`, `'`) return r.Replace(*s) } + +func Endpoint(useHttps bool, host string) string { + host = strings.TrimSpace(host) + host = strings.TrimLeft(host, "http://") + host = strings.TrimLeft(host, "https://") + if host == "" { + return "" + } + scheme := "http://" + if useHttps { + scheme = "https://" + } + return fmt.Sprintf("%s%s", scheme, host) +} From 0e6218256139581c5d0d3fee0bee11e875f1b0a4 Mon Sep 17 00:00:00 2001 From: yangsen Date: Fri, 2 Jul 2021 15:22:00 +0800 Subject: [PATCH 2/3] api host not set default --- cmd/asyncfetch.go | 3 --- cmd/root.go | 1 - cmd/rsbatch.go | 1 + 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/cmd/asyncfetch.go b/cmd/asyncfetch.go index a73f6294..410d67ea 100644 --- a/cmd/asyncfetch.go +++ b/cmd/asyncfetch.go @@ -46,9 +46,6 @@ func NewCmdAsyncCheck() *cobra.Command { Run: func(cmd *cobra.Command, positionalArgs []string) { bm := iqshell.GetBucketManager() - // let API choose APIHOST - bm.Cfg.ApiHost = "" - ret, err := bm.CheckAsyncFetchStatus(positionalArgs[0], positionalArgs[1]) if err != nil { fmt.Fprintf(os.Stderr, "CheckAsyncFetchStatus: %v\n", err) diff --git a/cmd/root.go b/cmd/root.go index 87fe42e0..b7f970f8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -149,7 +149,6 @@ func initConfig() { iqshell.SetDefaultAccPath(filepath.Join(rootPath, "account.json")) iqshell.SetDefaultRsHost(storage.DefaultRsHost) iqshell.SetDefaultRsfHost(storage.DefaultRsfHost) - iqshell.SetDefaultApiHost(storage.DefaultAPIHost) iqshell.SetDefaultUcHost("https://uc.qbox.me") if rErr := viper.ReadInConfig(); rErr != nil { diff --git a/cmd/rsbatch.go b/cmd/rsbatch.go index 82397715..4a75fd02 100644 --- a/cmd/rsbatch.go +++ b/cmd/rsbatch.go @@ -218,6 +218,7 @@ func (fc *fetchConfig) initBucketManager() { cfg := storage.Config{ IoHost: fc.upHost, + ApiHost: iqshell.ApiHost(), } fc.bm = iqshell.GetBucketManagerWithConfig(&cfg) } From cf567ce1fe45f63910055485940f922f12b0a996 Mon Sep 17 00:00:00 2001 From: yangsen Date: Fri, 2 Jul 2021 15:22:50 +0800 Subject: [PATCH 3/3] gofmt --- cmd/rsbatch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/rsbatch.go b/cmd/rsbatch.go index 4a75fd02..d2cf5a10 100644 --- a/cmd/rsbatch.go +++ b/cmd/rsbatch.go @@ -217,7 +217,7 @@ func (fc *fetchConfig) initFileExporter() { func (fc *fetchConfig) initBucketManager() { cfg := storage.Config{ - IoHost: fc.upHost, + IoHost: fc.upHost, ApiHost: iqshell.ApiHost(), } fc.bm = iqshell.GetBucketManagerWithConfig(&cfg)