Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-quota-header-discovery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@googleworkspace/cli": patch
---

Move x-goog-user-project header from default client headers to API request builder, fixing Discovery Document fetches failing with 403 when the quota project lacks certain APIs enabled
1 change: 1 addition & 0 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ mod tests {
.unwrap();

let _home_guard = EnvVarGuard::set("HOME", tmp.path());
let _adc_guard = EnvVarGuard::remove("GOOGLE_APPLICATION_CREDENTIALS");
assert_eq!(get_quota_project(), Some("my-project-123".to_string()));
}
}
7 changes: 0 additions & 7 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ pub fn build_client() -> Result<reqwest::Client, crate::error::GwsError> {
headers.insert("x-goog-api-client", header_value);
}

// Set quota project from ADC for billing/quota attribution
if let Some(quota_project) = crate::auth::get_quota_project() {
if let Ok(header_value) = HeaderValue::from_str(&quota_project) {
headers.insert("x-goog-user-project", header_value);
}
}

reqwest::Client::builder()
.default_headers(headers)
.build()
Expand Down
5 changes: 5 additions & 0 deletions src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ async fn build_http_request(
}
}

// Set quota project from ADC for billing/quota attribution
if let Some(quota_project) = crate::auth::get_quota_project() {
request = request.header("x-goog-user-project", quota_project);
}

for (key, value) in &input.query_params {
request = request.query(&[(key, value)]);
}
Expand Down
Loading