googleapis / googleapis/google-cloud-rust
Add logging to create_access_token_credential
- Dominant language
- Rust
- Stars
- 955
- Forks
- 144
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 279
Description
This is a small feature request. Feel free to close if not important/already planned/too hard/etc.
**Is your feature request related to a problem? Please describe.**
When auth doesn't work, error message is not always helpful: some error from HTTP service.
```
called `Result::unwrap()` on an `Err` value: CredentialError { is_retryable: false, source: "Failed to fetch token. {\n \"error\": \"invalid_grant\",\n \"error_description\": \"reauth related error (invalid_rapt)\",\n \"error_uri\": \"https://support.google.com/a/answer/9368756\",\n \"error_subtype\": \"invalid_rapt\"\n}" }thread 'tests::test2' panicked at xxx/src/lib.rs:9:55:
```
Turns out my local gcloud login expired. But at the time I was not even sure, that it actually used auth provided by gcloud command (file `~/.config/gcloud/application_default_credentials.json`).
**Describe the solution you'd like**
Add debug statements how authentication was obtained, for example:
```
logging::debug!("ADC path found using well known path: {}", adc_path);
...
logging::debug!("Calling URL https://... to obtain token ...")
```
Ideally, produce error message not just with final http response, but also with information
- why this URL was called
- suggestion to re-run ~~`gcloud auth login`~~ `gcloud auth application-default login` if something is expired and needs renewing
(I am a new user of GCP, so don't know well how it works.)
**Describe alternatives you've considered**
Invoke `gcloud auth application-default print-access-token` command directly, or call `https://metadata.google.internal/...` directly, as it is easier to debug.
Contributor guide
Assessment
This issue has not been assessed yet.