MCPcopy
hub / github.com/cli/cli / getToken

Function getToken

internal/config/migration/multi_account.go:139–160  ·  view source on GitHub ↗
(c *config.Config, hostname string)

Source from the content-addressed store, hash-verified

137}
138
139func getToken(c *config.Config, hostname string) (tokenSource, error) {
140 if token, _ := c.Get(append(hostsKey, hostname, "oauth_token")); token != "" {
141 return tokenSource{token: token, inKeyring: false}, nil
142 }
143 token, err := keyring.Get(keyringServiceName(hostname), "")
144
145 // If we have an error and it's not relating to there being no token
146 // then we'll return the error cause that's really unexpected.
147 if err != nil && !errors.Is(err, keyring.ErrNotFound) {
148 return tokenSource{}, err
149 }
150
151 // Otherwise we'll return a sentinel error
152 if err != nil || token == "" {
153 return tokenSource{}, noTokenError
154 }
155
156 return tokenSource{
157 token: token,
158 inKeyring: true,
159 }, nil
160}
161
162func getUsername(c *config.Config, hostname, token string, transport http.RoundTripper) (string, error) {
163 username, _ := c.Get(append(hostsKey, hostname, "user"))

Callers 1

DoMethod · 0.85

Calls 3

GetFunction · 0.92
keyringServiceNameFunction · 0.70
GetMethod · 0.65

Tested by

no test coverage detected