MCPcopy
hub / github.com/cli/cli / helperRun

Function helperRun

pkg/cmd/auth/gitcredential/helper.go:58–144  ·  view source on GitHub ↗
(opts *CredentialOptions)

Source from the content-addressed store, hash-verified

56}
57
58func helperRun(opts *CredentialOptions) error {
59 if opts.Operation == "store" {
60 // We pretend to implement the "store" operation, but do nothing since we already have a cached token.
61 return nil
62 }
63
64 if opts.Operation == "erase" {
65 // We pretend to implement the "erase" operation, but do nothing since we don't want git to cause user to be logged out.
66 return nil
67 }
68
69 if opts.Operation != "get" {
70 return fmt.Errorf("gh auth git-credential: %q operation not supported", opts.Operation)
71 }
72
73 wants := map[string]string{}
74
75 s := bufio.NewScanner(opts.IO.In)
76 for s.Scan() {
77 line := s.Text()
78 if line == "" {
79 break
80 }
81 parts := strings.SplitN(line, "=", 2)
82 if len(parts) < 2 {
83 continue
84 }
85 key, value := parts[0], parts[1]
86 if key == "url" {
87 u, err := url.Parse(value)
88 if err != nil {
89 return err
90 }
91 wants["protocol"] = u.Scheme
92 wants["host"] = u.Host
93 wants["path"] = u.Path
94 wants["username"] = u.User.Username()
95 wants["password"], _ = u.User.Password()
96 } else {
97 wants[key] = value
98 }
99 }
100 if err := s.Err(); err != nil {
101 return err
102 }
103
104 if wants["protocol"] != "https" {
105 return cmdutil.SilentError
106 }
107
108 cfg, err := opts.Config()
109 if err != nil {
110 return err
111 }
112
113 lookupHost := wants["host"]
114 var gotUser string
115 gotToken, source := cfg.ActiveToken(lookupHost)

Callers 2

NewCmdCredentialFunction · 0.85
Test_helperRunFunction · 0.85

Calls 6

ErrMethod · 0.80
ErrorfMethod · 0.65
PasswordMethod · 0.65
ConfigMethod · 0.65
ActiveTokenMethod · 0.65
ActiveUserMethod · 0.65

Tested by 1

Test_helperRunFunction · 0.68