-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Add async call to access secret #21603
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
Add async call to access secret #21603
Conversation
Howdy and thanks for contributing to our repo. The Cloudflare team reviews new, external PRs within two (2) weeks. If it's been two weeks or longer without any movement, please tag the PR Assignees in a comment. We review internal PRs within 1 week. If it's something urgent or has been sitting without a comment, start a thread in the Developer Docs space internally. PR Change SummaryAdded asynchronous functionality to access secrets in the Workers integration documentation.
Modified Files
How can I customize these reviews?Check out the Hyperlint AI Reviewer docs for more information on how to customize the review. If you just want to ignore it on this PR, you can add the Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add |
Preview URL: https://ac13faa1.preview.developers.cloudflare.com Files with changes (up to 15) |
@@ -140,7 +140,8 @@ import { env } from "cloudflare:workers"; | |||
import ApiClient from "example-api-client"; | |||
|
|||
// MY_SECRETS_STORE_SECRET is now usable in top-level scope | |||
let apiClient = ApiClient.new({ apiKey: env.MY_SECRETS_STORE_SECRET }); | |||
const APIkey = await env.MY_SECRETS_STORE_SECRET.get() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work, because it's doing async IO in the top level scope. The secrets need to be accessed from within a request handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work, because it's doing an await
in the top level scope
// you can use apiClient configured before any request is handled | ||
}, | ||
}; | ||
``` | ||
|
||
### Pass `env` as an argument to `fetch` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'call get() on the binding name/variable`
* Add async call to access secret * Remove extra env. from fixed auth bearer * Replace default store by first store * Add async call to first code example and fix env.<binding name> * Remove top level scope example * Further adjustments * More consistent naming: binding vs secret_name examples * Opt for binding variable in h3
Summary
Screenshots (optional)
Documentation checklist