From 48e743d62b87d0c86739e589407f8e8e47f872f3 Mon Sep 17 00:00:00 2001 From: Florian Weikert Date: Fri, 2 Sep 2022 16:54:58 +0200 Subject: [PATCH] Use different .netrc Go lib. (#351) Let's standardize on the one that we're already using internally. --- WORKSPACE | 8 +++++--- go.mod | 2 +- go.sum | 11 ++--------- httputil/BUILD | 2 +- httputil/httputil.go | 10 ++++------ 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 533c4c29..352ae692 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -43,9 +43,11 @@ go_repository( ) go_repository( - name = "com_github_jdxcode_netrc", - importpath = "github.com/jdxcode/netrc", - commit = "926c7f70242abe00179235c2b06bb647c0c53a12", + name = "com_github_bgentry_go_netrc", + importpath = "github.com/bgentry/go-netrc", + urls=["https://github.com/bgentry/go-netrc/archive/9fd32a8.zip"], + type = "zip", + strip_prefix = "go-netrc-9fd32a8b3d3d3f9d43c341bfe098430e07609480/netrc", ) go_rules_dependencies() diff --git a/go.mod b/go.mod index 752c4752..b4333316 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( github.com/bazelbuild/rules_go v0.34.0 + github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d github.com/hashicorp/go-version v1.6.0 - github.com/jdxcode/netrc v0.0.0-20210204082910-926c7f70242a github.com/mitchellh/go-homedir v1.1.0 ) diff --git a/go.sum b/go.sum index e52a172f..e5ef5fd2 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,8 @@ github.com/bazelbuild/rules_go v0.34.0 h1:cmObMtgIOaEU944SqXtJ9DnlS8IPGGa7pdRnsrpQzXM= github.com/bazelbuild/rules_go v0.34.0/go.mod h1:MC23Dc/wkXEyk3Wpq6lCqz0ZAYOZDw2DR5y3N1q2i7M= +github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas= +github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4= github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/jdxcode/netrc v0.0.0-20210204082910-926c7f70242a h1:d4+I1YEKVmWZrgkt6jpXBnLgV2ZjO0YxEtLDdfIZfH4= -github.com/jdxcode/netrc v0.0.0-20210204082910-926c7f70242a/go.mod h1:Zi/ZFkEqFHTm7qkjyNJjaWH4LQA9LQhGJyF0lTYGpxw= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U= -gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/httputil/BUILD b/httputil/BUILD index 89113cad..f168cffa 100644 --- a/httputil/BUILD +++ b/httputil/BUILD @@ -12,7 +12,7 @@ go_library( ], deps = [ "@com_github_mitchellh_go_homedir//:go_default_library", - "@com_github_jdxcode_netrc//:go_default_library" + "@com_github_bgentry_go_netrc//:go_default_library" ], importpath = "github.com/bazelbuild/bazelisk/httputil", visibility = ["//visibility:public"], diff --git a/httputil/httputil.go b/httputil/httputil.go index cbebf98b..9e18e53e 100644 --- a/httputil/httputil.go +++ b/httputil/httputil.go @@ -16,7 +16,7 @@ import ( "strconv" "time" - netrc "github.com/jdxcode/netrc" + netrc "github.com/bgentry/go-netrc" homedir "github.com/mitchellh/go-homedir" ) @@ -146,13 +146,13 @@ func tryFindNetrcFileCreds(host string) (string, error) { } var file = filepath.Join(dir, ".netrc") - n, err := netrc.Parse(file) + n, err := netrc.ParseFile(file) if err != nil { // netrc does not exist or we can't read it return "", err } - m := n.Machine(host) + m := n.FindMachine(host) if m == nil { // if host is not found, we should proceed without providing any Authorization header, // because remote host may not have auth at all. @@ -162,9 +162,7 @@ func tryFindNetrcFileCreds(host string) (string, error) { log.Printf("Using basic authentication credentials for host %s from %s", host, file) - login := m.Get("login") - pwd := m.Get("password") - token := b64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", login, pwd))) + token := b64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", m.Login, m.Password))) return fmt.Sprintf("Basic %s", token), nil }