GetCurrentLogin returns the login of the user the token belongs to. The token is passed explicitly because this runs before the token is stored in config, so the transport has nothing to attach. The transport only sets Authorization when it is absent, so the header set here wins.
(httpClient *http.Client, hostname, authToken string)
| 252 | // the transport has nothing to attach. The transport only sets Authorization when it is |
| 253 | // absent, so the header set here wins. |
| 254 | func GetCurrentLogin(httpClient *http.Client, hostname, authToken string) (string, error) { |
| 255 | var result struct{ Viewer struct{ Login string } } |
| 256 | |
| 257 | // TODO(api-client-rollout) |
| 258 | // This line of code is part of a mechanical roll out of the api client. |
| 259 | // As a follow up, consider whether the api client can be injected to this call site, rather than constructed |
| 260 | err := api.NewClientFromHTTP(httpClient).GraphQL(hostname, `query UserCurrent{viewer{login}}`, nil, &result, |
| 261 | api.WithHeader("Authorization", "token "+authToken)) |
| 262 | if err != nil { |
| 263 | return "", err |
| 264 | } |
| 265 | return result.Viewer.Login, nil |
| 266 | } |
no test coverage detected