feat: basic auth credentials from netrc#191
Conversation
|
Forgive my naivety here. I've never worked with netrc files before. Are these file paths configurable? A lot of people (myself included) prefer to keep configuration under $XDG_DATA_HOME. For example all of my neovim configuration lives under |
| func userNetrcCredentials(host string) (login, password string) { | ||
| var netrcMachine *netrc.Machine | ||
| for _, netrcFilePath := range []string{home.GPGNetrc(), home.Netrc()} { | ||
| if exists, _ := osutil.Exists(netrcFilePath); !exists { |
There was a problem hiding this comment.
Why do we need to check for existence before parsing the file? Shouldn't netrc.Parse throw os.IsNotExist(err) in that case?
https://github.com/jdxcode/netrc/blob/926c7f70242abe00179235c2b06bb647c0c53a12/netrc.go#L41-L44
Seems like a redundant check.
| if exists, _ := osutil.Exists(netrcFilePath); !exists { | ||
| continue | ||
| } | ||
| netrcFile, err := netrc.Parse(netrcFilePath) |
There was a problem hiding this comment.
with the previous comment in mind... This can be optimized further:
for _, netrcFilePath := range []string{home.GPGNetrc(), home.Netrc()} {
if netrcFile, err := netrc.Parse(netrcFilePath); err != nil {
if !os.IsNotExist(err) {
// we probably want to report an error here; we only care about if the file wasn't found - anything else is indeterministic behavior
}
} else {
netrcMachine = netrcFile.Machine(host)
return netrcMachine.Get("login"), netrcMachine.Get("password")
}
}
return "", ""
Also, how should we handle the case where both .netrc.gpg and .netrc are present on the user's machine? Right now it appears this logic will only read .netrc.gpg and ignore the latter. What if the user wants the program to read from .netrc?
There was a problem hiding this comment.
I was copying what git-credential-netrc was doing
If the user has $NETRC set, it could use that first instead
| // addCredentialsToRequest will attempt to attach relevant credentials to the http.Request | ||
| func addCredentialsToRequest(req *http.Request) { | ||
| login, password := userNetrcCredentials(req.Host) | ||
| if password != "" { |
There was a problem hiding this comment.
What about user accounts with no password? Shouldn't we check both username and password?
.netrc tends to be in the $HOME directory https://linux.die.net/man/1/ftp A number of systems support reading it from $NETRC I can add that? |
add basic auth credentials to request for food packages if present in users netrc file add 'Accept: application/octet-stream' header to permit working through [github api](https://docs.github.com/en/rest/reference/repos#get-a-release-asset) ref: fishworks#190
add basic auth credentials to request for food packages if present in users
netrc file
add 'Accept: application/octet-stream' header to permit working through github
api
ref: #190