Skip to content

Commit

Permalink
Merge pull request #320 from YangSen-qn/dev
Browse files Browse the repository at this point in the history
uc host check scheme
  • Loading branch information
xwen-winnie authored Jul 6, 2021
2 parents b27b4bb + cf567ce commit 9312794
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
3 changes: 0 additions & 3 deletions cmd/asyncfetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion cmd/rsbatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ 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)
}
Expand Down
11 changes: 8 additions & 3 deletions iqshell/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/spf13/pflag"
"github.com/spf13/viper"
"path/filepath"
"strings"
)

const (
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions iqshell/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"net/url"
"os"
Expand Down Expand Up @@ -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)
}

0 comments on commit 9312794

Please sign in to comment.