From 5ef50a8df9c2ddcf935b5c9d73db02495da1d51d Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 31 Jan 2024 14:53:09 +0100 Subject: [PATCH] fix(cli): push folders first + on_behalf_of stripped from metadata --- .github/DockerfileBackendTests | 6 +-- backend/windmill-api/src/workspaces.rs | 9 +++-- backend/windmill-worker/src/worker.rs | 9 +++-- cli/login.ts | 2 +- cli/script.ts | 3 -- cli/sync.ts | 53 ++++++++++++++++++++++++-- cli/workspace.ts | 2 +- 7 files changed, 66 insertions(+), 18 deletions(-) diff --git a/.github/DockerfileBackendTests b/.github/DockerfileBackendTests index 36595d7053..a3d9d592e3 100644 --- a/.github/DockerfileBackendTests +++ b/.github/DockerfileBackendTests @@ -1,4 +1,4 @@ -FROM python:3.10-slim-buster as nsjail +FROM python:3.11-slim-buster as nsjail WORKDIR /nsjail @@ -58,8 +58,8 @@ RUN /usr/local/bin/python3 -m pip install nltk RUN mkdir -p /nsjail_data/python && HOME=/nsjail_data/python /usr/local/bin/python3 -m nltk.downloader vader_lexicon COPY --from=nsjail /nsjail/nsjail /bin/nsjail -COPY --from=oven/bun:1.0.0 /usr/local/bin/bun /usr/bin/bun -COPY --from=denoland/deno:latest /usr/bin/deno /usr/bin/deno +COPY --from=oven/bun:1.0 /usr/local/bin/bun /usr/bin/bun +COPY --from=denoland/deno:1.40.2 /usr/bin/deno /usr/bin/deno RUN apt-get update \ && apt-get install -y postgresql-client --allow-unauthenticated diff --git a/backend/windmill-api/src/workspaces.rs b/backend/windmill-api/src/workspaces.rs index 5d249328f6..2dd266f682 100644 --- a/backend/windmill-api/src/workspaces.rs +++ b/backend/windmill-api/src/workspaces.rs @@ -1989,11 +1989,10 @@ pub fn to_string_without_metadata(value: &T, preserve_extra_perms: bool) -> R where T: ?Sized + Serialize, { - let value = serde_json::to_value(value).map_err(to_anyhow)?; + let mut value = serde_json::to_value(value).map_err(to_anyhow)?; value - .as_object() + .as_object_mut() .map(|obj| { - let mut obj = obj.clone(); for key in [ "workspace_id", "path", @@ -2016,6 +2015,10 @@ where } } + if let Some(o2) = obj.get_mut("policy").and_then(|x| x.as_object_mut()) { + o2.remove("on_behalf_of"); + o2.remove("on_behalf_of_email"); + } if !preserve_extra_perms && obj.contains_key("extra_perms") { obj.remove("extra_perms"); } diff --git a/backend/windmill-worker/src/worker.rs b/backend/windmill-worker/src/worker.rs index d7731dbaab..0f92345bfa 100644 --- a/backend/windmill-worker/src/worker.rs +++ b/backend/windmill-worker/src/worker.rs @@ -3442,7 +3442,7 @@ async fn lock_modules( let mut new_flow_modules = Vec::new(); for mut e in modules.into_iter() { let FlowModuleValue::RawScript { - lock: _, + lock, path, content, language, @@ -3450,7 +3450,7 @@ async fn lock_modules( tag, concurrent_limit, concurrency_time_window_s, - } = e.value + } = e.value.clone() else { match e.value { FlowModuleValue::ForloopFlow { @@ -3546,7 +3546,10 @@ async fn lock_modules( new_flow_modules.push(e); continue; }; - + if lock.as_ref().is_some_and(|x| !x.trim().is_empty()) { + new_flow_modules.push(e); + continue; + } let new_lock = capture_dependency_job( &job.id, &language, diff --git a/cli/login.ts b/cli/login.ts index 2960848481..8f2ef5b817 100644 --- a/cli/login.ts +++ b/cli/login.ts @@ -3,7 +3,7 @@ import { colors, getAvailablePort, log, open, Secret, Select } from "./deps.ts"; export async function loginInteractive(remote: string) { let token: string | undefined; - if (!Deno.isatty(Deno.stdin.rid)) { + if (!Deno.stdin.isTerminal) { log.info("Not a TTY, can't login interactively."); return undefined; } diff --git a/cli/script.ts b/cli/script.ts index 6a6f9d0fe6..94ffb8b619 100644 --- a/cli/script.ts +++ b/cli/script.ts @@ -151,7 +151,6 @@ export async function handleFile( typed == undefined || (typed.description === remote.description && typed.summary === remote.summary && - (typed.is_template ?? false) === (remote.is_template ?? false) && typed.kind == remote.kind && !remote.archived && (Array.isArray(remote?.lock) @@ -184,7 +183,6 @@ export async function handleFile( language: language as NewScript.language, path: remotePath.replaceAll("\\", "/"), summary: typed?.summary ?? "", - is_template: typed?.is_template, kind: typed?.kind, lock: lockfileUseArray ? typed?.lock.split("\n") : typed?.lock, parent_hash: remote.hash, @@ -212,7 +210,6 @@ export async function handleFile( language: language as NewScript.language, path: remotePath.replaceAll("\\", "/"), summary: typed?.summary ?? "", - is_template: typed?.is_template, kind: typed?.kind, lock: lockfileUseArray ? typed?.lock.split("\n") : typed?.lock, parent_hash: undefined, diff --git a/cli/sync.ts b/cli/sync.ts index 3ca782ff27..65e69d467c 100644 --- a/cli/sync.ts +++ b/cli/sync.ts @@ -381,12 +381,28 @@ async function compareDynFSElement( function parseYaml(k: string, v: string) { if (k.endsWith(".script.yaml")) { const o: any = yamlParse(v); - if (typeof o == "object" && Array.isArray(o?.["lock"])) { - o["lock"] = o["lock"].join("\n"); + if (typeof o == "object") { + if (Array.isArray(o?.["lock"])) { + o["lock"] = o["lock"].join("\n"); + } + if (o["is_template"] != undefined) { + delete o["is_template"]; + } + } + return o; + } else if (k.endsWith("flow.yaml")) { + const o: any = yamlParse(v); + const o2 = o["policy"]; + + if (typeof o2 == "object") { + if (o2["on_behalf_of"] != undefined) { + delete o2["on_behalf_of"]; + } + if (o2["on_behalf_of_email"] != undefined) { + delete o2["on_behalf_of_email"]; + } } return o; - } else { - return yamlParse(v); } } for (const [k, v] of Object.entries(m1)) { @@ -411,9 +427,38 @@ async function compareDynFSElement( } } + changes.sort((a, b) => + getOrderFromPath(a.path) == getOrderFromPath(b.path) + ? a.path.localeCompare(b.path) + : getOrderFromPath(a.path) - getOrderFromPath(b.path) + ); + return changes; } +function getOrderFromPath(p: string) { + const typ = getTypeStrFromPath(p); + if (typ == "folder") { + return 0; + } else if (typ == "resource-type") { + return 1; + } else if (typ == "resource") { + return 2; + } else if (typ == "script") { + return 3; + } else if (typ == "flow") { + return 4; + } else if (typ == "app") { + return 5; + } else if (typ == "schedule") { + return 6; + } else if (typ == "variable") { + return 7; + } else { + return 8; + } +} + const isNotWmillFile = (p: string, isDirectory: boolean) => { if (p.endsWith(SEP)) { return false; diff --git a/cli/workspace.ts b/cli/workspace.ts index e67066d81b..55f596c379 100644 --- a/cli/workspace.ts +++ b/cli/workspace.ts @@ -210,7 +210,7 @@ export async function add( remote = new URL(remote).toString(); // add trailing slash in all cases! let token = await tryGetLoginInfo(opts); - if (!token && !Deno.isatty(Deno.stdin.rid)) { + if (!token && !Deno.stdin.isTerminal) { log.info("Not a TTY, can't login interactively. Pass the token in --token"); return; }