From 8752dcbb191279b44a2b86ee0ed45ab040465b96 Mon Sep 17 00:00:00 2001 From: Guillaume Bouvignies Date: Wed, 17 Jan 2024 20:06:33 +0100 Subject: [PATCH] fix: lock file in metadata is now a string (#3027) --- backend/tests/worker.rs | 2 +- backend/windmill-api/openapi-deref.yaml | 33 +++++++++++++--- backend/windmill-api/openapi.yaml | 8 ++-- backend/windmill-api/src/scripts.rs | 2 - backend/windmill-api/src/workspaces.rs | 10 +---- backend/windmill-common/src/scripts.rs | 50 ++++++++++++++++++++++++- cli/script.ts | 5 ++- 7 files changed, 85 insertions(+), 25 deletions(-) diff --git a/backend/tests/worker.rs b/backend/tests/worker.rs index 33ba7fa915..e77b166a99 100644 --- a/backend/tests/worker.rs +++ b/backend/tests/worker.rs @@ -3148,7 +3148,7 @@ async fn run_deployed_relative_imports(db: &Pool, script_content: Stri is_template: None, kind: None, parent_hash: None, - lock: vec![], + lock: None, summary: "".to_string(), tag: None, schema: std::collections::HashMap::new(), diff --git a/backend/windmill-api/openapi-deref.yaml b/backend/windmill-api/openapi-deref.yaml index ecb798f56e..08deab14c2 100644 --- a/backend/windmill-api/openapi-deref.yaml +++ b/backend/windmill-api/openapi-deref.yaml @@ -1,6 +1,6 @@ openapi: 3.0.3 info: - version: 1.244.2 + version: 1.246.4 title: Windmill API contact: name: Windmill Team @@ -2086,6 +2086,29 @@ paths: - token_prefix - created_at - last_used_at + /w/{workspace}/oidc/token/{audience}: + post: + summary: get OIDC token (ee only) + operationId: getOidcToken + tags: + - oidc + parameters: + - name: workspace + in: path + required: true + schema: *ref_0 + - name: audience + in: path + required: true + schema: + type: string + responses: + '200': + description: new oidc token + content: + text/plain: + schema: + type: string /w/{workspace}/variables/create: post: summary: create variable @@ -4312,9 +4335,7 @@ paths: is_template: type: boolean lock: - type: array - items: - type: string + type: string language: type: string enum: @@ -6767,7 +6788,7 @@ paths: items: type: object properties: &ref_184 - content: + raw_code: type: string path: type: string @@ -6788,7 +6809,7 @@ paths: - nativets - bun required: &ref_185 - - content + - raw_code - path - language entrypoint: diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index 9611e073f6..995251c30c 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -7625,9 +7625,7 @@ components: is_template: type: boolean lock: - type: array - items: - type: string + type: string language: type: string enum: @@ -9379,7 +9377,7 @@ components: RawScriptForDependencies: type: object properties: - content: + raw_code: type: string path: type: string @@ -9402,6 +9400,6 @@ components: bun, ] required: - - content + - raw_code - path - language diff --git a/backend/windmill-api/src/scripts.rs b/backend/windmill-api/src/scripts.rs index 772e55c713..e53d635091 100644 --- a/backend/windmill-api/src/scripts.rs +++ b/backend/windmill-api/src/scripts.rs @@ -456,8 +456,6 @@ async fn create_script( Some(String::new()) } else { ns.lock - .as_ref() - .map(|x| x.join("\n")) .and_then(|e| if e.is_empty() { None } else { Some(e) }) }; diff --git a/backend/windmill-api/src/workspaces.rs b/backend/windmill-api/src/workspaces.rs index 55a2c99964..0743d4dd1a 100644 --- a/backend/windmill-api/src/workspaces.rs +++ b/backend/windmill-api/src/workspaces.rs @@ -1813,7 +1813,7 @@ struct ScriptMetadata { description: String, schema: Option, is_template: bool, - lock: Vec, + lock: Option, kind: String, #[serde(skip_serializing_if = "Option::is_none")] envs: Option>, @@ -2021,19 +2021,13 @@ async fn tarball_workspace( .write_to_archive(&script.content, &format!("{}.{}", script.path, ext)) .await?; - let lock = script - .lock - .unwrap_or_else(|| "".to_string()) - .lines() - .map(|x| x.to_string()) - .collect(); let metadata = ScriptMetadata { summary: script.summary, description: script.description, schema: script.schema, is_template: script.is_template, kind: script.kind.to_string(), - lock, + lock: script.lock, envs: script.envs, concurrent_limit: script.concurrent_limit, concurrency_time_window_s: script.concurrency_time_window_s, diff --git a/backend/windmill-common/src/scripts.rs b/backend/windmill-common/src/scripts.rs index 6168d92740..3ad1a4e0c8 100644 --- a/backend/windmill-common/src/scripts.rs +++ b/backend/windmill-common/src/scripts.rs @@ -240,7 +240,9 @@ pub struct NewScript { pub content: String, pub schema: Option, pub is_template: Option, - pub lock: Option>, + #[serde(default = "Option::default")] + #[serde(deserialize_with = "lock_deserialize")] + pub lock: Option, pub language: ScriptLang, pub kind: Option, pub tag: Option, @@ -258,6 +260,52 @@ pub struct NewScript { pub deployment_message: Option, } +fn lock_deserialize<'de, D>(deserializer: D) -> Result, D::Error> +where + D: serde::de::Deserializer<'de>, +{ + struct StringOrArrayVisitor; + + impl<'de> serde::de::Visitor<'de> for StringOrArrayVisitor { + type Value = Option; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("either a string or an array of strings") + } + + fn visit_str(self, v: &str) -> Result + where + E: serde::de::Error, + { + Ok(Some(v.to_string())) + } + + fn visit_none(self) -> Result + where + E: serde::de::Error, + { + Ok(None) + } + + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let mut split_lock: Vec = vec![]; + loop { + if let Ok(Some(elem)) = seq.next_element::() { + split_lock.push(elem); + } else { + break; + } + } + let lock = split_lock.join("\n"); + return Ok(Some(lock)); + } + } + deserializer.deserialize_any(StringOrArrayVisitor) +} + #[derive(Deserialize)] pub struct ListScriptQuery { pub path_start: Option, diff --git a/cli/script.ts b/cli/script.ts index feb9010970..d9072d1655 100644 --- a/cli/script.ts +++ b/cli/script.ts @@ -69,6 +69,7 @@ export async function handleScriptMetadata( } async function parseMetadataFile(scriptPath: string): Promise<{isJson: boolean, payload: any} | undefined> { + let metadataFilePath = scriptPath + ".script.json"; try { await Deno.stat(metadataFilePath); @@ -126,7 +127,7 @@ export async function handleFile( const remotePath = path .substring(0, path.indexOf(".")) .replaceAll("\\", "/"); - const typed = (await parseMetadataFile(path))?.payload; + const typed = (await parseMetadataFile(remotePath))?.payload; const language = inferContentTypeFromFilePath(path); let remote = undefined; @@ -831,7 +832,7 @@ async function updateScriptLock(workspace: Workspace, scriptContent: string, lan if (lock === undefined) { throw new Error(`Failed to generate lockfile. Full response was: ${JSON.stringify(response)}`); } - metadataContent.lock = lock.split("\n"); + metadataContent.lock = lock; } catch { throw new Error(`Failed to generate lockfile. Status was: ${rawResponse.statusText}`); }