-
-
Notifications
You must be signed in to change notification settings - Fork 522
implemented git credential caching #743
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
implemented git credential caching #743
Conversation
596d546
to
bdb7db1
Compare
Codecov Report
@@ Coverage Diff @@
## master #743 +/- ##
==========================================
+ Coverage 64.81% 64.94% +0.13%
==========================================
Files 169 170 +1
Lines 9134 9270 +136
==========================================
+ Hits 5920 6020 +100
- Misses 2489 2511 +22
- Partials 725 739 +14
Continue to review full report at Codecov.
|
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.
Very nice PR overall. Thanks a lot!
I left some comments, please review them.
Also I'd like to see some kind of tests for this.
We have a lot of tests dealing with stdin to get you started.
pkg/action/git-credential.go
Outdated
"os" | ||
"strings" | ||
|
||
"github.com/justwatchcom/gopass/pkg/store/sub" |
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.
Missing gofmt?
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.
I used goimports, which handles it like that...
pkg/action/git-credential.go
Outdated
Password string | ||
} | ||
|
||
func (c *gitCredentials) WriteTo(w io.Writer) (int64, error) { |
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.
Please add a godoc comment on this method
pkg/action/git-credential.go
Outdated
c := &gitCredentials{} | ||
for { | ||
key, err := rd.ReadString('=') | ||
if err == io.EOF { |
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.
I'd prefer to write it as if err != nil { if err == io.EOF { ... } }
rd := bufio.NewReader(r) | ||
c := &gitCredentials{} | ||
for { | ||
key, err := rd.ReadString('=') |
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.
Why not just do
line, err := rd.ReadString('\n')
kv := strings.SplitN(line, "=", 2)
key = strings.TrimSpace(kv[0])
value = strings.TrimSpace(kv[1])
I admit that it's not much shorter, but that's the way I usually do this.
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.
It just seemed more straightforward to read the format exactly as it is described in the man page
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.
Ok, if you're doing this on purpose (i.e. because it follows the man page closely), I'm good with that.
pkg/action/git-credential.go
Outdated
return ExitError(ctx, ExitUnsupported, err, "Error: %v while parsing git-credential", err) | ||
} | ||
path := "git/" + fsutil.CleanFilename(cred.Host) + "/" + fsutil.CleanFilename(cred.Username) | ||
if !s.Store.Exists(ctx, path) { |
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.
Some comments on this would be nice. I assume you're first checking the root store and then doing a search which should find any matching entry in a mounted substore?
pkg/action/git-credential.go
Outdated
if err != nil { | ||
return ExitError(ctx, ExitUnsupported, err, "Error: %v while parsing git-credential", err) | ||
} | ||
path := "git/" + fsutil.CleanFilename(cred.Host) + "/" + fsutil.CleanFilename(cred.Username) |
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.
This will always use the root store. For me that's ok, but I bet some users will complain ;)
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.
Can't you just mount a substore to git?
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.
Yes, you can.
pkg/action/git-credential.go
Outdated
if cred.Username != "" { | ||
_ = secret.SetValue("login", cred.Username) | ||
} | ||
// TODO: Skip this step if the same secret is already in the store. How to implement this? |
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.
How can comparison to existing keys be done?
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.
Are you looking for root.Exists?
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.
No, I'm looking for a way to check if the secret that would be stored equals the secret already stored by encrypting the current secret and comparing it to the stored secret (no need to decrypt the stored secret here)
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.
This is not supported. I don't think this edge case would be enough to extend the (already pretty big) store interface. If you want to compare it the old value will need to be decrypted.
pkg/action/git-credential.go
Outdated
path := "git/" + fsutil.CleanFilename(cred.Host) + "/" + fsutil.CleanFilename(cred.Username) | ||
if !s.Store.Exists(ctx, path) { | ||
// if the looked up path is a directory with only one entry (e.g. one user per host), take the subentry instead | ||
if s.Store.IsDir(ctx, path) { |
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.
Negate and return early:
if !s.Store.IsDir(ctx, path) {
return nil
}
...
Remove the else case below.
pkg/action/git-credential.go
Outdated
return ExitError(ctx, ExitDecrypt, err, "Error: %v while listing the storage", err) | ||
} | ||
entries := sub.List(0) | ||
if len(entries) == 1 { |
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.
Negate and return early:
if len(entries) != 1 {
fmt.Fprintln(os.Stderr, "gopass error: too many entries")
}
path = "git/" + entries[0]
Not a major issue in this case, but would prefer it that way.
5bfaab5
to
2b70ca4
Compare
@veecue I'd love to see this merged. Do you plan to continue working on this PR? |
Yes, I do. However, I'm not shure if the last two items on my TODO-List are necessary at all |
I think addressing our review comments and the first three bullet points should be enough. |
@veecue That looks pretty good already. Could you rebase (or merge master) again, so we can merge this as an alpha feature? |
f6104b3
to
0b45a29
Compare
* implemented git credential caching * code style and documentation * tests and handle existing entires * added tests
See #740
TODO: