func LoadNetRc() (nrc *NetRc, err error) { onrc, err := netrc.ParseFile(netRcPath()) if err != nil { return nil, err } return &NetRc{*onrc}, nil }
func loadNetrc() { if nrc == nil { var err error if nrc, err = netrc.ParseFile(netrcPath()); err != nil { if os.IsNotExist(err) { return } printError("loading netrc: " + err.Error()) } } }
func LoadNetRc() (nrc *NetRc, err error) { onrc, err := netrc.ParseFile(netRcPath()) if err != nil { if os.IsNotExist(err) { return &NetRc{}, nil } return nil, err } return &NetRc{*onrc}, nil }
func (c *Configuration) parseNetrc() (netrcfinder, error) { home, _ := c.Os.Get("HOME") 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) }
// addAuthFromNetrc adds auth information to the URL from the user's // netrc file if it can be found. This will only add the auth info // if the URL doesn't already have auth info specified and the // the username is blank. func addAuthFromNetrc(u *url.URL) error { // If the URL already has auth information, do nothing if u.User != nil && u.User.Username() != "" { return nil } // Get the netrc file path path := os.Getenv("NETRC") if path == "" { filename := ".netrc" if runtime.GOOS == "windows" { filename = "_netrc" } var err error path, err = homedir.Expand("~/" + filename) if err != nil { return err } } // If the file is not a file, then do nothing if fi, err := os.Stat(path); err != nil { // File doesn't exist, do nothing if os.IsNotExist(err) { return nil } // Some other error! return err } else if fi.IsDir() { // File is directory, ignore return nil } // Load up the netrc file net, err := netrc.ParseFile(path) if err != nil { return fmt.Errorf("Error parsing netrc file at %q: %s", path, err) } machine := net.FindMachine(u.Host) if machine == nil { // Machine not found, no problem return nil } // Set the user info u.User = url.UserPassword(machine.Login, machine.Password) return nil }
func getUpdates(g Gom) (*updates, error) { if !strings.HasPrefix(g.name, "github.com/") { return nil, errProviderNotSupported } usr, err := user.Current() if err != nil { return nil, err } dir := usr.HomeDir machines, err := netrc.ParseFile(fmt.Sprintf("%s/.netrc", dir)) if err != nil { return nil, err } token := "" m := machines.FindMachine("github.com") if m == nil { fmt.Printf("No github credential set") } else { token = m.Login } projectName := strings.Replace(g.name, "github.com/", "", -1) tab := strings.Split(projectName, "/") packageName := strings.Join(tab[0:2], "/") res, err := http.Get(fmt.Sprintf("https://api.github.com/repos/%s/commits?access_token=%s", packageName, token)) if err != nil { return nil, err } body, err := ioutil.ReadAll(res.Body) if err != nil { return nil, err } commits := []*Commit{} if err := json.Unmarshal(body, &commits); err != nil { fmt.Printf("Error with unmarshal: %s: %s\n", err.Error(), string(body)) return nil, err } return &updates{ latestVersion: commits[0].Sha, }, nil }
// Error codes returned by auth failures var ( ErrEmptyToken = errors.New("auth: You must be logged in. Please use `gemnasium auth login` first, or pass your api token with --token or GEMNASIUM_TOKEN") ) func netrcPath() string { if s := os.Getenv("NETRC_PATH"); s != "" { return s } return filepath.Join(os.Getenv("HOME"), netrcFilename) } var loadNetrc = func() *netrc.Netrc { nrc, err := netrc.ParseFile(netrcPath()) if err != nil { if os.IsNotExist(err) { nrc = &netrc.Netrc{} } else { utils.PrintFatal("loading netrc: " + err.Error()) } } return nrc } func saveCreds(host, user, pass string) error { nrc := loadNetrc() m := nrc.FindMachine(host) if m == nil || m.IsDefault() { m = nrc.NewMachine(host, user, pass, "")