diff --git a/backend/sqlx-data.json b/backend/sqlx-data.json index 8d40e2e01d..7c3f3cb1b4 100644 --- a/backend/sqlx-data.json +++ b/backend/sqlx-data.json @@ -2655,6 +2655,20 @@ }, "query": "INSERT INTO group_\n (workspace_id, name, summary)\n VALUES ($1, $2, $3) ON CONFLICT DO NOTHING" }, + "8876fa929ffb175cd976a2bca1195704aa9fe7215013ae29e49ef15cb201ba57": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Left": [ + "Jsonb", + "Text", + "Text" + ] + } + }, + "query": "UPDATE resource SET value = $1 WHERE path = $2 AND workspace_id = $3" + }, "88a3f58a1a315200fdd2e4bb8638246ee21818f8aaaf56f6e9d7ddce1490d886": { "describe": { "columns": [ diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index b59bcc74ea..5966828354 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -1422,6 +1422,29 @@ paths: schema: type: string + /w/{workspace}/resources/update_value/{path}: + post: + summary: update resource value + operationId: updateResourceValue + tags: + - resource + parameters: + - $ref: "#/components/parameters/WorkspaceId" + - $ref: "#/components/parameters/Path" + requestBody: + description: updated resource + required: true + content: + application/json: + schema: {} + responses: + "200": + description: resource value updated + content: + text/plain: + schema: + type: string + /w/{workspace}/resources/get/{path}: get: summary: get resource diff --git a/backend/windmill-api/src/resources.rs b/backend/windmill-api/src/resources.rs index 77e5d3e6d7..b59b78c49f 100644 --- a/backend/windmill-api/src/resources.rs +++ b/backend/windmill-api/src/resources.rs @@ -32,6 +32,7 @@ pub fn workspaced_service() -> Router { .route("/exists/*path", get(exists_resource)) .route("/get_value/*path", get(get_resource_value)) .route("/update/*path", post(update_resource)) + .route("/update_value/*path", post(update_resource_value)) .route("/delete/*path", delete(delete_resource)) .route("/create", post(create_resource)) .route("/type/list", get(list_resource_types)) @@ -402,6 +403,38 @@ async fn update_resource( Ok(format!("resource {} updated (npath: {:?})", path, npath)) } +async fn update_resource_value( + authed: Authed, + Extension(user_db): Extension, + Path((w_id, path)): Path<(String, StripPath)>, + Json(nv): Json, +) -> Result { + let path = path.to_path(); + let mut tx = user_db.begin(&authed).await?; + + sqlx::query!( + "UPDATE resource SET value = $1 WHERE path = $2 AND workspace_id = $3", + nv, + path, + w_id + ) + .execute(&mut tx) + .await?; + audit_log( + &mut tx, + &authed.username, + "resources.update", + ActionKind::Update, + &w_id, + Some(path), + None, + ) + .await?; + tx.commit().await?; + + Ok(format!("value of resource {} updated", path)) +} + async fn list_resource_types( Extension(db): Extension, Path(w_id): Path, diff --git a/deno-client/mod.ts b/deno-client/mod.ts index 6181779279..44d298f3b2 100644 --- a/deno-client/mod.ts +++ b/deno-client/mod.ts @@ -72,7 +72,7 @@ export async function setResource(value: any, path?: string, initializeToTypeIfN path = path ?? getStatePath() const workspace = getWorkspace() if (await ResourceService.existsResource({ workspace, path })) { - await ResourceService.updateResource({ workspace, path, requestBody: { value } }) + await ResourceService.updateResourceValue({ workspace, path, requestBody: value }) } else if (initializeToTypeIfNotExist) { await ResourceService.createResource({ workspace, requestBody: { path, value, resource_type: initializeToTypeIfNotExist } }) } else { diff --git a/go-client/windmill.go b/go-client/windmill.go index a2cfa28c82..b153fcaeb4 100644 --- a/go-client/windmill.go +++ b/go-client/windmill.go @@ -73,7 +73,7 @@ func SetResource(path string, value interface{}) error { if err != nil { return err } - res, err := client.Client.UpdateResourceWithResponse(context.Background(), client.Workspace, path, api.EditResource{Value: &value}) + res, err := client.Client.UpdateResourceValueWithResponse(context.Background(), client.Workspace, path, value) if err != nil { return err } diff --git a/python-client/wmill/wmill/client.py b/python-client/wmill/wmill/client.py index 9db965ff8d..e423824ba4 100644 --- a/python-client/wmill/wmill/client.py +++ b/python-client/wmill/wmill/client.py @@ -205,10 +205,9 @@ def set_resource( from windmill_api.models.create_resource_json_body import CreateResourceJsonBody from windmill_api.api.resource import ( exists_resource, - update_resource, + update_resource_value, create_resource, ) - from windmill_api.models.update_resource_json_body import UpdateResourceJsonBody path = path or get_state_path() workspace = get_workspace() @@ -224,11 +223,11 @@ def set_resource( ), ) else: - update_resource.sync_detailed( + update_resource_value.sync_detailed( workspace=get_workspace(), client=client, path=path, - json_body=UpdateResourceJsonBody(value=value), + json_body=value, )