- Add wmill.yaml configuration with includes for f/**, u/**, g/** - Add sync_to_git.sh script for automatic Git synchronization - Add initial workflows synced from Windmill: - Test script: u/antigravity/test_git_sync - Admin scripts: u/admin/hub_sync - Setup app: g/all/setup_app - Folders: f/app_custom, f/app_groups, f/app_themes
73 lines
1.6 KiB
TypeScript
73 lines
1.6 KiB
TypeScript
import * as wmill from "https://deno.land/x/windmill@v1.99.0/mod.ts";
|
|
|
|
export async function main(
|
|
oldEmail: string,
|
|
newEmail: string,
|
|
newPassword: string,
|
|
enable_hub_sync: boolean,
|
|
sync_now: boolean,
|
|
) {
|
|
try {
|
|
await wmill.UserService.createUserGlobally({
|
|
requestBody: {
|
|
email: newEmail,
|
|
password: newPassword,
|
|
super_admin: true,
|
|
},
|
|
});
|
|
} catch (e) {
|
|
throw Error("User already exists: " + e.body);
|
|
}
|
|
|
|
let new_token;
|
|
|
|
try {
|
|
new_token = await wmill.UserService.login({
|
|
requestBody: {
|
|
email: newEmail,
|
|
password: newPassword,
|
|
},
|
|
});
|
|
} catch (e) {
|
|
throw Error("Login failed: " + e.body);
|
|
}
|
|
|
|
wmill.setClient(new_token, Deno.env.get("BASE_INTERNAL_URL")!);
|
|
|
|
if (sync_now) {
|
|
try {
|
|
await wmill.JobService.runScriptByPath({
|
|
workspace: "admins",
|
|
path: "u/admin/hub_sync",
|
|
requestBody: {},
|
|
});
|
|
} catch (e) {
|
|
throw Error("Hub sync failed:" + e.body);
|
|
}
|
|
}
|
|
|
|
if (enable_hub_sync) {
|
|
try {
|
|
await wmill.ScheduleService.createSchedule({
|
|
workspace: "admins",
|
|
requestBody: {
|
|
path: "g/all/hub_sync",
|
|
schedule: "0 0 0 * * *",
|
|
script_path: "u/admin/hub_sync",
|
|
is_flow: false,
|
|
args: {},
|
|
enabled: true,
|
|
timezone: "Etc/UTC",
|
|
},
|
|
});
|
|
} catch (e) {
|
|
throw Error("Error creating schedule: " + e.body);
|
|
}
|
|
}
|
|
try {
|
|
await wmill.UserService.globalUserDelete({ email: oldEmail });
|
|
} catch (e) {
|
|
throw Error("Deleting old account failed: " + e.body);
|
|
}
|
|
}
|