googleapis / googleapis/google-cloud-rust

Add logging to create_access_token_credential

Open
#991 1 comment 0 reactions 0 assignees View on GitHub
auth priority: p3 type: feature request
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.