diff --git a/.changelog/1330.txt b/.changelog/1330.txt new file mode 100644 index 00000000000..630d7ee2531 --- /dev/null +++ b/.changelog/1330.txt @@ -0,0 +1,15 @@ +```release-note:enhancement +workers: Add support for uploading scripts to a Workers for Platforms namespace. +``` + +```release-note:enhancement +workers: Add support for declaring arbitrary bindings with UnsafeBinding. +``` + +```release-note:enhancement +workers: Add support for uploading workers with Workers for Platforms namespace bindings. +``` + +```release-note:enhancement +workers: Add `pipeline_hash` field to Workers script response struct. +``` diff --git a/workers_bindings.go b/workers_bindings.go index d37513ee6d3..f5bcd624a61 100644 --- a/workers_bindings.go +++ b/workers_bindings.go @@ -407,7 +407,7 @@ func (b DispatchNamespaceBinding) serialize(bindingName string) (workerBindingMe return meta, nil, nil } -// UnsafeBinding is for experimental or deprecated bindings, and allows specifying any binding type or property +// UnsafeBinding is for experimental or deprecated bindings, and allows specifying any binding type or property. type UnsafeBinding map[string]interface{} // Type returns the type of the binding. diff --git a/workers_bindings_test.go b/workers_bindings_test.go index f8dea25ad37..b7514449b90 100644 --- a/workers_bindings_test.go +++ b/workers_bindings_test.go @@ -1,7 +1,9 @@ package cloudflare import ( + "bytes" "context" + "encoding/json" "fmt" "io" "net/http" @@ -95,3 +97,46 @@ func TestListWorkerBindings(t *testing.T) { }) assert.Equal(t, WorkerAnalyticsEngineBindingType, res.BindingList[7].Binding.Type()) } + +func ExampleUnsafeBinding() { + pretty := func(meta workerBindingMeta) string { + buf := bytes.NewBufferString("") + encoder := json.NewEncoder(buf) + encoder.SetIndent("", " ") + if err := encoder.Encode(meta); err != nil { + fmt.Println("error:", err) + } + return buf.String() + } + + binding_a := WorkerServiceBinding{ + Service: "foo", + } + meta_a, _, _ := binding_a.serialize("my_binding") + meta_a_json := pretty(meta_a) + fmt.Println(meta_a_json) + + binding_b := UnsafeBinding{ + "type": "service", + "service": "foo", + } + meta_b, _, _ := binding_b.serialize("my_binding") + meta_b_json := pretty(meta_b) + fmt.Println(meta_b_json) + + fmt.Println(meta_a_json == meta_b_json) + // Output: + // { + // "name": "my_binding", + // "service": "foo", + // "type": "service" + // } + // + // { + // "name": "my_binding", + // "service": "foo", + // "type": "service" + // } + // + // true +} diff --git a/workers_test.go b/workers_test.go index 7171a38547a..d116e93841a 100644 --- a/workers_test.go +++ b/workers_test.go @@ -1209,7 +1209,7 @@ func TestUploadWorker_ToDispatchNamespace(t *testing.T) { assert.Equal(t, http.MethodPut, r.Method, "Expected method 'PUT', got %s", r.Method) mpUpload, err := parseMultipartUpload(r) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, workerScript, mpUpload.Script) @@ -1242,7 +1242,7 @@ func TestUploadWorker_UnsafeBinding(t *testing.T) { assert.Equal(t, http.MethodPut, r.Method, "Expected method 'PUT', got %s", r.Method) mpUpload, err := parseMultipartUpload(r) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, workerScript, mpUpload.Script)