Skip to content

Commit f383faa

Browse files
taeoldjoehan
andauthored
fix: explicitly set quota user in Service Usage API calls. (#8768)
* fix: explicitly set quota user in Service Usage API calls. * fix: support overriding quotta project on polling requests --------- Co-authored-by: joehan <joehanley@google.com>
1 parent 88cfd8e commit f383faa

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/gcp/serviceusage.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export async function generateServiceIdentity(
3434
try {
3535
const res = await apiClient.post<unknown, unknown>(
3636
`projects/${projectNumber}/services/${service}:generateServiceIdentity`,
37+
/* body=*/ {},
38+
{ headers: { "x-goog-quota-user": `projects/${projectNumber}` } },
3739
);
3840
return res.body as LongRunningOperation<unknown>;
3941
} catch (err: unknown) {
@@ -65,5 +67,6 @@ export async function generateServiceIdentityAndPoll(
6567
await poller.pollOperation<void>({
6668
...serviceUsagePollerOptions,
6769
operationResourceName: op.name,
70+
headers: { "x-goog-quota-user": `projects/${projectNumber}` },
6871
});
6972
}

src/operation-poller.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface OperationPollerOptions {
2323
masterTimeout?: number;
2424
onPoll?: (operation: OperationResult<any>) => any;
2525
doneFn?: (op: any) => boolean;
26+
headers?: Record<string, string>;
2627
}
2728

2829
const DEFAULT_INITIAL_BACKOFF_DELAY_MILLIS = 250;
@@ -80,7 +81,9 @@ export class OperationPoller<T> {
8081
return async () => {
8182
let res;
8283
try {
83-
res = await apiClient.get<OperationResult<T>>(options.operationResourceName);
84+
res = await apiClient.get<OperationResult<T>>(options.operationResourceName, {
85+
headers: options.headers,
86+
});
8487
} catch (err: any) {
8588
// Responses with 500 or 503 status code are treated as retriable errors.
8689
if (err.status === 500 || err.status === 503) {

0 commit comments

Comments
 (0)