Skip to content

Commit e623733

Browse files
committed
Deprioritize GCloudAuthorizedUser
1 parent 8ecfee5 commit e623733

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ The library supports the following methods of retrieving tokens in the listed pr
2323
1. Reading custom service account credentials from the path pointed to by the
2424
`GOOGLE_APPLICATION_CREDENTIALS` environment variable. Alternatively, custom service
2525
account credentials can be read from a JSON file or string.
26-
2. Retrieving a token from the `gcloud` CLI tool, if it is available on the `PATH`.
26+
2. Look for credentials in `.config/gcloud/application_default_credentials.json`;
27+
if found, use these credentials to request refresh tokens. This file can be created
28+
by invoking `gcloud auth application-default login`.
2729
3. Use the default service account by retrieving a token from the metadata server.
28-
4. Look for credentials in `.config/gcloud/application_default_credentials.json`;
29-
if found, use these credentials to request refresh tokens.
30+
4. Retrieving a token from the `gcloud` CLI tool, if it is available on the `PATH`.
3031

3132
For more detailed information and examples, see the [docs][docs-url].
3233

src/authentication_manager.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ impl AuthenticationManager {
3434
///
3535
/// 1. Check if the `GOOGLE_APPLICATION_CREDENTIALS` environment variable if set;
3636
/// if so, use a custom service account as the token source.
37-
/// 2. Check if the `gcloud` tool is available on the `PATH`; if so, use the
38-
/// `gcloud auth print-access-token` command as the token source.
37+
/// 2. Look for credentials in `.config/gcloud/application_default_credentials.json`;
38+
/// if found, use these credentials to request refresh tokens.
3939
/// 3. Send a HTTP request to the internal metadata server to retrieve a token;
4040
/// if it succeeds, use the default service account as the token source.
41-
/// 4. Look for credentials in `.config/gcloud/application_default_credentials.json`;
42-
/// if found, use these credentials to request refresh tokens.
41+
/// 4. Check if the `gcloud` tool is available on the `PATH`; if so, use the
42+
/// `gcloud auth print-access-token` command as the token source.
4343
#[tracing::instrument]
4444
pub async fn new() -> Result<Self, Error> {
4545
tracing::debug!("Initializing gcp_auth");
@@ -48,9 +48,9 @@ impl AuthenticationManager {
4848
}
4949

5050
let client = types::client();
51-
let gcloud_error = match GCloudAuthorizedUser::new().await {
51+
let default_user_error = match DefaultAuthorizedUser::new(&client).await {
5252
Ok(service_account) => {
53-
tracing::debug!("Using GCloudAuthorizedUser");
53+
tracing::debug!("Using DefaultAuthorizedUser");
5454
return Ok(Self::build(client, service_account));
5555
}
5656
Err(e) => e,
@@ -64,9 +64,9 @@ impl AuthenticationManager {
6464
Err(e) => e,
6565
};
6666

67-
let default_user_error = match DefaultAuthorizedUser::new(&client).await {
67+
let gcloud_error = match GCloudAuthorizedUser::new().await {
6868
Ok(service_account) => {
69-
tracing::debug!("Using DefaultAuthorizedUser");
69+
tracing::debug!("Using GCloudAuthorizedUser");
7070
return Ok(Self::build(client, service_account));
7171
}
7272
Err(e) => e,

src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
//! 1. Reading custom service account credentials from the path pointed to by the
1111
//! `GOOGLE_APPLICATION_CREDENTIALS` environment variable. Alternatively, custom service
1212
//! account credentials can be read from a JSON file or string.
13-
//! 2. Retrieving a token from the `gcloud` CLI tool, if it is available on the `PATH`.
13+
//! 2. Look for credentials in `.config/gcloud/application_default_credentials.json`;
14+
//! if found, use these credentials to request refresh tokens. This file can be created
15+
//! by invoking `gcloud auth application-default login`.
1416
//! 3. Use the default service account by retrieving a token from the metadata server.
15-
//! 4. Look for credentials in `.config/gcloud/application_default_credentials.json`;
16-
//! if found, use these credentials to request refresh tokens.
17+
//! 4. Retrieving a token from the `gcloud` CLI tool, if it is available on the `PATH`.
1718
//!
1819
//! For more details, see [`AuthenticationManager::new()`].
1920
//!

0 commit comments

Comments
 (0)