Build the api client for this invocation, resolving the auth token from the most specific source available. This is the single source of truth for token resolution; the result lives on the returned client and every downstream consumer (GraphQL queries, upload `Authorization` header, executor env injection) reads it from there. Priority (most specific first): 1. `--token` / `CODSPEED_TOKEN`
(cli: &Cli, config: &CodSpeedConfig)
| 307 | /// 2. `--oauth-token` / `CODSPEED_OAUTH_TOKEN` and the persisted CLI |
| 308 | /// token from the selected profile. |
| 309 | fn build_api_client(cli: &Cli, config: &CodSpeedConfig) -> CodSpeedAPIClient { |
| 310 | let run_token = match &cli.command { |
| 311 | Commands::Run(args) => args.shared.token.clone(), |
| 312 | Commands::Exec(args) => args.shared.token.clone(), |
| 313 | _ => None, |
| 314 | }; |
| 315 | let authentication = match run_token { |
| 316 | Some(token) => Authentication::RunToken(token), |
| 317 | None => config |
| 318 | .auth |
| 319 | .token |
| 320 | .clone() |
| 321 | .map_or(Authentication::Tokenless, Authentication::CliLogin), |
| 322 | }; |
| 323 | CodSpeedAPIClient::new(authentication, config.api_url.clone()) |
| 324 | } |