forked from windmill-labs/windmill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhub.ts
79 lines (73 loc) · 1.93 KB
/
hub.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Command } from "./deps.ts";
import { requireLogin, resolveWorkspace } from "./context.ts";
import { ResourceTypeFile } from "./resource-type.ts";
import { GlobalOptions } from "./types.ts";
async function pull(opts: GlobalOptions) {
const workspace = await resolveWorkspace(opts);
if (workspace.workspaceId !== "admins") {
console.log(
"Should only sync to admins workspace, but current is not admins.",
);
return;
}
const userInfo = await requireLogin(opts);
const list: {
id: number;
name: string;
schema: string;
approved: boolean;
app: string;
description: string;
created_by: string;
created_at: Date;
comments: never[];
}[] = await fetch(
"https://hub.windmill.dev/resource_types/list",
{
headers: {
"Accept": "application/json",
"X-email": userInfo.email,
},
},
)
.then((r) => r.json())
.then((list: { id: number; name: string }[]) =>
list.map((x) =>
fetch(
"https://hub.windmill.dev/resource_types/" + x.id + "/" + x.name,
{
headers: {
"Accept": "application/json",
},
},
)
)
)
.then((x) => Promise.all(x))
.then((x) =>
x.map((x) =>
x.json().catch((e) => {
console.log(e);
return undefined;
})
)
)
.then((x) => Promise.all(x))
.then((x) => x.filter((x) => x).map((x) => x.resource_type));
for (
const x of list
) {
console.log("syncing " + x.name);
const f = new ResourceTypeFile();
f.description = x.description;
f.schema = JSON.parse(x.schema);
await f.push(workspace.workspaceId, x.name);
}
}
const command = new Command()
.name("hub")
.description("Hub related commands. EXPERIMENTAL. INTERNAL USE ONLY.")
.command("pull")
.description("pull any supported defintions. EXPERIMENTAL.")
.action(pull as any);
export default command;