forked from windmill-labs/windmill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpull.ts
63 lines (57 loc) · 1.77 KB
/
pull.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
// deno-lint-ignore-file no-explicit-any
import { GlobalOptions } from "./types.ts";
import { colors, Command, JSZip } from "./deps.ts";
import { Workspace } from "./workspace.ts";
export async function downloadZip(
workspace: Workspace,
plainSecrets: boolean | undefined,
skipVariables?: boolean,
skipResources?: boolean,
skipSecrets?: boolean,
includeSchedules?: boolean
): Promise<JSZip | undefined> {
const requestHeaders: HeadersInit = new Headers();
requestHeaders.set("Authorization", "Bearer " + workspace.token);
requestHeaders.set("Content-Type", "application/octet-stream");
const zipResponse = await fetch(
workspace.remote +
"api/w/" +
workspace.workspaceId +
`/workspaces/tarball?archive_type=zip&plain_secret=${
plainSecrets ?? false
}&skip_variables=${skipVariables ?? false}&skip_resources=${
skipResources ?? false
}&skip_secrets=${skipSecrets ?? false}&include_schedules=${
includeSchedules ?? false
}`,
{
headers: requestHeaders,
method: "GET",
}
);
if (!zipResponse.ok) {
console.log(
colors.red("Failed to request tarball from API " + zipResponse.statusText)
);
throw new Error(await zipResponse.text());
}
const blob = await zipResponse.blob();
return await JSZip.loadAsync(blob as any);
}
async function stub(
_opts: GlobalOptions & { override: boolean },
_dir: string
) {
console.log(
colors.red.underline(
'Pull is deprecated. Use "sync pull --raw" instead. See <TODO_LINK_HERE> for more information.'
)
);
}
const command = new Command()
.description(
"Pull all definitions in the current workspace from the API and write them to disk."
)
.arguments("<dir:string>")
.action(stub as any);
export default command;