Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/any: make the netrc parser importable #31334

kevinburke opened this issue Apr 8, 2019 · 4 comments

x/any: make the netrc parser importable #31334

kevinburke opened this issue Apr 8, 2019 · 4 comments


Copy link

@kevinburke kevinburke commented Apr 8, 2019

There are two implementations of a netrc parser: one lives in src/cmd/go/internal/web2/web.go and the other one lives in x/tools/cmd/auth/netrcauth/netrcauth.go.

Apart from the fact that these two implementations may differ in how they parse the spec this is a useful piece of functionality written by people with a high degree of trust and it would be nice if this library could be imported from somewhere.

Copy link

@bcmills bcmills commented Apr 9, 2019

CC @rogpeppe for

Note that the netrc parser is currently in flux for #26232.

Honestly, though, if you need to consume its output I would rather you just shell out to x/tools/cmd/auth/netrcauth: that command-line API will need to be stable by 1.13, and it's very easy to parse using textproto, so I'm not sure we need to add a Go package API on top of it.

Copy link

@josharian josharian commented Apr 9, 2019

Aside: Possibly a good candidate for fuzzing. cc @thepudds

Copy link
Contributor Author

@kevinburke kevinburke commented Apr 13, 2019

Alright, I might push a proposed interface to and we can see how it looks.

netrcauth seems like it would do what I want, but the goal would be to use it in API clients such as or and I'm not sure I want to count on end users having a second binary - netrcauth - on their machines.

Copy link

@89z 89z commented Mar 29, 2021

I looked over the entire textproto package, but I still dont understand what @bcmills is talking about. They seem to be totally different formats. Here is example format for Netrc:

login 89z
password aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

At any rate, I found that the spec [1] and one popular implementation [2] just assume the tokens are separated by whitespace. So if you have control over the Netrc file, then you can just put each entry on its own line, then its very easy to parse with Go:

package main

import (

func main() {
   file, e := os.ReadFile(".netrc")
   if e != nil {
   var login, pass string
   fmt.Sscanf(string(file), "default login %v password %v", &login, &pass)
   fmt.Println(login, pass)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants