Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] in sample: taskqueues-backup-images #1143

Open
CoocooFroggy opened this issue Jun 21, 2024 · 1 comment
Open

[BUG] in sample: taskqueues-backup-images #1143

CoocooFroggy opened this issue Jun 21, 2024 · 1 comment

Comments

@CoocooFroggy
Copy link

Which sample has a bug?

async function getFunctionUrl(name, location="us-central1") {
if (!auth) {
auth = new GoogleAuth({
scopes: "https://www.googleapis.com/auth/cloud-platform",
});
}
const projectId = await auth.getProjectId();
const url = "https://cloudfunctions.googleapis.com/v2beta/" +
`projects/${projectId}/locations/${location}/functions/${name}`;
const client = await auth.getClient();
const res = await client.request({url});
const uri = res.data?.serviceConfig?.uri;
if (!uri) {
throw new Error(`Unable to retreive uri for function at ${url}`);
}
return uri;
}

How to reproduce the issue

Used getFunctionUrl exactly as shown.

Steps to set up and reproduce

Attempt to queue a function using the code shown. EG:

const queue = getFunctions().taskQueue("reminderEmail");
const targetUrl = await getFunctionUrl("reminderEmail");

queue.enqueue({bookingRequestId: event.params.docId}, {
  scheduleTime: new Date(),
  uri: targetUrl,
}).then(() => {
  console.log(`Queued reminder email for ${date}.`);
});

Debug output

Status code 7 (PERMISSION_DENIED)
Reason to retry PERMISSION_DENIED(7): HTTP status code 403
SCR-20240621-nrfl

Expected behavior

The function runs successfully. The documentation states,

Due to the way Cloud Tasks creates authentication tokens to authenticate requests to the underlying task queue functions, you must specify the Cloud Run URL of the function when enqueuing tasks. We recommend that you programmatically retrieve the URL for your function as demonstrated below...

However, the uri itself does not seem sufficient to authenticate the cloud function.

Actual behavior

The function is missing the necessary authentication.

@CoocooFroggy
Copy link
Author

Seems related to #1105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant