func accessTokenFromNetrc() string { machine, err := netrc.FindMachine(netrcPath(), "api.github.com") if err != nil { panic(err) } return machine.Password }
func getLoginAndPasswordFromNetrc(serviceEndpoint string) (username, password string) { username = "" password = "" // Get hostname from BaseURL u, err := url.Parse(serviceEndpoint) if err != nil { return } machine := u.Host // Get user's home directory to find ~/.netrc user, err := user.Current() if err != nil { return } netrcfile := path.Join(user.HomeDir, ".netrc") // Find entry in .netrc for the given machine m, err := netrc.FindMachine(netrcfile, machine) if err != nil { return } username = m.Login password = m.Password return }
func getCreds(host string) (user, pass string) { m, err := netrc.FindMachine(netrcPath, host) if err != nil { log.Fatalf("netrc error (%s): %v", host, err) } return m.Login, m.Password }
func getCreds(u string) (user, pass string) { apiURL, err := url.Parse(u) if err != nil { log.Fatalf("invalid API URL: %s", err) } if apiURL.User != nil { pw, _ := apiURL.User.Password() return apiURL.User.Username(), pw } m, err := netrc.FindMachine(netrcPath(), apiURL.Host) if err != nil { log.Fatalf("netrc error (%s): %v", apiURL.Host, err) } return m.Login, m.Password }