2016-05-13 16:38:06 +00:00
|
|
|
package config
|
2015-11-18 17:23:36 +00:00
|
|
|
|
2015-11-18 17:25:34 +00:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2018-05-25 18:55:39 +00:00
|
|
|
"github.com/git-lfs/go-netrc/netrc"
|
2015-11-18 17:25:34 +00:00
|
|
|
)
|
|
|
|
|
2015-11-18 17:23:36 +00:00
|
|
|
type netrcfinder interface {
|
|
|
|
FindMachine(string) *netrc.Machine
|
|
|
|
}
|
|
|
|
|
|
|
|
type noNetrc struct{}
|
|
|
|
|
|
|
|
func (n *noNetrc) FindMachine(host string) *netrc.Machine {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Configuration) parseNetrc() (netrcfinder, error) {
|
2016-08-10 20:23:03 +00:00
|
|
|
home, _ := c.Os.Get("HOME")
|
2015-11-18 17:23:36 +00:00
|
|
|
if len(home) == 0 {
|
|
|
|
return &noNetrc{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
nrcfilename := filepath.Join(home, netrcBasename)
|
|
|
|
if _, err := os.Stat(nrcfilename); err != nil {
|
|
|
|
return &noNetrc{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return netrc.ParseFile(nrcfilename)
|
|
|
|
}
|