Project ID is overwritten with service account's project id even if another project id configured.
Closed this issue · 1 comments
Thank you for your continuous work.
I found the issue the case when the client accesses to another project.
Even if I set another project id when I initialize ClientConfig
with another project id, it will be overwritten with service account's (TokenSource) project id.
google-cloud-rust/pubsub/src/client.rs
Lines 54 to 61 in 7a46db4
// this doesn't work as I expected.
let client_config = ClientConfig {
project_id: Some("another-project-id".to_string()),
..Default::default()
};
So as work around, I write like the following now:
let mut client_config = ClientConfig::default().with_auth().await.unwrap();
client_config.project_id = Some("another-project-id".to_string());
I think the client should use the configure project id instead of TokenSource project id, if it is configured like the following:
pub async fn with_auth(mut self) -> Result<Self, google_cloud_auth::error::Error> {
if let Environment::GoogleCloud(_) = self.environment {
let ts = google_cloud_auth::token::DefaultTokenSourceProvider::new(Self::auth_config()).await?;
self.project_id = match self.project_id {
Some(project_id) => Some(project_id),
None => ts.project_id.clone()
},
self.environment = Environment::GoogleCloud(Box::new(ts))
}
Ok(self)
}
But the above change may have big impact to the project that sets another project id to the client.
Do you think it is better to allow for such an effect and change it as described above, or to implement a different way to set a different project id?
Thank you
Thanks for the suggestion, I think it is intuitive to use the project_id
if it is specified in ClientConfig
.
As for the impact of the modification, if the project_id
of TokenSource
is used when the project_id
is set to None
in ClientConfig
, I think there will be almost no cases where the modification will have an impact.
Therefore, there is no problem with the with_auth modification you mentioned.
pub async fn with_auth(mut self) -> Result<Self, google_cloud_auth::error::Error> {
if let Environment::GoogleCloud(_) = self.environment {
let ts = google_cloud_auth::token::DefaultTokenSourceProvider::new(Self::auth_config()).await?;
self.project_id = self.project_id.or(ts.project_id.clone());
self.environment = Environment::GoogleCloud(Box::new(ts))
}
Ok(self)
}