Skip to content

Commit

Permalink
Use different .netrc Go lib. (#351)
Browse files Browse the repository at this point in the history
Let's standardize on the one that we're already using internally.
  • Loading branch information
fweikert authored Sep 2, 2022
1 parent 42edfc0 commit 48e743d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 20 deletions.
8 changes: 5 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
11 changes: 2 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
2 changes: 1 addition & 1 deletion httputil/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
10 changes: 4 additions & 6 deletions httputil/httputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"strconv"
"time"

netrc "github.com/jdxcode/netrc"
netrc "github.com/bgentry/go-netrc"
homedir "github.com/mitchellh/go-homedir"
)

Expand Down Expand Up @@ -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.
Expand 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
}

Expand Down

0 comments on commit 48e743d

Please sign in to comment.