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

polish: validate payload for kv:bulk put on client side #1024

Merged
merged 1 commit into from
May 16, 2022

Conversation

threepointone
Copy link
Contributor

This adds client side validation for the paylod for kv:bulk put, importantly ensuring we're uploading only string key/value pairs (as well as validation for the other fields).

Fixes #571

@changeset-bot
Copy link

changeset-bot bot commented May 16, 2022

🦋 Changeset detected

Latest commit: 575cf21

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented May 16, 2022

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/2333441982/npm-package-wrangler-1024

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/1024/npm-package-wrangler-1024

Or you can use npx with this latest build directly:

npx https://prerelease-registry.developers.workers.dev/runs/2333441982/npm-package-wrangler-1024 dev path/to/script.js

@threepointone threepointone requested a review from caass May 16, 2022 12:40
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small slip with the metadata validation. If we are going to add validation for these optional properties, then we should also add tests.

typeof keyValue.expiration_ttl === "number"
) ||
!(keyValue.base64 === undefined || typeof keyValue.base64 === "boolean") ||
!(keyValue.metadata === undefined || typeof keyValue.base64 === "object")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
!(keyValue.metadata === undefined || typeof keyValue.base64 === "object")
!(keyValue.metadata === undefined || typeof keyValue.metadata === "object")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed these! Adding now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@@ -2334,13 +2334,7 @@ export async function main(argv: string[]): Promise<void> {
const warnings: string[] = [];
for (let i = 0; i < content.length; i++) {
const keyValue = content[i];
if (typeof keyValue !== "object") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to add this check into the validation helper function! 👍🏻

Copy link
Contributor

@JacobMGEvans JacobMGEvans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concise straightforward improvement and I rather like the validation helper refactor.

This adds client side validation for the paylod for `kv:bulk put`, importantly ensuring we're uploading only string key/value pairs (as well as validation for the other fields).

Fixes #571
@threepointone threepointone force-pushed the validate-bulk-upload branch from 186a7a7 to 575cf21 Compare May 16, 2022 17:02
@threepointone
Copy link
Contributor Author

Thanks for the review! Rebasing on top of the windows ci fix also passed checks. I'll wait for @petebacondarwin to stamp this and land it.

@threepointone threepointone merged commit 110f340 into main May 16, 2022
@threepointone threepointone deleted the validate-bulk-upload branch May 16, 2022 18:50
@github-actions github-actions bot mentioned this pull request May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kv:bulk only accepts string values
3 participants