From 88ca721b156eb7edc27c7f6d23e62f8a750fa1db Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Thu, 14 Dec 2023 09:00:38 +0100 Subject: [PATCH] fix(cli): check for existing resource even in raw mode --- cli/apps.ts | 22 +++++++++------------- cli/deps.ts | 4 ++-- cli/folder.ts | 22 +++++++++------------- cli/resource-type.ts | 23 ++++++++++------------- cli/resource.ts | 23 ++++++++++------------- cli/schedule.ts | 22 +++++++++------------- cli/sync.ts | 2 -- cli/types.ts | 20 ++++++-------------- cli/variable.ts | 27 +++++++++++---------------- 9 files changed, 66 insertions(+), 99 deletions(-) diff --git a/cli/apps.ts b/cli/apps.ts index 6fc4b04ce7..6e5afbc9f8 100644 --- a/cli/apps.ts +++ b/cli/apps.ts @@ -27,20 +27,17 @@ export async function pushApp( remotePath: string, app: AppFile | AppWithLastVersion | undefined, newApp: AppFile, - raw: boolean, message?: string ): Promise { remotePath = removeType(remotePath, "app"); - if (raw) { - // deleting old app if it exists in raw mode - try { - app = await AppService.getAppByPath({ - workspace, - path: remotePath.replaceAll("\\", "/"), - }); - } catch { - //ignore - } + // deleting old app if it exists in raw mode + try { + app = await AppService.getAppByPath({ + workspace, + path: remotePath.replaceAll("\\", "/"), + }); + } catch { + //ignore } if (app) { @@ -119,8 +116,7 @@ async function push(opts: GlobalOptions, filePath: string) { workspace.workspaceId, remotePath, app, - parseFromFile(filePath), - false + parseFromFile(filePath) ); console.log(colors.bold.underline.green("App pushed")); } diff --git a/cli/deps.ts b/cli/deps.ts index 9d19d741c6..166644e121 100644 --- a/cli/deps.ts +++ b/cli/deps.ts @@ -1,6 +1,6 @@ // windmill -export { setClient } from "https://deno.land/x/windmill@v1.216.0/mod.ts"; -export * from "https://deno.land/x/windmill@v1.216.0/windmill-api/index.ts"; +export { setClient } from "https://deno.land/x/windmill@v1.225.0/mod.ts"; +export * from "https://deno.land/x/windmill@v1.225.0/windmill-api/index.ts"; export { SEP } from "https://deno.land/std@0.201.0/path/separator.ts"; // cliffy export { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.2/command/mod.ts"; diff --git a/cli/folder.ts b/cli/folder.ts index cab4f17e18..4c1ddd85c0 100644 --- a/cli/folder.ts +++ b/cli/folder.ts @@ -43,8 +43,7 @@ export async function pushFolder( workspace: string, name: string, folder: Folder | FolderFile | undefined, - localFolder: FolderFile, - raw: boolean + localFolder: FolderFile ): Promise { if (name.startsWith(SEP)) { name = name.substring(1); @@ -55,15 +54,13 @@ export async function pushFolder( name = name.split(SEP)[0]; log.debug(`Processing local folder ${name}`); - if (raw) { - // deleting old app if it exists in raw mode - try { - folder = await FolderService.getFolder({ workspace, name }); - log.debug(`Folder ${name} exists on remote`); - } catch { - log.debug(`Folder ${name} does not exist on remote`); - //ignore - } + // deleting old app if it exists in raw mode + try { + folder = await FolderService.getFolder({ workspace, name }); + log.debug(`Folder ${name} exists on remote`); + } catch { + log.debug(`Folder ${name} does not exist on remote`); + //ignore } if (folder) { @@ -120,8 +117,7 @@ async function push(opts: GlobalOptions, filePath: string, remotePath: string) { workspace.workspaceId, remotePath, undefined, - parseFromFile(filePath), - false + parseFromFile(filePath) ); console.log(colors.bold.underline.green("Folder pushed")); } diff --git a/cli/resource-type.ts b/cli/resource-type.ts index fc85c4ed9d..38e43efb88 100644 --- a/cli/resource-type.ts +++ b/cli/resource-type.ts @@ -24,20 +24,18 @@ export async function pushResourceType( workspace: string, remotePath: string, resource: ResourceTypeFile | ResourceType | undefined, - localResource: ResourceTypeFile, - raw: boolean + localResource: ResourceTypeFile ): Promise { remotePath = removeType(remotePath, "resource-type"); - if (raw) { - try { - resource = await ResourceService.getResourceType({ - workspace: workspace, - path: remotePath, - }); - } catch { - // resource type doesn't exist - } + try { + resource = await ResourceService.getResourceType({ + workspace: workspace, + path: remotePath, + }); + } catch { + // resource type doesn't exist } + if (resource) { if (isSuperset(localResource, resource)) { return; @@ -77,8 +75,7 @@ async function push(opts: PushOptions, filePath: string, name: string) { workspace.workspaceId, name, undefined, - parseFromFile(filePath), - true + parseFromFile(filePath) ); log.info(colors.bold.underline.green("Resource pushed")); } diff --git a/cli/resource.ts b/cli/resource.ts index 3eee8437b3..55b1a211ae 100644 --- a/cli/resource.ts +++ b/cli/resource.ts @@ -26,20 +26,18 @@ export async function pushResource( workspace: string, remotePath: string, resource: ResourceFile | Resource | undefined, - localResource: ResourceFile, - raw: boolean + localResource: ResourceFile ): Promise { remotePath = removeType(remotePath, "resource"); - if (raw) { - try { - resource = await ResourceService.getResource({ - workspace: workspace, - path: remotePath.replaceAll("\\", "/"), - }); - } catch { - // flow doesn't exist - } + try { + resource = await ResourceService.getResource({ + workspace: workspace, + path: remotePath.replaceAll("\\", "/"), + }); + } catch { + // flow doesn't exist } + if (resource) { if (isSuperset(localResource, resource)) { return; @@ -90,8 +88,7 @@ async function push(opts: PushOptions, filePath: string, remotePath: string) { workspace.workspaceId, remotePath, undefined, - parseFromFile(filePath), - true + parseFromFile(filePath) ); log.info(colors.bold.underline.green(`Resource ${remotePath} pushed`)); } diff --git a/cli/schedule.ts b/cli/schedule.ts index ba76ac70e9..d9fcd525ec 100644 --- a/cli/schedule.ts +++ b/cli/schedule.ts @@ -44,22 +44,19 @@ export async function pushSchedule( workspace: string, path: string, schedule: Schedule | ScheduleFile | undefined, - localSchedule: ScheduleFile, - raw: boolean + localSchedule: ScheduleFile ): Promise { path = removeType(path, "schedule"); log.debug(`Processing local schedule ${path}`); - if (raw) { - // deleting old app if it exists in raw mode - try { - schedule = await ScheduleService.getSchedule({ workspace, path }); - log.debug(`Schedule ${path} exists on remote`); - } catch { - log.debug(`Schedule ${path} does not exist on remote`); - //ignore - } + // deleting old app if it exists in raw mode + try { + schedule = await ScheduleService.getSchedule({ workspace, path }); + log.debug(`Schedule ${path} exists on remote`); + } catch { + log.debug(`Schedule ${path} does not exist on remote`); + //ignore } if (schedule) { @@ -116,8 +113,7 @@ async function push(opts: GlobalOptions, filePath: string, remotePath: string) { workspace.workspaceId, remotePath, undefined, - parseFromFile(filePath), - false + parseFromFile(filePath) ); console.log(colors.bold.underline.green("Schedule pushed")); } diff --git a/cli/sync.ts b/cli/sync.ts index 0ce6df44de..821c64d7b7 100644 --- a/cli/sync.ts +++ b/cli/sync.ts @@ -732,7 +732,6 @@ async function push( oldObj, newObj, opts.plainSecrets ?? false, - opts.raw, opts.message ); @@ -766,7 +765,6 @@ async function push( undefined, obj, opts.plainSecrets ?? false, - opts.raw, opts.message ); diff --git a/cli/types.ts b/cli/types.ts index 0d2d2ee324..4de8c760b4 100644 --- a/cli/types.ts +++ b/cli/types.ts @@ -99,33 +99,25 @@ export async function pushObj( befObj: any, newObj: any, plainSecrets: boolean, - checkForCreate: boolean, message?: string ) { const typeEnding = getTypeStrFromPath(p); if (typeEnding === "app") { - await pushApp(workspace, p, befObj, newObj, checkForCreate, message); + await pushApp(workspace, p, befObj, newObj, message); } else if (typeEnding === "folder") { - await pushFolder(workspace, p, befObj, newObj, checkForCreate); + await pushFolder(workspace, p, befObj, newObj); } else if (typeEnding === "variable") { - await pushVariable( - workspace, - p, - befObj, - newObj, - plainSecrets, - checkForCreate - ); + await pushVariable(workspace, p, befObj, newObj, plainSecrets); } else if (typeEnding === "flow") { const flowName = p.split(".flow/")[0]; await pushFlow(workspace, flowName, flowName + ".flow", message); } else if (typeEnding === "resource") { - await pushResource(workspace, p, befObj, newObj, checkForCreate); + await pushResource(workspace, p, befObj, newObj); } else if (typeEnding === "resource-type") { - await pushResourceType(workspace, p, befObj, newObj, checkForCreate); + await pushResourceType(workspace, p, befObj, newObj); } else if (typeEnding === "schedule") { - await pushSchedule(workspace, p, befObj, newObj, checkForCreate); + await pushSchedule(workspace, p, befObj, newObj); } else { throw new Error("infer type unreachable"); } diff --git a/cli/variable.ts b/cli/variable.ts index eebae09af6..41c756bf71 100644 --- a/cli/variable.ts +++ b/cli/variable.ts @@ -52,23 +52,20 @@ export async function pushVariable( remotePath: string, variable: VariableFile | ListableVariable | undefined, localVariable: VariableFile, - plainSecrets: boolean, - raw: boolean + plainSecrets: boolean ): Promise { remotePath = removeType(remotePath, "variable"); log.debug(`Processing local variable ${remotePath}`); - if (raw) { - try { - variable = await VariableService.getVariable({ - workspace: workspace, - path: remotePath.replaceAll("\\", "/"), - decryptSecret: plainSecrets, - }); - log.debug(`Variable ${remotePath} exists on remote`); - } catch { - log.debug(`Variable ${remotePath} does not exist on remote`); - } + try { + variable = await VariableService.getVariable({ + workspace: workspace, + path: remotePath.replaceAll("\\", "/"), + decryptSecret: plainSecrets, + }); + log.debug(`Variable ${remotePath} exists on remote`); + } catch { + log.debug(`Variable ${remotePath} does not exist on remote`); } if (variable) { @@ -125,8 +122,7 @@ async function push( remotePath, undefined, parseFromFile(filePath), - opts.plainSecrets, - true + opts.plainSecrets ); log.info(colors.bold.underline.green(`Variable ${remotePath} pushed`)); } @@ -171,7 +167,6 @@ async function add( is_secret: !opts.public, description: "", }, - true, true ); log.info(colors.bold.underline.green(`Variable ${remotePath} pushed`));