commit e82076b19f23f436c28f921ebbea74e2703ea0cc from: Oliver Lowe date: Sun Nov 03 22:21:57 2024 UTC github: support only token file store Instead of both netrc and token files. One less thing to worry about. commit - 4c6af851c2b236144371f69a88eaa5d73e9a72c5 commit + e82076b19f23f436c28f921ebbea74e2703ea0cc blob - 0ca71a798fecc32677228856922d4abd816bf286 blob + 70452a20cf35c2db21525e652e82e1cc12d9d1dc --- client.go +++ client.go @@ -28,24 +28,6 @@ type Client struct { token string } -// Dial returns a Client authenticating as user. -// Authentication credentials are loaded from $HOME/.netrc -// using the 'api.github.com' entry, which should contain a -// GitHub personal access token. -// If user is the empty string, Dial uses the first line in .netrc -// listed for api.github.com. -// -// For example, $HOME/.netrc might contain: -// -// machine api.github.com login ken password ghp_123456789abcdef123456789abcdef12345 -func Dial(user string) (*Client, error) { - _, passwd, err := netrcAuth("api.github.com", user) - if err != nil { - return nil, err - } - return &Client{token: passwd}, nil -} - // NewClient returns a new client using the given GitHub personal access token (of the form "ghp_...."). func NewClient(token string) *Client { return &Client{token: token} blob - a8755c0aaae7fd261e9124ee99e7f0f9cb1ac0e7 (mode 644) blob + /dev/null --- netrc.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2020 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package github - -import ( - "fmt" - "io/ioutil" - "os" - "path/filepath" - "runtime" - "strings" -) - -func netrcAuth(host, user string) (string, string, error) { - netrc := ".netrc" - if runtime.GOOS == "windows" { - netrc = "_netrc" - } - - homeDir, err := os.UserHomeDir() - if err != nil { - return "", "", err - } - data, _ := ioutil.ReadFile(filepath.Join(homeDir, netrc)) - for _, line := range strings.Split(string(data), "\n") { - if i := strings.Index(line, "#"); i >= 0 { - line = line[:i] - } - f := strings.Fields(line) - if len(f) >= 6 && f[0] == "machine" && f[1] == host && f[2] == "login" && f[4] == "password" && (user == "" || f[3] == user) { - return f[3], f[5], nil - } - } - return "", "", fmt.Errorf("cannot find netrc entry for %s", host) -}