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

Function getToken

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

Source from the content-addressed store, hash-verified

145}
146
147func getToken(c *config.Config, hostname string) (tokenSource, error) {
148 if token, _ := c.Get(append(hostsKey, hostname, "oauth_token")); token != "" {
149 return tokenSource{token: token, inKeyring: false}, nil
150 }
151 token, err := keyring.Get(keyringServiceName(hostname), "")
152
153 // If we have an error and it's not relating to there being no token
154 // then we'll return the error cause that's really unexpected.
155 if err != nil && !errors.Is(err, keyring.ErrNotFound) {
156 return tokenSource{}, err
157 }
158
159 // Otherwise we'll return a sentinel error
160 if err != nil || token == "" {
161 return tokenSource{}, noTokenError
162 }
163
164 return tokenSource{
165 token: token,
166 inKeyring: true,
167 }, nil
168}
169
170func getUsername(c *config.Config, hostname, token string, transport http.RoundTripper) (string, error) {
171 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