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

Support Resource Bindings in UploadWorker #293

Closed
wants to merge 1 commit into from
Closed

Support Resource Bindings in UploadWorker #293

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Apr 9, 2019

This PR makes it possible to bind Worker scripts to KV namespaces when uploading scripts via the API.

Types of changes

What sort of change does your code introduce/modify?

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@@ -167,15 +182,41 @@ func (api *API) ListWorkerScripts() (WorkerListResponse, error) {
// UploadWorker push raw script content for your worker
//
// API reference: https://api.cloudflare.com/#worker-script-upload-worker
func (api *API) UploadWorker(requestParams *WorkerRequestParams, data string) (WorkerScriptResponse, error) {
func (api *API) UploadWorker(requestParams *WorkerRequestParams, data string, metadataParams *WorkerMetadataParams) (WorkerScriptResponse, error) {
Copy link

Choose a reason for hiding this comment

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

there is no requirement to upload metadata and changing the public facing interface would require people to update their code to pass in a second nil parameter.

What do you think about updating this PR to keep this function as is and adding a new UploadWorkerWithResourceBindings function to so we don't change API?

return api.doUploadWorker(uri, data)
}

// UploadNamedWorker push raw script content for your worker
Copy link

Choose a reason for hiding this comment

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

Is this referred to as a NamedWorker anywhere else?
@deuill?

res, err := api.makeRequestWithHeaders("PUT", uri, []byte(data), headers)
var r WorkerScriptResponse
headers.Set("Content-Type", writer.FormDataContentType())
res, err := api.makeRequestWithHeaders("PUT", uri, body.Bytes(), headers)
Copy link

Choose a reason for hiding this comment

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

should we consider switching this to http.MethodPut too to make it more consistent with line 219?

var r WorkerScriptResponse
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
metadataPart, err := writer.CreateFormFile("metadata", "metadata.json")
Copy link

Choose a reason for hiding this comment

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

we should probably not hardcode these as metadata.json and script.js are not the only available options
https://developers.cloudflare.com/workers/api/resource-bindings/webassembly-modules/

@stale
Copy link

stale bot commented Oct 15, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Oct 15, 2019
@patryk
Copy link

patryk commented Oct 24, 2019

Merged a similar solution in #363. Thanks @grobinson-cloudflare !

@patryk patryk closed this Oct 24, 2019
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.

2 participants