From 4ed5dc5f592673d7be3a952ebfe30e7520dd135d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E9=93=AD?= Date: Tue, 22 Aug 2023 17:38:54 +0800 Subject: [PATCH] fixed --- cmd/dget/main.go | 2 +- install.go | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/dget/main.go b/cmd/dget/main.go index d908153..d5f93e1 100644 --- a/cmd/dget/main.go +++ b/cmd/dget/main.go @@ -50,7 +50,7 @@ func main() { var client dget.Client if *proxy != "" { - proxyUrl, err := url.Parse("http://proxyIp:proxyPort") + proxyUrl, err := url.Parse(*proxy) if err != nil { logrus.Fatalln("代理地址"+*proxy+"错误", err) } diff --git a/install.go b/install.go index ddcdf19..a76ebde 100644 --- a/install.go +++ b/install.go @@ -89,13 +89,14 @@ func (m *Client) Install(_registry, d, tag string, arch string, printInfo bool) if resp.StatusCode == 401 { //Bearer realm="https://auth.docker.io/token",service="registry.docker.io" var hAuths = strings.Split(resp.Header.Get("Www-Authenticate"), "\"") + logrus.Debugln("Www-Authenticate", hAuths) if len(hAuths) > 1 { authUrl = hAuths[1] } if len(hAuths) > 3 { regService = hAuths[3] } else { - regService = "" + regService = _registry } } resp.Body.Close() @@ -115,8 +116,8 @@ func (m *Client) Install(_registry, d, tag string, arch string, printInfo bool) logrus.Debugln("Authorization by", accessToken) req.Header.Add("Authorization", "Bearer "+accessToken) // req.Header.Add("Accept", "application/vnd.oci.image.manifest.v1+json") - req.Header.Add("Accept", "application/vnd.oci.image.index.v1+json") req.Header.Add("Accept", "application/vnd.docker.distribution.manifest.list.v2+json") + req.Header.Add("Accept", "application/vnd.oci.image.index.v1+json") var authHeader = req.Header @@ -372,7 +373,9 @@ func (m *Client) download(_registry, d, tag string, digest digest.Digest, authHe } func getAuthHead(a, r, d string) (string, error) { - resp, err := http.Get(fmt.Sprintf("%s?service=%s&scope=repository:%s:pull", a, r, d)) + var regUrl = fmt.Sprintf("%s?service=%s&scope=repository:%s:pull", a, r, d) + logrus.Debug("get auth head from", regUrl) + resp, err := http.Get(regUrl) if err == nil { defer resp.Body.Close() var results map[string]interface{}