mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-19 00:02:03 +00:00
d3a171c283
* Setup V2 & Allow Workspace in base url
* Handle login conflict information
* Rework workspace & remote logic
* Add login logic
* Add token storage logic
* 🚀 finish refactor
* :Fix Pull
* Remove setup
* Add create-token
* Remove legacy typesc
* Fix change
* Fix warns
* fix warning
* Update README
* Switch to new workspace by default
* Update demo video
* Update Images
* remove duplicate
* Change wording
* Add to main README
* Fix main readme
* Fix videos
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
// deno-lint-ignore-file no-explicit-any
|
|
import { colors } from "https://deno.land/x/cliffy@v0.25.4/ansi/colors.ts";
|
|
import { setClient } from "https://deno.land/x/windmill@v1.50.0/mod.ts";
|
|
import { tryGetLoginInfo } from "./login.ts";
|
|
import { GlobalOptions } from "./types.ts";
|
|
import {
|
|
getActiveWorkspace,
|
|
getWorkspaceByName,
|
|
Workspace,
|
|
} from "./workspace.ts";
|
|
|
|
export type Context = {
|
|
workspace: string;
|
|
baseUrl: string;
|
|
urlStore: string;
|
|
token: string;
|
|
};
|
|
|
|
export async function resolveWorkspace(
|
|
opts: GlobalOptions,
|
|
): Promise<Workspace> {
|
|
const cache = (opts as any).__secret_workspace;
|
|
if (cache) return cache;
|
|
|
|
if (opts.workspace) {
|
|
const e = await getWorkspaceByName(opts.workspace);
|
|
if (!e) {
|
|
console.log(colors.red.underline("Given workspace does not exist."));
|
|
return Deno.exit(-1);
|
|
}
|
|
(opts as any).__secret_workspace = e;
|
|
return e;
|
|
}
|
|
|
|
const defaultWorkspace = await getActiveWorkspace(opts);
|
|
if (!defaultWorkspace) {
|
|
console.log(colors.red.underline("No workspace given and no default set."));
|
|
return Deno.exit(-3);
|
|
}
|
|
|
|
return defaultWorkspace;
|
|
}
|
|
|
|
export async function requireLogin(opts: GlobalOptions) {
|
|
const workspace = await resolveWorkspace(opts);
|
|
|
|
let token = await tryGetLoginInfo(opts);
|
|
if (!token) {
|
|
token = workspace.token;
|
|
}
|
|
|
|
setClient(token, workspace.remote.substring(0, workspace.remote.length - 1));
|
|
}
|