From 944ef2df6919eab40f78905bee6dda01a85dfcaa Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sat, 27 May 2023 14:31:23 +0200 Subject: [PATCH] fix(cli): expose an encrypt value endpoint --- backend/windmill-api/openapi.yaml | 23 +++++++++++++++++++++++ backend/windmill-api/src/variables.rs | 16 ++++++++++++++++ cli/hub.ts | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index fcf5b4bce5..1ed7802a42 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -1181,6 +1181,29 @@ paths: schema: type: string + /w/{workspace}/variables/encrypt: + post: + summary: encrypt value + operationId: encryptValue + tags: + - variable + parameters: + - $ref: "#/components/parameters/WorkspaceId" + requestBody: + description: new variable + required: true + content: + application/json: + schema: + type: string + responses: + "200": + description: encrypted value + content: + text/plain: + schema: + type: string + /w/{workspace}/variables/delete/{path}: delete: summary: delete variable diff --git a/backend/windmill-api/src/variables.rs b/backend/windmill-api/src/variables.rs index cf0ab42671..7ce70ebe8a 100644 --- a/backend/windmill-api/src/variables.rs +++ b/backend/windmill-api/src/variables.rs @@ -40,6 +40,7 @@ pub fn workspaced_service() -> Router { .route("/update/*path", post(update_variable)) .route("/delete/*path", delete(delete_variable)) .route("/create", post(create_variable)) + .route("/encrypt", post(encrypt_value)) } async fn list_contextual_variables( @@ -257,6 +258,21 @@ async fn create_variable( )) } +async fn encrypt_value( + Extension(db): Extension, + Path(w_id): Path, + Json(variable): Json, +) -> Result { + let mut tx = db.begin().await?; + + let mc = build_crypt(&mut tx, &w_id).await?; + let value = encrypt(&mc, &variable); + + tx.commit().await?; + + Ok(value) +} + async fn delete_variable( authed: Authed, Extension(user_db): Extension, diff --git a/cli/hub.ts b/cli/hub.ts index 86952fc1a1..4adbf83ebf 100644 --- a/cli/hub.ts +++ b/cli/hub.ts @@ -81,7 +81,7 @@ async function pull(opts: GlobalOptions) { x.name + ".resource-type.json", undefined, x, - false + true ); } }