Skip to content

Commit

Permalink
io src remove cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSen-qn committed May 22, 2023
1 parent 47ca2b0 commit ef9de86
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 77 deletions.
8 changes: 6 additions & 2 deletions cmd_test/download_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ func TestGetImage(t *testing.T) {
t.Fatal("get result path error:", err)
}
path := filepath.Join(resultPath, test.ImageKey)
_, errs := test.RunCmdWithError("get", test.Bucket, test.ImageKey,
ret, errs := test.RunCmdWithError("get", test.Bucket, test.ImageKey,
"--public",
"-o", path)
"-o", path,
"-d")
defer test.RemoveFile(path)

if len(errs) > 0 {
t.Fail()
}
if !strings.Contains(ret, ".qiniucs.com") {
t.Fatal("get file: should get io src domain")
}
if !test.IsFileHasContent(path) {
t.Fatal("get file content can't be empty")
}
Expand Down
2 changes: 1 addition & 1 deletion docs/get.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $ qshell get --doc

# 选项
- -o/--outfile:保存在本地的文件路径;不指定,保存在当前文件夹,文件名使用存储空间中的名字【可选】
- --domain:设置下载请求的域名,默认为空表示从存储源站下载,qshell 下载使用域名的优先级:1.配置选项中的下载请求域名(此参数) 2.bucket 绑定的域名(qshell 内部查询,无需配置) ,当优先级高的域名下载失败后会尝试使用优先级低的域名进行下载。【可选】
- --domain:设置下载请求的域名,默认为空表示从存储源站下载,qshell 下载使用域名的优先级:1.配置选项中的下载请求域名(此参数) 2.bucket 绑定的域名(qshell 内部查询,无需配置) 3. 源站域名(qshell 内部查询,无需配置),当优先级高的域名下载失败后会尝试使用优先级低的域名进行下载。【可选】
- --get-file-api: 当存储服务端支持 getfile 接口时才有效。【可选】
- --public:空间是否为公开空间;为 `true` 时为公有空间,公有空间下载时不会对下载 URL 进行签名,可以提升 CDN 域名性能,默认为 `false`(私有空间)【可选】
- --check-size: 下载后检测本地文件和服务端文件 size 的一致性。【可选】
Expand Down
7 changes: 0 additions & 7 deletions iqshell/common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ func (c *Config) GetRegion() *storage.Region {
}
}

func (c *Config) GetIoSrcHost() string {
if c == nil || c.Hosts == nil {
return ""
}
return c.Hosts.GetOneIoSrc()
}

func (c *Config) Merge(from *Config) {
if from == nil {
return
Expand Down
13 changes: 6 additions & 7 deletions iqshell/common/config/config_global.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ func GetGlobal() *Config {
},
UseHttps: getIsUseHttps(ConfigTypeGlobal),
Hosts: &Hosts{
UC: GetUcHosts(ConfigTypeGlobal),
Api: GetApiHosts(ConfigTypeGlobal),
Rs: GetRsHosts(ConfigTypeGlobal),
Rsf: GetRsfHosts(ConfigTypeGlobal),
Io: GetIoHosts(ConfigTypeGlobal),
Up: GetUpHosts(ConfigTypeGlobal),
IoSrc: GetIoSrcHosts(ConfigTypeGlobal),
UC: GetUcHosts(ConfigTypeGlobal),
Api: GetApiHosts(ConfigTypeGlobal),
Rs: GetRsHosts(ConfigTypeGlobal),
Rsf: GetRsfHosts(ConfigTypeGlobal),
Io: GetIoHosts(ConfigTypeGlobal),
Up: GetUpHosts(ConfigTypeGlobal),
},
}
}
8 changes: 0 additions & 8 deletions iqshell/common/config/config_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ var (
localKeyHostUc = []string{"hosts.uc", "hosts.uc_host"}
localKeyHostUcs = []string{"hosts.ucs", "hosts.uc_hosts"}

// IO SRC HOST
localKeyHostIoSrc = []string{"hosts.io_src", "hosts.io_src_host"}
localKeyHostIoSrcs = []string{"hosts.io_srcs", "hosts.io_src_hosts"}

// USE HTTPS
localKeyIsUseHttps = []string{"use_https"}

Expand Down Expand Up @@ -95,10 +91,6 @@ func GetApiHosts(configType ConfigType) []string {
return getHostsFromLocal(configType, localKeyHostApi, localKeyHostApis)
}

func GetIoSrcHosts(configType ConfigType) []string {
return getHostsFromLocal(configType, localKeyHostIoSrc, localKeyHostIoSrcs)
}

func GetCredentials(configType ConfigType) auth.Credentials {
return auth.Credentials{
AccessKey: getAccessKey(configType),
Expand Down
13 changes: 6 additions & 7 deletions iqshell/common/config/config_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ func GetUser() *Config {
},
UseHttps: getIsUseHttps(ConfigTypeUser),
Hosts: &Hosts{
UC: GetUcHosts(ConfigTypeUser),
Api: GetApiHosts(ConfigTypeUser),
Rs: GetRsHosts(ConfigTypeUser),
Rsf: GetRsfHosts(ConfigTypeUser),
Io: GetIoHosts(ConfigTypeUser),
Up: GetUpHosts(ConfigTypeUser),
IoSrc: GetIoSrcHosts(ConfigTypeUser),
UC: GetUcHosts(ConfigTypeUser),
Api: GetApiHosts(ConfigTypeUser),
Rs: GetRsHosts(ConfigTypeUser),
Rsf: GetRsfHosts(ConfigTypeUser),
Io: GetIoHosts(ConfigTypeUser),
Up: GetUpHosts(ConfigTypeUser),
},
}
}
21 changes: 6 additions & 15 deletions iqshell/common/config/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package config
import "github.com/qiniu/qshell/v2/iqshell/common/utils"

type Hosts struct {
UC []string `json:"uc,omitempty"`
Api []string `json:"api,omitempty"`
Rs []string `json:"rs,omitempty"`
Rsf []string `json:"rsf,omitempty"`
Io []string `json:"io,omitempty"`
Up []string `json:"up,omitempty"`
IoSrc []string `json:"io_src,omitempty"`
UC []string `json:"uc,omitempty"`
Api []string `json:"api,omitempty"`
Rs []string `json:"rs,omitempty"`
Rsf []string `json:"rsf,omitempty"`
Io []string `json:"io,omitempty"`
Up []string `json:"up,omitempty"`
}

func (h *Hosts) GetOneUc() string {
Expand All @@ -36,10 +35,6 @@ func (h *Hosts) GetOneUp() string {
return getOneHostFromStringArray(h.Up)
}

func (h *Hosts) GetOneIoSrc() string {
return getOneHostFromStringArray(h.IoSrc)
}

func getOneHostFromStringArray(hosts []string) string {
hosts = getRealHosts(hosts)
if len(hosts) > 0 {
Expand Down Expand Up @@ -89,8 +84,4 @@ func (h *Hosts) merge(from *Hosts) {
if len(h.Up) == 0 {
h.Up = getRealHosts(from.Up)
}

if len(h.IoSrc) == 0 {
h.IoSrc = getRealHosts(from.IoSrc)
}
}
17 changes: 7 additions & 10 deletions iqshell/storage/object/download/operations/download_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,13 @@ func defaultDownloadHosts(cfg *config.Config, downloadCfg *DownloadCfg) []*host.
}

// 3. 源站域名
// 此处不传 RegionId 通过 UC bucket 接口自动获取
if ioSrcHosts, e := download.CreateSrcDownloadDomainWithBucket(cfg, downloadCfg.Bucket); e != nil {
log.DebugF("create bucket:%s src domain error:%v", b, e)
} else {
for _, h := range ioSrcHosts {
hosts = append(hosts, &host.Host{
Host: "",
Domain: h,
})
}
if ioSrcHost, e := download.CreateSrcDownloadDomainWithBucket(cfg, downloadCfg.Bucket); e != nil {
log.Warning("create bucket:%s src domain error:%v", b, e)
} else if len(ioSrcHost) > 0 {
hosts = append(hosts, &host.Host{
Host: "",
Domain: ioSrcHost,
})
}

return hosts
Expand Down
26 changes: 6 additions & 20 deletions iqshell/storage/object/download/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,12 @@ func createDownloadUrl(info *DownloadApiInfo) (string, *data.CodeError) {
}

// CreateSrcDownloadDomainWithBucket bucket 源站下载域名
func CreateSrcDownloadDomainWithBucket(cfg *config.Config, bucketName string) ([]string, *data.CodeError) {

hosts := make([]string, 0, 0)
if cfg != nil && len(cfg.GetIoSrcHost()) > 0 {
hosts = append(hosts, cfg.GetIoSrcHost())
}

func CreateSrcDownloadDomainWithBucket(cfg *config.Config, bucketName string) (string, *data.CodeError) {
serverCfgHost, err := getSrcDownloadDomainWithBucket(bucketName)
if err != nil {
log.WarningF("get io src host for bucket:%s error:%v", bucketName, err)
}
if len(serverCfgHost) > 0 {
hosts = append(hosts, serverCfgHost)
return "", err
}
return hosts, nil
return serverCfgHost, nil
}

func isIoSrcHost(host string, bucketName string) bool {
Expand All @@ -162,15 +153,10 @@ func isIoSrcHost(host string, bucketName string) bool {
return false
}

customEndpoint := ""
if workspace.GetConfig() != nil {
customEndpoint = workspace.GetConfig().GetIoSrcHost()
}
if len(customEndpoint) > 0 {
return strings.Contains(host, customEndpoint)
srcDownloadDomain, err := getSrcDownloadDomainWithBucket(bucketName)
if err != nil {
log.WarningF("check host is src host error:%v", err)
}

srcDownloadDomain, _ := getSrcDownloadDomainWithBucket(bucketName)
if len(srcDownloadDomain) == 0 {
return false
}
Expand Down

0 comments on commit ef9de86

Please sign in to comment.