Exemplo n.º 1
0
func accessTokenFromNetrc() string {
	machine, err := netrc.FindMachine(netrcPath(), "api.github.com")
	if err != nil {
		panic(err)
	}
	return machine.Password
}
Exemplo n.º 2
0
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
}
Exemplo n.º 3
0
Arquivo: build.go Projeto: kr/hk-1
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
}
Exemplo n.º 4
0
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
}