mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-12-04 08:09:16 +00:00
Merge remote-tracking branch 'origin/main' into deploy-block-on-failing-ci-tests
# Conflicts: # backend/windmill-api/src/ai_session_tools/gen/instructions.json
This commit is contained in:
@@ -551,6 +551,106 @@ async function remove(_opts: GlobalOptions, name: string) {
|
||||
await removeWorkspace(name, false, _opts);
|
||||
}
|
||||
|
||||
const CLI_LOGIN_TOKEN_LABEL_PREFIX = "cli-login:";
|
||||
|
||||
// Only a token the CLI's own browser login minted is revoked: a token pasted into the profile may
|
||||
// also be used elsewhere (CI, another machine), so deleting it could break more than this profile.
|
||||
async function revokeCliLoginToken(token: string): Promise<boolean> {
|
||||
const prefix = token.substring(0, 10);
|
||||
const perPage = 100;
|
||||
for (let page = 1; page <= 50; page++) {
|
||||
const tokens = await wmill.listTokens({ excludeEphemeral: true, page, perPage });
|
||||
const match = tokens.find((t) => t.token_prefix === prefix);
|
||||
if (match) {
|
||||
if (!match.label?.startsWith(CLI_LOGIN_TOKEN_LABEL_PREFIX)) {
|
||||
return false;
|
||||
}
|
||||
await wmill.deleteToken({ tokenPrefix: prefix });
|
||||
return true;
|
||||
}
|
||||
if (tokens.length < perPage) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async function login(opts: GlobalOptions, workspaceName?: string) {
|
||||
const workspace = workspaceName
|
||||
? await getWorkspaceByName(workspaceName, opts.configDir)
|
||||
: await getActiveWorkspace(opts);
|
||||
if (!workspace) {
|
||||
log.info(
|
||||
colors.red.bold(
|
||||
workspaceName
|
||||
? `! Workspace profile ${workspaceName} does not exist locally`
|
||||
: "! No active workspace profile. Add one with 'wmill workspace add'."
|
||||
)
|
||||
);
|
||||
return process.exit(1);
|
||||
}
|
||||
if (
|
||||
opts.baseUrl &&
|
||||
new URL(opts.baseUrl).toString() !== new URL(workspace.remote).toString()
|
||||
) {
|
||||
log.info(
|
||||
colors.red.bold(
|
||||
`! --base-url ${opts.baseUrl} does not match profile ${workspace.name} (${workspace.remote}). Use 'wmill workspace add' for another instance.`
|
||||
)
|
||||
);
|
||||
return process.exit(1);
|
||||
}
|
||||
|
||||
let token = await tryGetLoginInfo(opts);
|
||||
if (!token) {
|
||||
if (!(process.stdin.isTTY ?? false)) {
|
||||
log.info("Not a TTY, can't login interactively. Pass the token in --token");
|
||||
return process.exit(1);
|
||||
}
|
||||
log.info(
|
||||
`Signing in again to ${workspace.workspaceId} on ${workspace.remote} for profile ${workspace.name}`
|
||||
);
|
||||
token = await loginInteractive(workspace.remote);
|
||||
}
|
||||
if (!token) {
|
||||
log.info(colors.red.bold("! Login failed, the profile was left unchanged."));
|
||||
return process.exit(1);
|
||||
}
|
||||
|
||||
const remote = workspace.remote.substring(0, workspace.remote.length - 1);
|
||||
setClient(token, remote);
|
||||
try {
|
||||
await wmill.whoami({ workspace: workspace.workspaceId });
|
||||
} catch (e) {
|
||||
log.info(
|
||||
colors.red.bold(
|
||||
`! The new token cannot access workspace ${workspace.workspaceId}, the profile was left unchanged.`
|
||||
)
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
|
||||
const oldToken = workspace.token;
|
||||
await addWorkspace({ ...workspace, token }, opts);
|
||||
|
||||
// `wmill instance pull --include-workspaces` copies one token into the instance profile and
|
||||
// every workspace profile it creates: revoking it would sign all the others out.
|
||||
const { allInstances } = await import("../instance/instance.ts");
|
||||
const stillReferenced =
|
||||
(await allWorkspaces(opts.configDir)).some((w) => w.token === oldToken) ||
|
||||
(await allInstances()).some((i) => i.token === oldToken);
|
||||
if (oldToken && oldToken !== token && !stillReferenced) {
|
||||
try {
|
||||
if (await revokeCliLoginToken(oldToken)) {
|
||||
log.info("Revoked the profile's previous token.");
|
||||
}
|
||||
} catch {
|
||||
// Already expired or deleted, or owned by another user: nothing left to revoke.
|
||||
}
|
||||
}
|
||||
log.info(colors.green.underline(`Successfully signed in again for profile ${workspace.name}`));
|
||||
}
|
||||
|
||||
async function whoami(_opts: GlobalOptions) {
|
||||
const whoamiInfo = await requireLogin(_opts);
|
||||
log.info(JSON.stringify(whoamiInfo, null, 2));
|
||||
@@ -937,6 +1037,13 @@ const command = new Command()
|
||||
.description("Remove a workspace")
|
||||
.arguments("<workspace_name:string>")
|
||||
.action(remove as any)
|
||||
.command("login")
|
||||
.complete("workspace", async () => (await allWorkspaces()).map((x) => x.name))
|
||||
.description(
|
||||
"Sign in again for a workspace profile (default: the active one) and replace its token, e.g. to extend one about to expire. The previous token is revoked when the CLI's browser login created it."
|
||||
)
|
||||
.arguments("[workspace_name:string:workspace]")
|
||||
.action(login as any)
|
||||
.command("whoami")
|
||||
.description("Show the currently active user")
|
||||
.action(whoami as any)
|
||||
|
||||
+15
-7
@@ -122,19 +122,27 @@ export async function requireLogin(
|
||||
return process.exit(1);
|
||||
}
|
||||
|
||||
log.infoStderr(
|
||||
"! Could not reach API given existing credentials. Attempting to reauth..."
|
||||
);
|
||||
const isUnauthorized = error && typeof error === "object" &&
|
||||
"name" in error && (error as { name: unknown }).name === "ApiError" &&
|
||||
(error as { status?: number }).status === 401;
|
||||
log.infoStderr(colors.yellow(
|
||||
isUnauthorized
|
||||
? `! The token of workspace profile '${workspace.name}' has expired or was revoked. Sign in again to continue.`
|
||||
: "! Could not reach API given existing credentials. Attempting to reauth..."
|
||||
));
|
||||
const newToken = await loginInteractive(workspace.remote);
|
||||
if (!newToken) {
|
||||
throw new Error("Unauthorized: Could not authenticate with the provided credentials");
|
||||
throw new Error(
|
||||
`Unauthorized: Could not authenticate with the provided credentials. Run 'wmill workspace login ${workspace.name}' in a terminal to sign in again.`
|
||||
);
|
||||
}
|
||||
|
||||
// Update workspace token
|
||||
// Removed silently first: `addWorkspace` logs the update to stdout, which would land in the
|
||||
// output of the command being run (e.g. `wmill variable get … > file`).
|
||||
const { removeWorkspace, addWorkspace } = await import("../commands/workspace/workspace.ts");
|
||||
removeWorkspace(workspace.name, false, opts);
|
||||
await removeWorkspace(workspace.name, true, opts);
|
||||
workspace.token = newToken;
|
||||
addWorkspace(workspace, opts);
|
||||
await addWorkspace(workspace, opts);
|
||||
|
||||
setClient(
|
||||
newToken,
|
||||
|
||||
@@ -10,4 +10,4 @@ export const WM_FORK_PREFIX = "wm-fork";
|
||||
// (e.g. utils.ts) can read it without importing main.ts and creating a circular
|
||||
// dependency (main → workspace → utils → main) that triggers a TDZ.
|
||||
// Re-exported from main.ts for backwards compatibility.
|
||||
export const VERSION = "1.882.0";
|
||||
export const VERSION = "1.883.0";
|
||||
|
||||
@@ -97,7 +97,7 @@ export async function browserLogin(
|
||||
|
||||
// Start the server
|
||||
server.listen(port, () => {
|
||||
console.log(`Listening on port ${port}`);
|
||||
log.infoStderr(`Listening on port ${port}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ export interface ErrorHandlerConfig {
|
||||
extra_args?: any;
|
||||
muted_on_cancel?: boolean;
|
||||
muted_on_user_path?: boolean;
|
||||
muted_on_ui_runs?: boolean;
|
||||
}
|
||||
|
||||
export interface SuccessHandlerConfig {
|
||||
@@ -254,6 +255,9 @@ export async function pushWorkspaceSettings(
|
||||
for (const key of SETTINGS_MANAGED_ONLY_WHEN_PRESENT) {
|
||||
delete (localSettings as any)[key];
|
||||
}
|
||||
// Such a server reads an error handler body carrying this key as the legacy format, which
|
||||
// clears the handler.
|
||||
delete localSettings.error_handler?.muted_on_ui_runs;
|
||||
const webhookUnreadable = unreadableSecret(localSettings.webhook);
|
||||
if (webhookUnreadable) {
|
||||
log.warn(
|
||||
|
||||
Generated
+2
-1
@@ -8651,7 +8651,7 @@ write a secret you were not given: keep the placeholder.
|
||||
| Key | Value |
|
||||
|---|---|
|
||||
| \`auto_invite\` | \`{ enabled, mode: invite \\| add, operator, instance_groups?, instance_groups_roles? }\`. The instance groups are managed only when \`instance_groups\` is stated; clearing a group removes the members it added. |
|
||||
| \`error_handler\` / \`success_handler\` | \`{ path, extra_args?, muted_on_cancel?, muted_on_user_path? }\`, \`path\` being \`script/<path>\` or \`flow/<path>\`. |
|
||||
| \`error_handler\` / \`success_handler\` | \`{ path, extra_args?, muted_on_cancel?, muted_on_user_path?, muted_on_ui_runs? }\`, \`path\` being \`script/<path>\` or \`flow/<path>\`. \`muted_on_ui_runs\` (error handler only) skips jobs started from the UI. |
|
||||
| \`error_handler_fallback_to_instance_alerts\` | Report failures to the instance critical alert channels when no error handler is set. |
|
||||
| \`webhook\` | URL POSTed a JSON event on every change to the workspace's items. |
|
||||
| \`ai_config\` | Providers, default and completion models, custom prompts, \`copilot_disabled\`. |
|
||||
@@ -9703,6 +9703,7 @@ workspace related commands
|
||||
- \`--create-workspace-name <workspace_name:string>\` - Specify the workspace name. Ignored if --create is not specified or the workspace already exists. Will default to the workspace id.
|
||||
- \`--create-username <username:string>\` - Specify your own username in the newly created workspace. Ignored if --create is not specified, the workspace already exists or automatic username creation is enabled on the instance.
|
||||
- \`workspace remove <workspace_name:string>\` - Remove a workspace
|
||||
- \`workspace login [workspace_name:string:workspace]\` - Sign in again for a workspace profile (default: the active one) and replace its token, e.g. to extend one about to expire. The previous token is revoked when the CLI's browser login created it.
|
||||
- \`workspace whoami\` - Show the currently active user
|
||||
- \`workspace list\` - List local workspace profiles
|
||||
- \`workspace list-remote\` - List workspaces on the remote server that you have access to
|
||||
|
||||
@@ -284,11 +284,11 @@ export function inferContentTypeFromFilePath(
|
||||
): ScriptLanguage {
|
||||
if (contentPath.endsWith(".py")) {
|
||||
return "python3";
|
||||
} else if (contentPath.endsWith("fetch.ts")) {
|
||||
} else if (contentPath.endsWith(".fetch.ts")) {
|
||||
return "nativets";
|
||||
} else if (contentPath.endsWith("bun.ts")) {
|
||||
} else if (contentPath.endsWith(".bun.ts")) {
|
||||
return "bun";
|
||||
} else if (contentPath.endsWith("deno.ts")) {
|
||||
} else if (contentPath.endsWith(".deno.ts")) {
|
||||
return "deno";
|
||||
} else if (contentPath.endsWith(".ts")) {
|
||||
return defaultTs ?? "bun";
|
||||
|
||||
@@ -391,6 +391,13 @@ describe("inferContentTypeFromFilePath", () => {
|
||||
expect(inferContentTypeFromFilePath("script.fetch.ts", "bun")).toBe("nativets");
|
||||
});
|
||||
|
||||
test("language suffix needs its dot", () => {
|
||||
expect(inferContentTypeFromFilePath("f/a/a_fetch.ts", "bun")).toBe("bun");
|
||||
expect(inferContentTypeFromFilePath("f/a/afetch.ts", "bun")).toBe("bun");
|
||||
expect(inferContentTypeFromFilePath("f/a/a_bun.ts", "deno")).toBe("deno");
|
||||
expect(inferContentTypeFromFilePath("f/a/a_deno.ts", "bun")).toBe("bun");
|
||||
});
|
||||
|
||||
test("detects SQL variants", () => {
|
||||
expect(inferContentTypeFromFilePath("query.pg.sql", undefined)).toBe("postgresql");
|
||||
expect(inferContentTypeFromFilePath("query.my.sql", undefined)).toBe("mysql");
|
||||
|
||||
Reference in New Issue
Block a user