MCPcopy Create free account
hub / github.com/cli/cli / helperRun

Function helperRun

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

Source from the content-addressed store, hash-verified

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

Callers 2

NewCmdCredentialFunction · 0.85
Test_helperRunFunction · 0.85

Calls 7

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

Tested by 1

Test_helperRunFunction · 0.68