Skip to content

Conversation

rossmeier
Copy link
Contributor

@rossmeier rossmeier commented Apr 9, 2018

See #740
TODO:

  • Write some kind of tests?
  • Do not overwrite existing values with the same value
  • Properly resolve autosync hangup
  • Use a better and more configurable way to create storage paths
  • Add the possibility to use multiple accounts on one host

@rossmeier rossmeier force-pushed the feature/git-credential branch 4 times, most recently from 596d546 to bdb7db1 Compare April 9, 2018 20:11
@codecov
Copy link

codecov bot commented Apr 9, 2018

Codecov Report

Merging #743 into master will increase coverage by 0.13%.
The diff coverage is 73.53%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
commands.go 91.79% <100%> (+0.38%) ⬆️
pkg/action/git-credential.go 70.97% <70.97%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4734dd4...0b45a29. Read the comment docs.

@dominikschulz dominikschulz self-requested a review April 10, 2018 07:13
Copy link
Member

@dominikschulz dominikschulz left a 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.

"os"
"strings"

"github.com/justwatchcom/gopass/pkg/store/sub"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing gofmt?

Copy link
Contributor Author

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...

Password string
}

func (c *gitCredentials) WriteTo(w io.Writer) (int64, error) {
Copy link
Member

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

c := &gitCredentials{}
for {
key, err := rd.ReadString('=')
if err == io.EOF {
Copy link
Member

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('=')
Copy link
Member

@dominikschulz dominikschulz Apr 10, 2018

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.

Copy link
Contributor Author

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

Copy link
Member

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.

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) {
Copy link
Member

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?

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)
Copy link
Member

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 ;)

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you can.

@dominikschulz dominikschulz added the feature Enhancements and new features label Apr 10, 2018
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?
Copy link
Contributor Author

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?

Copy link
Member

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?

Copy link
Contributor Author

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)

Copy link
Member

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.

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) {
Copy link
Contributor

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.

return ExitError(ctx, ExitDecrypt, err, "Error: %v while listing the storage", err)
}
entries := sub.List(0)
if len(entries) == 1 {
Copy link
Contributor

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.

@rossmeier rossmeier force-pushed the feature/git-credential branch 2 times, most recently from 5bfaab5 to 2b70ca4 Compare May 8, 2018 09:16
@dominikschulz
Copy link
Member

@veecue I'd love to see this merged. Do you plan to continue working on this PR?

@rossmeier
Copy link
Contributor Author

Yes, I do. However, I'm not shure if the last two items on my TODO-List are necessary at all

@dominikschulz
Copy link
Member

I think addressing our review comments and the first three bullet points should be enough.

@dominikschulz
Copy link
Member

@veecue That looks pretty good already. Could you rebase (or merge master) again, so we can merge this as an alpha feature?
Thanks a lot!

@rossmeier rossmeier force-pushed the feature/git-credential branch from f6104b3 to 0b45a29 Compare May 23, 2018 11:58
@dominikschulz dominikschulz dismissed metalmatze’s stale review May 23, 2018 12:11

updated codebase

@dominikschulz dominikschulz merged commit a3d6081 into gopasspw:master May 23, 2018
kpitt pushed a commit to kpitt/gopass that referenced this pull request Jul 21, 2022
* implemented git credential caching

* code style and documentation

* tests and handle existing entires

* added tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Enhancements and new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants