Skip to content

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

Merged
merged 9 commits into from
Apr 10, 2025

Conversation

RebeccaTamachiro
Copy link
Contributor

Summary

Screenshots (optional)

Documentation checklist

  • The documentation style guide has been adhered to.
  • If a larger change - such as adding a new page- an issue has been opened in relation to any incorrect or out of date information that this PR fixes.
  • Files which have changed name or location have been allocated redirects.

@RebeccaTamachiro RebeccaTamachiro requested a review from a team as a code owner April 10, 2025 14:46
Copy link
Contributor

hyperlint-ai bot commented Apr 10, 2025

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 Summary

Added asynchronous functionality to access secrets in the Workers integration documentation.

  • Implemented async call to retrieve secrets using the new environment variable method.
  • Updated the example code to reflect the new secret access pattern.

Modified Files

  • src/content/docs/secrets-store/integrations/workers.mdx

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 hyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

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 hyperlint-ignore to the PR to ignore the link check for this PR.

@github-actions github-actions bot added size/s and removed size/xs labels Apr 10, 2025
@@ -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()
Copy link
Contributor

@penalosa penalosa Apr 10, 2025

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.

Copy link
Contributor

@penalosa penalosa left a 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`

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`

@RebeccaTamachiro RebeccaTamachiro enabled auto-merge (squash) April 10, 2025 15:58
@RebeccaTamachiro RebeccaTamachiro merged commit 371bbeb into production Apr 10, 2025
11 checks passed
@RebeccaTamachiro RebeccaTamachiro deleted the rebecca/secrets-store-fix-code-example branch April 10, 2025 16:28
RebeccaTamachiro added a commit that referenced this pull request Apr 21, 2025
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants