-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Feature: add support to read from netrc #329
Feature: add support to read from netrc #329
Conversation
404bf3f
to
85f4020
Compare
Hi @adolsalamanca, Thank you for working on this 🙌🏻 Since the tool is getting some attention recently and lot of devs relying on the project, I think it would be better to stick with the standard As you mentioned in the description, golang already implements netrc protocol. We can borrow the package (with credit) and use it for our token validation. We will have one less thing to maintain if we stick with this. |
85f4020
to
52a2918
Compare
Omg @ankitpokhrel, my bad, this was a typo. The thing is that I decided to slightly modify their implementation because they were just relying on global vars, but maybe I can try to make use of the original implementation with a few tweaks. |
Thanks for responding so fast mate!! @ankitpokhrel Only thing added was the function The only problem is that Deepsource is now complaining due to case "default" redundant inside netrc reader. Best regards |
68b63a0
to
e9593d0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @adolsalamanca,
Overall this is getting in shape. There are few things we should keep in mind tho.
- I believe
machine
name is unique in each.netrc
file. If there are duplicates first entry is the valid one. These details are usually used for auto-login process and as per the spec, auto-login can be initiated as soon as the first entry for the machine is found. - When the user enters server name during
jira init
process, we need to make sure not to ask for theusername/email
if it is present in.netrc
file. We can do this in a different PR if this one is getting big.
Let me know if you need any help and thank you again for working on this.
pkg/netrc/reader.go
Outdated
return "", netrcErr | ||
} | ||
|
||
jiraServerURL, err := url.ParseRequestURI(jiraServer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
netrc has nothing to do with Jira and netrc
package should not care anything about it at all.
I would suggest to keep reader
and reader_test
sync with the original implementation including license information (required as per BSD).
You can have a new file called netrc.go
in the package that will expose required methods to work with netrc
package.
// Package netrc implements GNU .netrc specification.
// This implementation is borrowed from the original implementation by the go authors.
// See https://github.com/golang/go/blob/master/src/cmd/go/internal/auth/netrc.go
// See https://www.gnu.org/software/inetutils/manual/html_node/The-_002enetrc-file.html
package netrc
import (
"fmt"
)
// ErrNetRCEntryNotFound is thrown if details for the machine is not found.
var ErrNetRCEntryNotFound = fmt.Errorf("netrc: entry not found in config")
// Entry is a netrc config entry.
type Entry struct {
Machine string
Login string
Password string
}
// Read reads config for the given machine.
func Read(machine string) (*Entry, error) {
netrcOnce.Do(readNetrc)
if netrcErr != nil {
return nil, fmt.Errorf("netrc: %w", netrcErr)
}
for _, line := range netrc {
if line.machine == machine {
return &Entry{
Machine: line.machine,
Login: line.login,
Password: line.password,
}, nil
}
}
return nil, ErrNetRCEntryNotFound
}
Now, you can use the exposed method elsewhere.
netrcEntry, err := netrc.Read(config.Server)
Please feel free to update above implementation as necessary.
Regarding this, don't worry about deepsource complaint in third-party or borrowed files. Not all issues reported by deepsource are crucial. |
Thanks for the reviews mate!
This is that happens when you refactor in automatic mode, but the original intention was completely separate responsibilities, that's why I created netrc in pkg folder. Good catch! Will apply suggestions soon, have a good start of the week :) |
Hey @ankitpokhrel Still, there's something I would like to improve, when the Thanks!! |
a5f4d1f
to
3aafbe6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @adolsalamanca, this seem to be working fine so merging this. Thank you 🙇🏻.
Just a heads up, I might do some changes for better user experience.
Description
This PR includes a tiny new feature to support reading configs from .netrc file as suggested in this issue
Changes
JIRA_API_TOKEN
env variable.Checks
Let me know or feel free to edit the code if there's something that doesn't fit in terms of structure or approach :)