commit e82076b19f23f436c28f921ebbea74e2703ea0cc
parent 4c6af851c2b236144371f69a88eaa5d73e9a72c5
Author: Oliver Lowe <o@olowe.co>
Date: Tue, 30 Jul 2024 12:12:50 +1000
github: support only token file store
Instead of both netrc and token files. One less thing to worry about.
Diffstat:
| M | client.go | | | 18 | ------------------ |
| D | netrc.go | | | 37 | ------------------------------------- |
2 files changed, 0 insertions(+), 55 deletions(-)
diff --git a/client.go b/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}
diff --git a/netrc.go b/netrc.go
@@ -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)
-}