Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

FAQ: fixes to git authentication instructions #851

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,35 @@ for each repository you wish to authenticate to will allow `dep` to use an
authenticated repository.

First, configure `git` to use the credentials option for the specific repository.
Yes, the example.com.username is weird, but it's correct; the 'username' would be
the user repo you're authenticating to access, the 'myusername' is the username
you would use for the actual authentication.

For example, if you use gitlab, and you wish to access https://gitlab.example.com/example/package.git,
For example, if you use gitlab, and you wish to access `https://gitlab.example.com/example/package.git`,
then you would want to use the following configuration:

`$ git config --global credential.https://gitlab.example.com.example yourusername`
```
$ git config --global credential.https://gitlab.example.com.example yourusername
```

You also need to tell `git` what authentication provider you wish to use. You can get
a list of providers, with the following command:
In the example the hostname `gitlab.example.com.username` string seems incorrect, but
it's actually the hostname plus the name of the repo you are accessing which is `username`.
The trailing 'yourusername' is the username you would use for the actual authentication.

`$ git help -a | grep credential-
You also need to configure `git` with the authentication provider you wish to use. You can get
a list of providers, with the command:

```
$ git help -a | grep credential-
credential-cache remote-fd
credential-cache--daemon remote-ftp
credential-osxkeychain remote-ftps
credential-store remote-http`
credential-store remote-http
```

You would then choose an appropriate provider. To use the osxkeychain, then you
You would then choose an appropriate provider. For example, to use the osxkeychain, you
would use the following:

`git config --global credential.helper osxkeychain`
```
git config --global credential.helper osxkeychain
```

If you need to do this for a CI system, then you may want to use the "store" provider.
Please see the documentation on how to configure that: https://git-scm.com/docs/git-credential-store
Expand Down
8 changes: 7 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 29 additions & 11 deletions internal/gps/source_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/golang/dep/internal/gps/pkgtree"
"github.com/nightlyone/lockfile"
"github.com/pkg/errors"
"github.com/sdboyer/constext"
)
Expand Down Expand Up @@ -115,7 +116,7 @@ func (p ProjectAnalyzerInfo) String() string {
// tools; control via dependency injection is intended to be sufficient.
type SourceMgr struct {
cachedir string // path to root of cache dir
lf *os.File // handle for the sm lock file on disk
lf *lockfile.Lockfile // handle for the sm lock file on disk
suprvsr *supervisor // subsystem that supervises running calls/io
cancelAll context.CancelFunc // cancel func to kill all running work
deduceCoord *deductionCoordinator // subsystem that manages import path deduction
Expand Down Expand Up @@ -153,21 +154,38 @@ func NewSourceManager(cachedir string) (*SourceMgr, error) {
return nil, err
}

// Fix for #820
//
// Consult https://godoc.org/github.com/nightlyone/lockfile for the lockfile
// behaviour. It's magic. It deals with stale processes, and if there is
// a process keeping the lock busy, it will pass back a temporary error that
// we can spin on.

glpath := filepath.Join(cachedir, "sm.lock")
_, err = os.Stat(glpath)
if err == nil {
lockfile, err := lockfile.New(glpath)
if err != nil {
return nil, CouldNotCreateLockError{
Path: glpath,
Err: fmt.Errorf("cache lock file %s exists - another process crashed or is still running?", glpath),
Err: fmt.Errorf("unable to create lockfile %s: %s", glpath, err.Error()),
}
}

fi, err := os.OpenFile(glpath, os.O_CREATE|os.O_EXCL, 0600) // is 0600 sane for this purpose?
if err != nil {
return nil, CouldNotCreateLockError{
Path: glpath,
Err: fmt.Errorf("err on attempting to create global cache lock: %s", err),
// If it's a TemporaryError, we retry every second. Otherwise, we fail
// permanently.

err = lockfile.TryLock()
for err != nil {
if _, ok := err.(interface {
Temporary() bool
}); ok {
time.Sleep(time.Second * 1)
} else {
return nil, CouldNotCreateLockError{
Path: glpath,
Err: fmt.Errorf("unable to lock lockfile %s: %s", glpath, err.Error()),
}
}
err = lockfile.TryLock()
}

ctx, cf := context.WithCancel(context.TODO())
Expand All @@ -176,7 +194,7 @@ func NewSourceManager(cachedir string) (*SourceMgr, error) {

sm := &SourceMgr{
cachedir: cachedir,
lf: fi,
lf: &lockfile,
suprvsr: superv,
cancelAll: cf,
deduceCoord: deducer,
Expand Down Expand Up @@ -314,7 +332,7 @@ func (sm *SourceMgr) doRelease() {
sm.suprvsr.wait()

// Close the file handle for the lock file and remove it from disk
sm.lf.Close()
sm.lf.Unlock()
os.Remove(filepath.Join(sm.cachedir, "sm.lock"))

// Close the qch, if non-nil, so the signal handlers run out. This will
Expand Down
27 changes: 27 additions & 0 deletions vendor/github.com/nightlyone/lockfile/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions vendor/github.com/nightlyone/lockfile/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions vendor/github.com/nightlyone/lockfile/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions vendor/github.com/nightlyone/lockfile/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions vendor/github.com/nightlyone/lockfile/appveyor.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading