@zuplo/cli 1.41.0 → 1.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cmds/delete.js +11 -1
- package/dist/cmds/deploy.js +9 -3
- package/dist/cmds/list.js +11 -1
- package/dist/cmds/test.js +1 -1
- package/dist/cmds/tunnel/create.js +2 -1
- package/dist/cmds/tunnel/delete.js +2 -1
- package/dist/cmds/tunnel/describe.js +2 -1
- package/dist/cmds/tunnel/list.js +2 -1
- package/dist/cmds/tunnel/rotate-token.js +2 -1
- package/dist/cmds/tunnel/services/describe.js +2 -1
- package/dist/cmds/tunnel/services/update.js +2 -1
- package/dist/cmds/variable/create.js +11 -1
- package/dist/cmds/variable/update.js +9 -4
- package/dist/common/constants.js +2 -0
- package/dist/common/middleware/user-configuration.js +59 -0
- package/dist/common/validators/file-system-validator.js +15 -8
- package/dist/common/validators/project-name-validator.js +30 -0
- package/dist/delete/handler.js +16 -28
- package/dist/deploy/handler.js +24 -36
- package/dist/list/handler.js +12 -24
- package/dist/tunnel/create/handler.js +15 -27
- package/dist/tunnel/delete/handler.js +20 -32
- package/dist/tunnel/describe/handler.js +12 -24
- package/dist/tunnel/list/handler.js +18 -30
- package/dist/tunnel/rotate-token/handler.js +13 -25
- package/dist/tunnel/services/describe/handler.js +12 -24
- package/dist/tunnel/services/update/handler.js +29 -41
- package/dist/variable/create/handler.js +19 -31
- package/dist/variable/update/handler.js +17 -29
- package/package.json +2 -1
package/dist/cmds/delete.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { configure } from "../common/middleware/user-configuration.js";
|
|
1
2
|
import setBlocking from "../common/output.js";
|
|
3
|
+
import { YargsChecker } from "../common/validators/lib.js";
|
|
4
|
+
import { ProjectIsSetValidator } from "../common/validators/project-name-validator.js";
|
|
2
5
|
import { deleteZup } from "../delete/handler.js";
|
|
3
6
|
export default {
|
|
4
7
|
desc: "Deletes the zup at the URL",
|
|
@@ -13,6 +16,10 @@ export default {
|
|
|
13
16
|
.option("url", {
|
|
14
17
|
type: "string",
|
|
15
18
|
describe: "The URL of the zup to delete",
|
|
19
|
+
})
|
|
20
|
+
.option("project", {
|
|
21
|
+
type: "string",
|
|
22
|
+
describe: "The project name",
|
|
16
23
|
})
|
|
17
24
|
.option("wait", {
|
|
18
25
|
type: "boolean",
|
|
@@ -20,7 +27,10 @@ export default {
|
|
|
20
27
|
})
|
|
21
28
|
.boolean("wait")
|
|
22
29
|
.demandOption(["api-key", "url"])
|
|
23
|
-
.middleware([setBlocking])
|
|
30
|
+
.middleware([setBlocking, configure])
|
|
31
|
+
.check(async (argv) => {
|
|
32
|
+
return await new YargsChecker(new ProjectIsSetValidator()).check(argv);
|
|
33
|
+
});
|
|
24
34
|
},
|
|
25
35
|
handler: async (argv) => {
|
|
26
36
|
await deleteZup(argv);
|
package/dist/cmds/deploy.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { configure } from "../common/middleware/user-configuration.js";
|
|
1
2
|
import setBlocking from "../common/output.js";
|
|
2
3
|
import { validDeployDirectoryValidator } from "../common/validators/file-system-validator.js";
|
|
3
4
|
import { YargsChecker } from "../common/validators/lib.js";
|
|
@@ -11,6 +12,11 @@ export default {
|
|
|
11
12
|
type: "string",
|
|
12
13
|
describe: "The API Key from Zuplo",
|
|
13
14
|
envVar: "API_KEY",
|
|
15
|
+
})
|
|
16
|
+
.option("project", {
|
|
17
|
+
type: "string",
|
|
18
|
+
hidden: true,
|
|
19
|
+
describe: "The project name",
|
|
14
20
|
})
|
|
15
21
|
.option("dir", {
|
|
16
22
|
type: "string",
|
|
@@ -26,10 +32,10 @@ export default {
|
|
|
26
32
|
})
|
|
27
33
|
.demandOption(["api-key"])
|
|
28
34
|
.boolean("verify-remote")
|
|
35
|
+
.middleware([setBlocking, configure])
|
|
29
36
|
.check(async (argv) => {
|
|
30
|
-
return await new YargsChecker(validDeployDirectoryValidator).check(argv
|
|
31
|
-
})
|
|
32
|
-
.middleware([setBlocking]);
|
|
37
|
+
return await new YargsChecker(validDeployDirectoryValidator).check(argv);
|
|
38
|
+
});
|
|
33
39
|
},
|
|
34
40
|
handler: async (argv) => {
|
|
35
41
|
await deploy(argv);
|
package/dist/cmds/list.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { configure } from "../common/middleware/user-configuration.js";
|
|
1
2
|
import setBlocking from "../common/output.js";
|
|
3
|
+
import { YargsChecker } from "../common/validators/lib.js";
|
|
4
|
+
import { ProjectIsSetValidator } from "../common/validators/project-name-validator.js";
|
|
2
5
|
import { list } from "../list/handler.js";
|
|
3
6
|
export default {
|
|
4
7
|
desc: "Lists all deployed zups",
|
|
@@ -9,9 +12,16 @@ export default {
|
|
|
9
12
|
type: "string",
|
|
10
13
|
describe: "The API Key from Zuplo",
|
|
11
14
|
envVar: "API_KEY",
|
|
15
|
+
})
|
|
16
|
+
.option("project", {
|
|
17
|
+
type: "string",
|
|
18
|
+
describe: "The project name",
|
|
12
19
|
})
|
|
13
20
|
.demandOption(["api-key"])
|
|
14
|
-
.middleware([setBlocking])
|
|
21
|
+
.middleware([setBlocking, configure])
|
|
22
|
+
.check(async (argv) => {
|
|
23
|
+
return await new YargsChecker(new ProjectIsSetValidator()).check(argv);
|
|
24
|
+
});
|
|
15
25
|
},
|
|
16
26
|
handler: async (argv) => {
|
|
17
27
|
await list(argv);
|
package/dist/cmds/test.js
CHANGED
|
@@ -23,7 +23,7 @@ export default {
|
|
|
23
23
|
hidden: true,
|
|
24
24
|
})
|
|
25
25
|
.check(async (argv) => {
|
|
26
|
-
return await new YargsChecker(validTestDirectoryValidator).check(argv
|
|
26
|
+
return await new YargsChecker(validTestDirectoryValidator).check(argv);
|
|
27
27
|
})
|
|
28
28
|
.middleware([setBlocking]);
|
|
29
29
|
},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { configure } from "../../common/middleware/user-configuration.js";
|
|
1
2
|
import setBlocking from "../../common/output.js";
|
|
2
3
|
import { create } from "../../tunnel/create/handler.js";
|
|
3
4
|
export default {
|
|
@@ -15,7 +16,7 @@ export default {
|
|
|
15
16
|
envVar: "API_KEY",
|
|
16
17
|
})
|
|
17
18
|
.demandOption(["api-key", "tunnel-name"])
|
|
18
|
-
.middleware([setBlocking]);
|
|
19
|
+
.middleware([setBlocking, configure]);
|
|
19
20
|
},
|
|
20
21
|
handler: async (argv) => {
|
|
21
22
|
create(argv);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { configure } from "../../common/middleware/user-configuration.js";
|
|
1
2
|
import setBlocking from "../../common/output.js";
|
|
2
3
|
import { deleteTunnel } from "../../tunnel/delete/handler.js";
|
|
3
4
|
export default {
|
|
@@ -11,7 +12,7 @@ export default {
|
|
|
11
12
|
envVar: "API_KEY",
|
|
12
13
|
})
|
|
13
14
|
.demandOption(["api-key"])
|
|
14
|
-
.middleware([setBlocking]);
|
|
15
|
+
.middleware([setBlocking, configure]);
|
|
15
16
|
},
|
|
16
17
|
handler: async (argv) => {
|
|
17
18
|
deleteTunnel(argv);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { configure } from "../../common/middleware/user-configuration.js";
|
|
1
2
|
import setBlocking from "../../common/output.js";
|
|
2
3
|
import { describe } from "../../tunnel/describe/handler.js";
|
|
3
4
|
export default {
|
|
@@ -15,7 +16,7 @@ export default {
|
|
|
15
16
|
envVar: "API_KEY",
|
|
16
17
|
})
|
|
17
18
|
.demandOption(["api-key", "tunnel-id"])
|
|
18
|
-
.middleware([setBlocking]);
|
|
19
|
+
.middleware([setBlocking, configure]);
|
|
19
20
|
},
|
|
20
21
|
handler: async (argv) => {
|
|
21
22
|
describe(argv);
|
package/dist/cmds/tunnel/list.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { configure } from "../../common/middleware/user-configuration.js";
|
|
1
2
|
import setBlocking from "../../common/output.js";
|
|
2
3
|
import { list } from "../../tunnel/list/handler.js";
|
|
3
4
|
export default {
|
|
@@ -11,7 +12,7 @@ export default {
|
|
|
11
12
|
envVar: "API_KEY",
|
|
12
13
|
})
|
|
13
14
|
.demandOption(["api-key"])
|
|
14
|
-
.middleware([setBlocking]);
|
|
15
|
+
.middleware([setBlocking, configure]);
|
|
15
16
|
},
|
|
16
17
|
handler: async (argv) => {
|
|
17
18
|
await list(argv);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { configure } from "../../common/middleware/user-configuration.js";
|
|
1
2
|
import setBlocking from "../../common/output.js";
|
|
2
3
|
import { rotateToken } from "../../tunnel/rotate-token/handler.js";
|
|
3
4
|
export default {
|
|
@@ -15,7 +16,7 @@ export default {
|
|
|
15
16
|
envVar: "API_KEY",
|
|
16
17
|
})
|
|
17
18
|
.demandOption(["api-key", "tunnel-id"])
|
|
18
|
-
.middleware([setBlocking]);
|
|
19
|
+
.middleware([setBlocking, configure]);
|
|
19
20
|
},
|
|
20
21
|
handler: async (argv) => {
|
|
21
22
|
rotateToken(argv);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { configure } from "../../../common/middleware/user-configuration.js";
|
|
1
2
|
import setBlocking from "../../../common/output.js";
|
|
2
3
|
import { describe, } from "../../../tunnel/services/describe/handler.js";
|
|
3
4
|
export default {
|
|
@@ -15,7 +16,7 @@ export default {
|
|
|
15
16
|
envVar: "API_KEY",
|
|
16
17
|
})
|
|
17
18
|
.demandOption(["api-key", "tunnel-id"])
|
|
18
|
-
.middleware([setBlocking]);
|
|
19
|
+
.middleware([setBlocking, configure]);
|
|
19
20
|
},
|
|
20
21
|
handler: async (argv) => {
|
|
21
22
|
describe(argv);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { configure } from "../../../common/middleware/user-configuration.js";
|
|
1
2
|
import setBlocking from "../../../common/output.js";
|
|
2
3
|
import { updateServices, } from "../../../tunnel/services/update/handler.js";
|
|
3
4
|
export default {
|
|
@@ -19,7 +20,7 @@ export default {
|
|
|
19
20
|
envVar: "API_KEY",
|
|
20
21
|
})
|
|
21
22
|
.demandOption(["api-key", "configuration-file", "tunnel-id"])
|
|
22
|
-
.middleware([setBlocking]);
|
|
23
|
+
.middleware([setBlocking, configure]);
|
|
23
24
|
},
|
|
24
25
|
handler: async (argv) => {
|
|
25
26
|
updateServices(argv);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { configure } from "../../common/middleware/user-configuration.js";
|
|
1
2
|
import setBlocking from "../../common/output.js";
|
|
3
|
+
import { YargsChecker } from "../../common/validators/lib.js";
|
|
4
|
+
import { ProjectIsSetValidator } from "../../common/validators/project-name-validator.js";
|
|
2
5
|
import { create } from "../../variable/create/handler.js";
|
|
3
6
|
export default {
|
|
4
7
|
desc: "Creates a new variable for a branch",
|
|
@@ -25,9 +28,16 @@ export default {
|
|
|
25
28
|
type: "string",
|
|
26
29
|
describe: "The API Key from Zuplo",
|
|
27
30
|
envVar: "API_KEY",
|
|
31
|
+
})
|
|
32
|
+
.option("project", {
|
|
33
|
+
type: "string",
|
|
34
|
+
describe: "The project name",
|
|
28
35
|
})
|
|
29
36
|
.demandOption(["api-key", "name", "value", "is-secret", "branch"])
|
|
30
|
-
.middleware([setBlocking])
|
|
37
|
+
.middleware([setBlocking, configure])
|
|
38
|
+
.check(async (argv) => {
|
|
39
|
+
return await new YargsChecker(new ProjectIsSetValidator()).check(argv);
|
|
40
|
+
});
|
|
31
41
|
},
|
|
32
42
|
handler: async (argv) => {
|
|
33
43
|
create(argv);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { configure } from "../../common/middleware/user-configuration.js";
|
|
1
2
|
import setBlocking from "../../common/output.js";
|
|
3
|
+
import { YargsChecker } from "../../common/validators/lib.js";
|
|
4
|
+
import { ProjectIsSetValidator } from "../../common/validators/project-name-validator.js";
|
|
2
5
|
import { update } from "../../variable/update/handler.js";
|
|
3
6
|
export default {
|
|
4
7
|
desc: "Updates an existing variable for a branch",
|
|
@@ -17,13 +20,15 @@ export default {
|
|
|
17
20
|
type: "string",
|
|
18
21
|
describe: "The branch where the variable exists",
|
|
19
22
|
})
|
|
20
|
-
.option("
|
|
23
|
+
.option("project", {
|
|
21
24
|
type: "string",
|
|
22
|
-
describe: "The
|
|
23
|
-
envVar: "API_KEY",
|
|
25
|
+
describe: "The project name",
|
|
24
26
|
})
|
|
25
27
|
.demandOption(["api-key", "name", "value", "branch"])
|
|
26
|
-
.middleware([setBlocking])
|
|
28
|
+
.middleware([setBlocking, configure])
|
|
29
|
+
.check(async (argv) => {
|
|
30
|
+
return await new YargsChecker(new ProjectIsSetValidator()).check(argv);
|
|
31
|
+
});
|
|
27
32
|
},
|
|
28
33
|
handler: async (argv) => {
|
|
29
34
|
update(argv);
|
package/dist/common/constants.js
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { parse } from "jsonc-parser";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { ZUPLO_FALLBACK_JSON_FILE, ZUPLO_PREFERRED_JSON_FILE, } from "../constants.js";
|
|
6
|
+
import { logger } from "../logger.js";
|
|
7
|
+
import { printCriticalFailureToConsoleAndExit } from "../output.js";
|
|
8
|
+
import settings from "../settings.js";
|
|
9
|
+
export async function configure(argv) {
|
|
10
|
+
const cliParametersConfiguration = { ...argv };
|
|
11
|
+
const whoAmIResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/who-am-i`, {
|
|
12
|
+
method: "GET",
|
|
13
|
+
headers: {
|
|
14
|
+
Authorization: `Bearer ${argv["api-key"]}`,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
if (whoAmIResponse.ok) {
|
|
18
|
+
const apiKeyMetadata = await whoAmIResponse.json();
|
|
19
|
+
Object.assign(argv, omitNull(apiKeyMetadata));
|
|
20
|
+
const { project: zuploJsoncProject } = await processZuploConfigurationFile();
|
|
21
|
+
if (zuploJsoncProject) {
|
|
22
|
+
argv.project = zuploJsoncProject;
|
|
23
|
+
}
|
|
24
|
+
Object.assign(argv, cliParametersConfiguration);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
logger.trace({ status: whoAmIResponse.status, statusText: whoAmIResponse.statusText }, "Failed to determine who-am-i");
|
|
28
|
+
printCriticalFailureToConsoleAndExit("Error: Failed to validate the API key. Check your API key.");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function processZuploConfigurationFile() {
|
|
32
|
+
const preferredPath = resolve(".", ZUPLO_PREFERRED_JSON_FILE);
|
|
33
|
+
const fallbackPath = resolve(".", ZUPLO_FALLBACK_JSON_FILE);
|
|
34
|
+
let fileContents = "{}";
|
|
35
|
+
if (existsSync(preferredPath)) {
|
|
36
|
+
fileContents = await readFile(preferredPath, "utf-8");
|
|
37
|
+
}
|
|
38
|
+
else if (existsSync(fallbackPath)) {
|
|
39
|
+
fileContents = await readFile(fallbackPath, "utf-8");
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
logger.trace("No zuplo.jsonc file found");
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
const errors = [];
|
|
46
|
+
const data = parse(fileContents, errors);
|
|
47
|
+
if (errors.length > 0) {
|
|
48
|
+
logger.trace(errors[0], "Failed to parse zuplo.jsonc");
|
|
49
|
+
printCriticalFailureToConsoleAndExit("Error: Failed to parse the values from zuplo.jsonc. Check your zuplo.jsonc file.");
|
|
50
|
+
}
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
let omitNull = (obj) => {
|
|
54
|
+
Object.keys(obj)
|
|
55
|
+
.filter((k) => obj[k] === null)
|
|
56
|
+
.forEach((k) => delete obj[k]);
|
|
57
|
+
return obj;
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=user-configuration.js.map
|
|
@@ -4,6 +4,7 @@ import { join } from "node:path";
|
|
|
4
4
|
import { simpleGit } from "simple-git";
|
|
5
5
|
import { TEST_IN_FOLDER } from "../constants.js";
|
|
6
6
|
import { CompositeValidator } from "./lib.js";
|
|
7
|
+
import { ProjectIsSetValidator } from "./project-name-validator.js";
|
|
7
8
|
export class NotAGitRepoError extends Error {
|
|
8
9
|
constructor() {
|
|
9
10
|
super("Invalid directory: The current directory is not a Git repository.");
|
|
@@ -41,7 +42,8 @@ export class MissingGitRemote extends Error {
|
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
export class GitVersionControlValidator {
|
|
44
|
-
async validate(
|
|
45
|
+
async validate(option) {
|
|
46
|
+
const { dir } = option;
|
|
45
47
|
try {
|
|
46
48
|
await simpleGit({ baseDir: dir }).status();
|
|
47
49
|
return { ok: true };
|
|
@@ -55,7 +57,8 @@ export class GitVersionControlValidator {
|
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
export class GitCommitValidator {
|
|
58
|
-
async validate(
|
|
60
|
+
async validate(option) {
|
|
61
|
+
const { dir } = option;
|
|
59
62
|
try {
|
|
60
63
|
const git = simpleGit({ baseDir: dir });
|
|
61
64
|
const commits = await git.log({ maxCount: 1 });
|
|
@@ -76,7 +79,8 @@ export class GitCommitValidator {
|
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
export class GitBranchValidator {
|
|
79
|
-
async validate(
|
|
82
|
+
async validate(option) {
|
|
83
|
+
const { dir } = option;
|
|
80
84
|
const git = simpleGit({ baseDir: dir });
|
|
81
85
|
const branch = await git.branch();
|
|
82
86
|
if (!branch.current) {
|
|
@@ -89,7 +93,8 @@ export class GitBranchValidator {
|
|
|
89
93
|
}
|
|
90
94
|
}
|
|
91
95
|
export class GitRemoteValidator {
|
|
92
|
-
async validate(
|
|
96
|
+
async validate(option) {
|
|
97
|
+
const { dir } = option;
|
|
93
98
|
const git = simpleGit({ baseDir: dir });
|
|
94
99
|
const remotes = await git.getRemotes(true);
|
|
95
100
|
const origin = remotes.find((r) => r.name === "origin");
|
|
@@ -103,12 +108,13 @@ export class GitRemoteValidator {
|
|
|
103
108
|
}
|
|
104
109
|
}
|
|
105
110
|
export class ZuploProjectValidator {
|
|
106
|
-
async validate(
|
|
111
|
+
async validate(options) {
|
|
112
|
+
const { dir } = options;
|
|
107
113
|
try {
|
|
108
114
|
if (existsSync(`${dir}/config/routes.json`)) {
|
|
109
115
|
return { ok: true };
|
|
110
116
|
}
|
|
111
|
-
else {
|
|
117
|
+
else if (existsSync(`${dir}/config`)) {
|
|
112
118
|
const files = readdirSync(join(dir, "config"));
|
|
113
119
|
const existingOASFiles = files.filter((file) => file.endsWith(".oas.json")).length >= 1;
|
|
114
120
|
if (existingOASFiles === true) {
|
|
@@ -129,7 +135,8 @@ export class ZuploProjectValidator {
|
|
|
129
135
|
}
|
|
130
136
|
}
|
|
131
137
|
export class ZuploProjectHasTestsValidator {
|
|
132
|
-
async validate(
|
|
138
|
+
async validate(option) {
|
|
139
|
+
const { dir } = option;
|
|
133
140
|
try {
|
|
134
141
|
if (fg.sync(`${dir}/${TEST_IN_FOLDER}/**/*.test.ts`).length >= 1) {
|
|
135
142
|
return { ok: true };
|
|
@@ -149,6 +156,6 @@ export class ZuploProjectHasTestsValidator {
|
|
|
149
156
|
}
|
|
150
157
|
}
|
|
151
158
|
}
|
|
152
|
-
export const validDeployDirectoryValidator = new CompositeValidator(new ZuploProjectValidator(), new GitVersionControlValidator(), new GitCommitValidator(), new GitBranchValidator(), new GitRemoteValidator());
|
|
159
|
+
export const validDeployDirectoryValidator = new CompositeValidator(new ZuploProjectValidator(), new GitVersionControlValidator(), new GitCommitValidator(), new GitBranchValidator(), new GitRemoteValidator(), new ProjectIsSetValidator());
|
|
153
160
|
export const validTestDirectoryValidator = new CompositeValidator(new ZuploProjectValidator(), new ZuploProjectHasTestsValidator());
|
|
154
161
|
//# sourceMappingURL=file-system-validator.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export class ProjectIsNotSet extends Error {
|
|
2
|
+
constructor() {
|
|
3
|
+
super(`Missing project name. This command requires a project to be specified. Either specify it using --project or set it in zuplo.jsonc.
|
|
4
|
+
|
|
5
|
+
zuplo.jsonc should look like this:
|
|
6
|
+
|
|
7
|
+
{
|
|
8
|
+
"version": 1,
|
|
9
|
+
"project": "<name-of-your-project>",
|
|
10
|
+
"compatibilityDate": "2023-03-14"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
`);
|
|
14
|
+
Object.setPrototypeOf(this, ProjectIsNotSet.prototype);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class ProjectIsSetValidator {
|
|
18
|
+
async validate(argv) {
|
|
19
|
+
if (!argv.project) {
|
|
20
|
+
return {
|
|
21
|
+
ok: false,
|
|
22
|
+
error: new ProjectIsNotSet(),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return { ok: true };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=project-name-validator.js.map
|
package/dist/delete/handler.js
CHANGED
|
@@ -28,46 +28,34 @@ export async function deleteZup(argv) {
|
|
|
28
28
|
logger.error(err, "Failed to parse the URL");
|
|
29
29
|
printCriticalFailureToConsoleAndExit(`Error: Failed to parse the URL: ${argv.url}. Ensure you have entered a valid URL.`);
|
|
30
30
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
31
|
+
const { account, project } = argv;
|
|
32
|
+
const deleteResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/projects/${project}/deployments/${deploymentName}`, {
|
|
33
|
+
method: "DELETE",
|
|
33
34
|
headers: {
|
|
34
35
|
Authorization: `Bearer ${argv["api-key"]}`,
|
|
35
36
|
},
|
|
36
37
|
});
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
if (deleteResponse.ok) {
|
|
46
|
-
if (argv.wait) {
|
|
47
|
-
const deleted = await pingDeployment(argv);
|
|
48
|
-
if (!deleted) {
|
|
49
|
-
logger.error(`Failed to confirm deletion of zup within alloted time frame.`);
|
|
50
|
-
printCriticalFailureToConsoleAndExit(`Error: Failed to confirm deletion of zup within alloted time frame of ${settings.MAX_POLL_RETRIES * settings.POLL_INTERVAL} ms. Your zup is still be available at ${argv.url}.`);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
printResultToConsoleAndExitGracefully(`Deleted ${argv.url}`);
|
|
54
|
-
}
|
|
38
|
+
if (deleteResponse.ok) {
|
|
39
|
+
if (argv.wait) {
|
|
40
|
+
const deleted = await pingDeployment(argv);
|
|
41
|
+
if (!deleted) {
|
|
42
|
+
logger.error(`Failed to confirm deletion of zup within alloted time frame.`);
|
|
43
|
+
printCriticalFailureToConsoleAndExit(`Error: Failed to confirm deletion of zup within alloted time frame of ${settings.MAX_POLL_RETRIES * settings.POLL_INTERVAL} ms. Your zup is still be available at ${argv.url}.`);
|
|
55
44
|
}
|
|
56
45
|
else {
|
|
57
|
-
printResultToConsoleAndExitGracefully(`
|
|
46
|
+
printResultToConsoleAndExitGracefully(`Deleted ${argv.url}`);
|
|
58
47
|
}
|
|
59
48
|
}
|
|
60
49
|
else {
|
|
61
|
-
|
|
62
|
-
status: deleteResponse.status,
|
|
63
|
-
statusText: deleteResponse.statusText,
|
|
64
|
-
}, "Failed to enqueue the deletion request");
|
|
65
|
-
printCriticalFailureToConsoleAndExit("Error: Failed to enqueue the deletion request. Try again later.");
|
|
50
|
+
printResultToConsoleAndExitGracefully(`Enqueued deletion of ${argv.url}`);
|
|
66
51
|
}
|
|
67
52
|
}
|
|
68
53
|
else {
|
|
69
|
-
logger.error({
|
|
70
|
-
|
|
54
|
+
logger.error({
|
|
55
|
+
status: deleteResponse.status,
|
|
56
|
+
statusText: deleteResponse.statusText,
|
|
57
|
+
}, "Failed to enqueue the deletion request");
|
|
58
|
+
printCriticalFailureToConsoleAndExit("Error: Failed to enqueue the deletion request. Try again later.");
|
|
71
59
|
}
|
|
72
60
|
}
|
|
73
61
|
//# sourceMappingURL=handler.js.map
|
package/dist/deploy/handler.js
CHANGED
|
@@ -2,60 +2,48 @@ import { parse } from "path";
|
|
|
2
2
|
import { logger } from "../common/logger.js";
|
|
3
3
|
import { printCriticalFailureToConsoleAndExit, printDiagnosticsToConsole, printResultToConsoleAndExitGracefully, } from "../common/output.js";
|
|
4
4
|
import settings from "../common/settings.js";
|
|
5
|
-
import {
|
|
5
|
+
import { ARCHIVE_EXTENSION, archive } from "./archive.js";
|
|
6
6
|
import { upload } from "./file-upload.js";
|
|
7
7
|
import { pollDeployment } from "./poll-deployment.js";
|
|
8
8
|
export async function deploy(argv) {
|
|
9
9
|
const archiveMetadata = await archive(argv);
|
|
10
10
|
logger.info(`Tarball created locally at ${archiveMetadata}`);
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const { account, project } = argv;
|
|
12
|
+
const uploadUrlResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/projects/${project}/sources`, {
|
|
13
|
+
method: "POST",
|
|
13
14
|
headers: {
|
|
14
15
|
Authorization: `Bearer ${argv["api-key"]}`,
|
|
15
16
|
},
|
|
16
17
|
});
|
|
17
|
-
if (
|
|
18
|
-
const {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const { uploadUrl } = await uploadUrlResponse.json();
|
|
27
|
-
const uploadResponse = await upload(archiveMetadata.tarball, uploadUrl);
|
|
28
|
-
if (uploadResponse.ok) {
|
|
29
|
-
printDiagnosticsToConsole(`Deploying the current branch ${archiveMetadata.metadata.branch} to project ${project} on account ${account}...`);
|
|
30
|
-
const fileId = parse(new URL(uploadUrl).pathname).base.replace(ARCHIVE_EXTENSION, "");
|
|
31
|
-
const { url, steps, buildResult } = await pollDeployment(argv, fileId, account, project);
|
|
32
|
-
if (url) {
|
|
33
|
-
printResultToConsoleAndExitGracefully(`Deployed to ${url}`);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
const diagnostics = buildResult ?? steps;
|
|
37
|
-
printCriticalFailureToConsoleAndExit(`Failed to deploy the current branch ${archiveMetadata.metadata.branch} to project ${project} on account ${account}. Here's the diagnostics: ${JSON.stringify(diagnostics, null, 2)}`);
|
|
38
|
-
}
|
|
18
|
+
if (uploadUrlResponse.ok) {
|
|
19
|
+
const { uploadUrl } = await uploadUrlResponse.json();
|
|
20
|
+
const uploadResponse = await upload(archiveMetadata.tarball, uploadUrl);
|
|
21
|
+
if (uploadResponse.ok) {
|
|
22
|
+
printDiagnosticsToConsole(`Deploying the current branch ${archiveMetadata.metadata.branch} to project ${project} on account ${account}...`);
|
|
23
|
+
const fileId = parse(new URL(uploadUrl).pathname).base.replace(ARCHIVE_EXTENSION, "");
|
|
24
|
+
const { url, steps, buildResult } = await pollDeployment(argv, fileId, account, project);
|
|
25
|
+
if (url) {
|
|
26
|
+
printResultToConsoleAndExitGracefully(`Deployed to ${url}`);
|
|
39
27
|
}
|
|
40
28
|
else {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
statusText: uploadResponse.statusText,
|
|
44
|
-
}, "Failed to upload source to cloud storage");
|
|
45
|
-
printDiagnosticsToConsole("Error: Failed to upload source to cloud storage. Try again later.");
|
|
29
|
+
const diagnostics = buildResult ?? steps;
|
|
30
|
+
printCriticalFailureToConsoleAndExit(`Failed to deploy the current branch ${archiveMetadata.metadata.branch} to project ${project} on account ${account}. Here's the diagnostics: ${JSON.stringify(diagnostics, null, 2)}`);
|
|
46
31
|
}
|
|
47
32
|
}
|
|
48
33
|
else {
|
|
49
34
|
logger.error({
|
|
50
|
-
status:
|
|
51
|
-
statusText:
|
|
52
|
-
}, "Failed to
|
|
53
|
-
|
|
35
|
+
status: uploadResponse.status,
|
|
36
|
+
statusText: uploadResponse.statusText,
|
|
37
|
+
}, "Failed to upload source to cloud storage");
|
|
38
|
+
printDiagnosticsToConsole("Error: Failed to upload source to cloud storage. Try again later.");
|
|
54
39
|
}
|
|
55
40
|
}
|
|
56
41
|
else {
|
|
57
|
-
logger.error({
|
|
58
|
-
|
|
42
|
+
logger.error({
|
|
43
|
+
status: uploadUrlResponse.status,
|
|
44
|
+
statusText: uploadUrlResponse.statusText,
|
|
45
|
+
}, "Failed to retrieve uploadUrl");
|
|
46
|
+
printCriticalFailureToConsoleAndExit("Error: Failed to determine where to upload your files. Try again later.");
|
|
59
47
|
}
|
|
60
48
|
}
|
|
61
49
|
//# sourceMappingURL=handler.js.map
|
package/dist/list/handler.js
CHANGED
|
@@ -1,37 +1,25 @@
|
|
|
1
1
|
import { logger } from "../common/logger.js";
|
|
2
|
-
import {
|
|
2
|
+
import { printDiagnosticsToConsole, printResultToConsoleAndExitGracefully, } from "../common/output.js";
|
|
3
3
|
import settings from "../common/settings.js";
|
|
4
4
|
export async function list(argv) {
|
|
5
|
-
const
|
|
5
|
+
const { account, project } = argv;
|
|
6
|
+
const listResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/projects/${project}/deployments`, {
|
|
6
7
|
method: "GET",
|
|
7
8
|
headers: {
|
|
8
9
|
Authorization: `Bearer ${argv["api-key"]}`,
|
|
9
10
|
},
|
|
10
11
|
});
|
|
11
|
-
if (
|
|
12
|
-
const {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
headers: {
|
|
16
|
-
Authorization: `Bearer ${argv["api-key"]}`,
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
if (listResponse.ok) {
|
|
20
|
-
const { data: deployments } = await listResponse.json();
|
|
21
|
-
const output = deployments.map((deployment) => deployment.url).join("\n");
|
|
22
|
-
printResultToConsoleAndExitGracefully(output);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
logger.error({
|
|
26
|
-
status: listResponse.status,
|
|
27
|
-
statusText: listResponse.statusText,
|
|
28
|
-
}, "Failed to list deployed zups");
|
|
29
|
-
printDiagnosticsToConsole("Error: Failed to list deployed zups. Try again later.");
|
|
30
|
-
}
|
|
12
|
+
if (listResponse.ok) {
|
|
13
|
+
const { data: deployments } = await listResponse.json();
|
|
14
|
+
const output = deployments.map((deployment) => deployment.url).join("\n");
|
|
15
|
+
printResultToConsoleAndExitGracefully(output);
|
|
31
16
|
}
|
|
32
17
|
else {
|
|
33
|
-
logger.error({
|
|
34
|
-
|
|
18
|
+
logger.error({
|
|
19
|
+
status: listResponse.status,
|
|
20
|
+
statusText: listResponse.statusText,
|
|
21
|
+
}, "Failed to list deployed zups");
|
|
22
|
+
printDiagnosticsToConsole("Error: Failed to list deployed zups. Try again later.");
|
|
35
23
|
}
|
|
36
24
|
}
|
|
37
25
|
//# sourceMappingURL=handler.js.map
|
|
@@ -1,39 +1,27 @@
|
|
|
1
1
|
import { logger } from "../../common/logger.js";
|
|
2
|
-
import {
|
|
2
|
+
import { printDiagnosticsToConsole, printTableToConsoleAndExitGracefully, } from "../../common/output.js";
|
|
3
3
|
import settings from "../../common/settings.js";
|
|
4
4
|
export async function create(argv) {
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const { account } = argv;
|
|
6
|
+
const createResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/tunnels`, {
|
|
7
|
+
method: "POST",
|
|
7
8
|
headers: {
|
|
8
9
|
Authorization: `Bearer ${argv["api-key"]}`,
|
|
10
|
+
"Content-Type": "application/json",
|
|
9
11
|
},
|
|
12
|
+
body: JSON.stringify({ name: argv["tunnel-name"] }),
|
|
10
13
|
});
|
|
11
|
-
if (
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
method: "POST",
|
|
15
|
-
headers: {
|
|
16
|
-
Authorization: `Bearer ${argv["api-key"]}`,
|
|
17
|
-
"Content-Type": "application/json",
|
|
18
|
-
},
|
|
19
|
-
body: JSON.stringify({ name: argv["tunnel-name"] }),
|
|
20
|
-
});
|
|
21
|
-
if (createResponse.ok) {
|
|
22
|
-
const tunnel = await createResponse.json();
|
|
23
|
-
printTableToConsoleAndExitGracefully(tunnel);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
logger.error({
|
|
27
|
-
status: createResponse.status,
|
|
28
|
-
statusText: createResponse.statusText,
|
|
29
|
-
response: await createResponse.text(),
|
|
30
|
-
}, "Failed to create tunnel for account");
|
|
31
|
-
printDiagnosticsToConsole("Error: Failed to create tunnel for your account. Check the arguments.");
|
|
32
|
-
}
|
|
14
|
+
if (createResponse.ok) {
|
|
15
|
+
const tunnel = await createResponse.json();
|
|
16
|
+
printTableToConsoleAndExitGracefully(tunnel);
|
|
33
17
|
}
|
|
34
18
|
else {
|
|
35
|
-
logger.error({
|
|
36
|
-
|
|
19
|
+
logger.error({
|
|
20
|
+
status: createResponse.status,
|
|
21
|
+
statusText: createResponse.statusText,
|
|
22
|
+
response: await createResponse.text(),
|
|
23
|
+
}, "Failed to create tunnel for account");
|
|
24
|
+
printDiagnosticsToConsole("Error: Failed to create tunnel for your account. Check the arguments.");
|
|
37
25
|
}
|
|
38
26
|
}
|
|
39
27
|
//# sourceMappingURL=handler.js.map
|
|
@@ -3,48 +3,36 @@ import { printCriticalFailureToConsoleAndExit, printDiagnosticsToConsole, printR
|
|
|
3
3
|
import settings from "../../common/settings.js";
|
|
4
4
|
import { pollTeardownOperation } from "./poll-teardown-operation.js";
|
|
5
5
|
export async function deleteTunnel(argv) {
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const { account } = argv;
|
|
7
|
+
const deleteResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/tunnels/${argv["tunnel-id"]}`, {
|
|
8
|
+
method: "DELETE",
|
|
8
9
|
headers: {
|
|
9
10
|
Authorization: `Bearer ${argv["api-key"]}`,
|
|
10
11
|
},
|
|
11
12
|
});
|
|
12
|
-
if (
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
if (deleteResponse.ok) {
|
|
14
|
+
const teardownOperation = await deleteResponse.json();
|
|
15
|
+
printDiagnosticsToConsole(`Deleting tunnel ${argv["tunnel-id"]} on account ${account}...`);
|
|
16
|
+
const polledTearDownOperation = await pollTeardownOperation({
|
|
17
|
+
argv,
|
|
18
|
+
account,
|
|
19
|
+
teardownOperationId: teardownOperation.id,
|
|
19
20
|
});
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
printDiagnosticsToConsole(`Deleting tunnel ${argv["tunnel-id"]} on account ${account}...`);
|
|
23
|
-
const polledTearDownOperation = await pollTeardownOperation({
|
|
24
|
-
argv,
|
|
25
|
-
account,
|
|
26
|
-
teardownOperationId: teardownOperation.id,
|
|
27
|
-
});
|
|
28
|
-
if (polledTearDownOperation.status === "success") {
|
|
29
|
-
printResultToConsoleAndExitGracefully(`Tunnel ${argv["tunnel-id"]} deleted successfully.`);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
printDiagnosticsToConsole(polledTearDownOperation.details);
|
|
33
|
-
printCriticalFailureToConsoleAndExit(`Tunnel ${argv["tunnel-id"]} failed to delete. Here's the error: ${polledTearDownOperation.message}`);
|
|
34
|
-
}
|
|
21
|
+
if (polledTearDownOperation.status === "success") {
|
|
22
|
+
printResultToConsoleAndExitGracefully(`Tunnel ${argv["tunnel-id"]} deleted successfully.`);
|
|
35
23
|
}
|
|
36
24
|
else {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
statusText: deleteResponse.statusText,
|
|
40
|
-
response: await deleteResponse.text(),
|
|
41
|
-
}, "Failed to delete tunnel for account");
|
|
42
|
-
printDiagnosticsToConsole("Error: Failed to delete the tunnel for your account. Check the arguments.");
|
|
25
|
+
printDiagnosticsToConsole(polledTearDownOperation.details);
|
|
26
|
+
printCriticalFailureToConsoleAndExit(`Tunnel ${argv["tunnel-id"]} failed to delete. Here's the error: ${polledTearDownOperation.message}`);
|
|
43
27
|
}
|
|
44
28
|
}
|
|
45
29
|
else {
|
|
46
|
-
logger.error({
|
|
47
|
-
|
|
30
|
+
logger.error({
|
|
31
|
+
status: deleteResponse.status,
|
|
32
|
+
statusText: deleteResponse.statusText,
|
|
33
|
+
response: await deleteResponse.text(),
|
|
34
|
+
}, "Failed to delete tunnel for account");
|
|
35
|
+
printDiagnosticsToConsole("Error: Failed to delete the tunnel for your account. Check the arguments.");
|
|
48
36
|
}
|
|
49
37
|
}
|
|
50
38
|
//# sourceMappingURL=handler.js.map
|
|
@@ -1,37 +1,25 @@
|
|
|
1
1
|
import { logger } from "../../common/logger.js";
|
|
2
|
-
import {
|
|
2
|
+
import { printDiagnosticsToConsole, printTableToConsoleAndExitGracefully, } from "../../common/output.js";
|
|
3
3
|
import settings from "../../common/settings.js";
|
|
4
4
|
export async function describe(argv) {
|
|
5
|
-
const
|
|
5
|
+
const { account } = argv;
|
|
6
|
+
const describeResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/tunnels/${argv["tunnel-id"]}`, {
|
|
6
7
|
method: "GET",
|
|
7
8
|
headers: {
|
|
8
9
|
Authorization: `Bearer ${argv["api-key"]}`,
|
|
9
10
|
},
|
|
10
11
|
});
|
|
11
|
-
if (
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
method: "GET",
|
|
15
|
-
headers: {
|
|
16
|
-
Authorization: `Bearer ${argv["api-key"]}`,
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
if (describeResponse.ok) {
|
|
20
|
-
const tunnel = await describeResponse.json();
|
|
21
|
-
printTableToConsoleAndExitGracefully(tunnel);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
logger.error({
|
|
25
|
-
status: describeResponse.status,
|
|
26
|
-
statusText: describeResponse.statusText,
|
|
27
|
-
response: await describeResponse.text(),
|
|
28
|
-
}, "Failed to describe tunnel for account");
|
|
29
|
-
printDiagnosticsToConsole("Error: Failed to describe tunnel for your account. Check the arguments.");
|
|
30
|
-
}
|
|
12
|
+
if (describeResponse.ok) {
|
|
13
|
+
const tunnel = await describeResponse.json();
|
|
14
|
+
printTableToConsoleAndExitGracefully(tunnel);
|
|
31
15
|
}
|
|
32
16
|
else {
|
|
33
|
-
logger.error({
|
|
34
|
-
|
|
17
|
+
logger.error({
|
|
18
|
+
status: describeResponse.status,
|
|
19
|
+
statusText: describeResponse.statusText,
|
|
20
|
+
response: await describeResponse.text(),
|
|
21
|
+
}, "Failed to describe tunnel for account");
|
|
22
|
+
printDiagnosticsToConsole("Error: Failed to describe tunnel for your account. Check the arguments.");
|
|
35
23
|
}
|
|
36
24
|
}
|
|
37
25
|
//# sourceMappingURL=handler.js.map
|
|
@@ -1,46 +1,34 @@
|
|
|
1
1
|
import { logger } from "../../common/logger.js";
|
|
2
|
-
import {
|
|
2
|
+
import { printDiagnosticsToConsole, printResultToConsoleAndExitGracefully, printTableToConsoleAndExitGracefully, } from "../../common/output.js";
|
|
3
3
|
import settings from "../../common/settings.js";
|
|
4
4
|
export async function list(argv) {
|
|
5
|
-
const
|
|
5
|
+
const { account } = await argv;
|
|
6
|
+
const listResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/tunnels`, {
|
|
6
7
|
method: "GET",
|
|
7
8
|
headers: {
|
|
8
9
|
Authorization: `Bearer ${argv["api-key"]}`,
|
|
9
10
|
},
|
|
10
11
|
});
|
|
11
|
-
if (
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Authorization: `Bearer ${argv["api-key"]}`,
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
if (listResponse.ok) {
|
|
20
|
-
const tunnels = await listResponse.json();
|
|
21
|
-
if (tunnels.data.length === 0) {
|
|
22
|
-
const output = "No tunnels found";
|
|
23
|
-
printResultToConsoleAndExitGracefully(output);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
const table = tunnels.data.map((tunnel) => {
|
|
27
|
-
return { "tunnel-id": tunnel.id, name: tunnel.name };
|
|
28
|
-
});
|
|
29
|
-
printTableToConsoleAndExitGracefully(table);
|
|
30
|
-
}
|
|
12
|
+
if (listResponse.ok) {
|
|
13
|
+
const tunnels = await listResponse.json();
|
|
14
|
+
if (tunnels.data.length === 0) {
|
|
15
|
+
const output = "No tunnels found";
|
|
16
|
+
printResultToConsoleAndExitGracefully(output);
|
|
31
17
|
}
|
|
32
18
|
else {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}, "Failed to list tunnels for account");
|
|
38
|
-
printDiagnosticsToConsole("Error: Failed to list tunnels for your account. Try again later.");
|
|
19
|
+
const table = tunnels.data.map((tunnel) => {
|
|
20
|
+
return { "tunnel-id": tunnel.id, name: tunnel.name };
|
|
21
|
+
});
|
|
22
|
+
printTableToConsoleAndExitGracefully(table);
|
|
39
23
|
}
|
|
40
24
|
}
|
|
41
25
|
else {
|
|
42
|
-
logger.error({
|
|
43
|
-
|
|
26
|
+
logger.error({
|
|
27
|
+
status: listResponse.status,
|
|
28
|
+
statusText: listResponse.statusText,
|
|
29
|
+
response: await listResponse.text(),
|
|
30
|
+
}, "Failed to list tunnels for account");
|
|
31
|
+
printDiagnosticsToConsole("Error: Failed to list tunnels for your account. Try again later.");
|
|
44
32
|
}
|
|
45
33
|
}
|
|
46
34
|
//# sourceMappingURL=handler.js.map
|
|
@@ -1,37 +1,25 @@
|
|
|
1
1
|
import { logger } from "../../common/logger.js";
|
|
2
|
-
import {
|
|
2
|
+
import { printDiagnosticsToConsole, printTableToConsoleAndExitGracefully, } from "../../common/output.js";
|
|
3
3
|
import settings from "../../common/settings.js";
|
|
4
4
|
export async function rotateToken(argv) {
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const { account } = argv;
|
|
6
|
+
const rotateResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/tunnels/${argv["tunnel-id"]}/$rotate-token`, {
|
|
7
|
+
method: "POST",
|
|
7
8
|
headers: {
|
|
8
9
|
Authorization: `Bearer ${argv["api-key"]}`,
|
|
9
10
|
},
|
|
10
11
|
});
|
|
11
|
-
if (
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
method: "POST",
|
|
15
|
-
headers: {
|
|
16
|
-
Authorization: `Bearer ${argv["api-key"]}`,
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
if (rotateResponse.ok) {
|
|
20
|
-
const tunnel = await rotateResponse.json();
|
|
21
|
-
printTableToConsoleAndExitGracefully(tunnel);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
logger.error({
|
|
25
|
-
status: rotateResponse.status,
|
|
26
|
-
statusText: rotateResponse.statusText,
|
|
27
|
-
response: await rotateResponse.text(),
|
|
28
|
-
}, "Failed to rotate token for tunnel");
|
|
29
|
-
printDiagnosticsToConsole("Error: Failed to rotate token for tunnel. Check the arguments.");
|
|
30
|
-
}
|
|
12
|
+
if (rotateResponse.ok) {
|
|
13
|
+
const tunnel = await rotateResponse.json();
|
|
14
|
+
printTableToConsoleAndExitGracefully(tunnel);
|
|
31
15
|
}
|
|
32
16
|
else {
|
|
33
|
-
logger.error({
|
|
34
|
-
|
|
17
|
+
logger.error({
|
|
18
|
+
status: rotateResponse.status,
|
|
19
|
+
statusText: rotateResponse.statusText,
|
|
20
|
+
response: await rotateResponse.text(),
|
|
21
|
+
}, "Failed to rotate token for tunnel");
|
|
22
|
+
printDiagnosticsToConsole("Error: Failed to rotate token for tunnel. Check the arguments.");
|
|
35
23
|
}
|
|
36
24
|
}
|
|
37
25
|
//# sourceMappingURL=handler.js.map
|
|
@@ -1,37 +1,25 @@
|
|
|
1
1
|
import { logger } from "../../../common/logger.js";
|
|
2
|
-
import {
|
|
2
|
+
import { printDiagnosticsToConsole, printResultToConsoleAndExitGracefully, } from "../../../common/output.js";
|
|
3
3
|
import settings from "../../../common/settings.js";
|
|
4
4
|
export async function describe(argv) {
|
|
5
|
-
const
|
|
5
|
+
const { account } = argv;
|
|
6
|
+
const describeResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/tunnels/${argv["tunnel-id"]}/services-configuration`, {
|
|
6
7
|
method: "GET",
|
|
7
8
|
headers: {
|
|
8
9
|
Authorization: `Bearer ${argv["api-key"]}`,
|
|
9
10
|
},
|
|
10
11
|
});
|
|
11
|
-
if (
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
method: "GET",
|
|
15
|
-
headers: {
|
|
16
|
-
Authorization: `Bearer ${argv["api-key"]}`,
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
if (describeResponse.ok) {
|
|
20
|
-
const tunnel = await describeResponse.json();
|
|
21
|
-
printResultToConsoleAndExitGracefully(JSON.stringify(tunnel, null, 2));
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
logger.error({
|
|
25
|
-
status: describeResponse.status,
|
|
26
|
-
statusText: describeResponse.statusText,
|
|
27
|
-
response: await describeResponse.text(),
|
|
28
|
-
}, "Failed to describe services for tunnel");
|
|
29
|
-
printDiagnosticsToConsole("Error: Failed to describe the services for your tunnel. Check the arguments.");
|
|
30
|
-
}
|
|
12
|
+
if (describeResponse.ok) {
|
|
13
|
+
const tunnel = await describeResponse.json();
|
|
14
|
+
printResultToConsoleAndExitGracefully(JSON.stringify(tunnel, null, 2));
|
|
31
15
|
}
|
|
32
16
|
else {
|
|
33
|
-
logger.error({
|
|
34
|
-
|
|
17
|
+
logger.error({
|
|
18
|
+
status: describeResponse.status,
|
|
19
|
+
statusText: describeResponse.statusText,
|
|
20
|
+
response: await describeResponse.text(),
|
|
21
|
+
}, "Failed to describe services for tunnel");
|
|
22
|
+
printDiagnosticsToConsole("Error: Failed to describe the services for your tunnel. Check the arguments.");
|
|
35
23
|
}
|
|
36
24
|
}
|
|
37
25
|
//# sourceMappingURL=handler.js.map
|
|
@@ -4,57 +4,45 @@ import { printCriticalFailureToConsoleAndExit, printDiagnosticsToConsole, printR
|
|
|
4
4
|
import settings from "../../../common/settings.js";
|
|
5
5
|
import { pollProvisioningOperation } from "./poll-provisioning-operations.js";
|
|
6
6
|
export async function updateServices(argv) {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
let contents;
|
|
8
|
+
try {
|
|
9
|
+
contents = await readFile(argv["configuration-file"], "utf-8");
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
printCriticalFailureToConsoleAndExit(`Error reading the configuration file at ${argv["configuration-file"]}: ${err.message}}`);
|
|
13
|
+
}
|
|
14
|
+
const { account } = argv;
|
|
15
|
+
const deleteResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/tunnels/${argv["tunnel-id"]}/services-configuration`, {
|
|
16
|
+
method: "PUT",
|
|
9
17
|
headers: {
|
|
10
18
|
Authorization: `Bearer ${argv["api-key"]}`,
|
|
19
|
+
"Content-Type": "application/json",
|
|
11
20
|
},
|
|
21
|
+
body: contents,
|
|
12
22
|
});
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
const { account } = await whoAmIResponse.json();
|
|
22
|
-
const deleteResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/tunnels/${argv["tunnel-id"]}/services-configuration`, {
|
|
23
|
-
method: "PUT",
|
|
24
|
-
headers: {
|
|
25
|
-
Authorization: `Bearer ${argv["api-key"]}`,
|
|
26
|
-
"Content-Type": "application/json",
|
|
27
|
-
},
|
|
28
|
-
body: contents,
|
|
23
|
+
if (deleteResponse.ok) {
|
|
24
|
+
const provisioningOperation = await deleteResponse.json();
|
|
25
|
+
printDiagnosticsToConsole(`Updating services on tunnel ${argv["tunnel-id"]} on account ${account}...`);
|
|
26
|
+
const polledProvisioningOperation = await pollProvisioningOperation({
|
|
27
|
+
argv,
|
|
28
|
+
account,
|
|
29
|
+
provisioningOperationId: provisioningOperation.id,
|
|
29
30
|
});
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
printDiagnosticsToConsole(`Updating services on tunnel ${argv["tunnel-id"]} on account ${account}...`);
|
|
33
|
-
const polledProvisioningOperation = await pollProvisioningOperation({
|
|
34
|
-
argv,
|
|
35
|
-
account,
|
|
36
|
-
provisioningOperationId: provisioningOperation.id,
|
|
37
|
-
});
|
|
38
|
-
if (polledProvisioningOperation.status === "success") {
|
|
39
|
-
printResultToConsoleAndExitGracefully(`Tunnel ${argv["tunnel-id"]} updated successfully.`);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
printDiagnosticsToConsole(polledProvisioningOperation.details);
|
|
43
|
-
printCriticalFailureToConsoleAndExit(`Tunnel ${argv["tunnel-id"]} failed to update. Here's the error: ${polledProvisioningOperation.message}`);
|
|
44
|
-
}
|
|
31
|
+
if (polledProvisioningOperation.status === "success") {
|
|
32
|
+
printResultToConsoleAndExitGracefully(`Tunnel ${argv["tunnel-id"]} updated successfully.`);
|
|
45
33
|
}
|
|
46
34
|
else {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
statusText: deleteResponse.statusText,
|
|
50
|
-
response: await deleteResponse.text(),
|
|
51
|
-
}, "Failed to update tunnel for account");
|
|
52
|
-
printDiagnosticsToConsole("Error: Failed to update the tunnel for your account. Check the arguments.");
|
|
35
|
+
printDiagnosticsToConsole(polledProvisioningOperation.details);
|
|
36
|
+
printCriticalFailureToConsoleAndExit(`Tunnel ${argv["tunnel-id"]} failed to update. Here's the error: ${polledProvisioningOperation.message}`);
|
|
53
37
|
}
|
|
54
38
|
}
|
|
55
39
|
else {
|
|
56
|
-
logger.error({
|
|
57
|
-
|
|
40
|
+
logger.error({
|
|
41
|
+
status: deleteResponse.status,
|
|
42
|
+
statusText: deleteResponse.statusText,
|
|
43
|
+
response: await deleteResponse.text(),
|
|
44
|
+
}, "Failed to update tunnel for account");
|
|
45
|
+
printDiagnosticsToConsole("Error: Failed to update the tunnel for your account. Check the arguments.");
|
|
58
46
|
}
|
|
59
47
|
}
|
|
60
48
|
//# sourceMappingURL=handler.js.map
|
|
@@ -1,43 +1,31 @@
|
|
|
1
1
|
import { logger } from "../../common/logger.js";
|
|
2
|
-
import {
|
|
2
|
+
import { printDiagnosticsToConsole, printResultToConsole, } from "../../common/output.js";
|
|
3
3
|
import settings from "../../common/settings.js";
|
|
4
4
|
export async function create(argv) {
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const { account, project } = argv;
|
|
6
|
+
const createResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/projects/${project}/branches/${encodeURIComponent(argv["branch"])}/variables`, {
|
|
7
|
+
method: "POST",
|
|
7
8
|
headers: {
|
|
8
9
|
Authorization: `Bearer ${argv["api-key"]}`,
|
|
10
|
+
"Content-Type": "application/json",
|
|
9
11
|
},
|
|
12
|
+
body: JSON.stringify({
|
|
13
|
+
name: argv["name"],
|
|
14
|
+
isSecret: argv["is-secret"],
|
|
15
|
+
value: argv["value"],
|
|
16
|
+
}),
|
|
10
17
|
});
|
|
11
|
-
if (
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
headers: {
|
|
16
|
-
Authorization: `Bearer ${argv["api-key"]}`,
|
|
17
|
-
"Content-Type": "application/json",
|
|
18
|
-
},
|
|
19
|
-
body: JSON.stringify({
|
|
20
|
-
name: argv["name"],
|
|
21
|
-
isSecret: argv["is-secret"],
|
|
22
|
-
value: argv["value"],
|
|
23
|
-
}),
|
|
24
|
-
});
|
|
25
|
-
if (createResponse.ok) {
|
|
26
|
-
const variable = await createResponse.json();
|
|
27
|
-
printResultToConsole(variable.name + " created successfully");
|
|
28
|
-
console.log(variable);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
logger.error({
|
|
32
|
-
status: createResponse.status,
|
|
33
|
-
statusText: createResponse.statusText,
|
|
34
|
-
}, "Failed to create variable");
|
|
35
|
-
printDiagnosticsToConsole("Error: Failed to create variable. Check the arguments.");
|
|
36
|
-
}
|
|
18
|
+
if (createResponse.ok) {
|
|
19
|
+
const variable = await createResponse.json();
|
|
20
|
+
printResultToConsole(variable.name + " created successfully");
|
|
21
|
+
console.log(variable);
|
|
37
22
|
}
|
|
38
23
|
else {
|
|
39
|
-
logger.error({
|
|
40
|
-
|
|
24
|
+
logger.error({
|
|
25
|
+
status: createResponse.status,
|
|
26
|
+
statusText: createResponse.statusText,
|
|
27
|
+
}, "Failed to create variable");
|
|
28
|
+
printDiagnosticsToConsole("Error: Failed to create variable. Check the arguments.");
|
|
41
29
|
}
|
|
42
30
|
}
|
|
43
31
|
//# sourceMappingURL=handler.js.map
|
|
@@ -1,41 +1,29 @@
|
|
|
1
1
|
import { logger } from "../../common/logger.js";
|
|
2
|
-
import {
|
|
2
|
+
import { printDiagnosticsToConsole, printResultToConsole, } from "../../common/output.js";
|
|
3
3
|
import settings from "../../common/settings.js";
|
|
4
4
|
export async function update(argv) {
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const { account, project } = argv;
|
|
6
|
+
const updateResponse = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/projects/${project}/branches/${encodeURIComponent(argv["branch"])}/variables/${encodeURIComponent(argv["name"])}`, {
|
|
7
|
+
method: "PATCH",
|
|
7
8
|
headers: {
|
|
8
9
|
Authorization: `Bearer ${argv["api-key"]}`,
|
|
10
|
+
"Content-Type": "application/json",
|
|
9
11
|
},
|
|
12
|
+
body: JSON.stringify({
|
|
13
|
+
value: argv["value"],
|
|
14
|
+
}),
|
|
10
15
|
});
|
|
11
|
-
if (
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
headers: {
|
|
16
|
-
Authorization: `Bearer ${argv["api-key"]}`,
|
|
17
|
-
"Content-Type": "application/json",
|
|
18
|
-
},
|
|
19
|
-
body: JSON.stringify({
|
|
20
|
-
value: argv["value"],
|
|
21
|
-
}),
|
|
22
|
-
});
|
|
23
|
-
if (updateResponse.ok) {
|
|
24
|
-
const variable = await updateResponse.json();
|
|
25
|
-
printResultToConsole(variable.name + " updated successfully");
|
|
26
|
-
console.log(variable);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
logger.error({
|
|
30
|
-
status: updateResponse.status,
|
|
31
|
-
statusText: updateResponse.statusText,
|
|
32
|
-
}, "Failed to update variable");
|
|
33
|
-
printDiagnosticsToConsole("Error: Failed to update variable. Check the arguments.");
|
|
34
|
-
}
|
|
16
|
+
if (updateResponse.ok) {
|
|
17
|
+
const variable = await updateResponse.json();
|
|
18
|
+
printResultToConsole(variable.name + " updated successfully");
|
|
19
|
+
console.log(variable);
|
|
35
20
|
}
|
|
36
21
|
else {
|
|
37
|
-
logger.error({
|
|
38
|
-
|
|
22
|
+
logger.error({
|
|
23
|
+
status: updateResponse.status,
|
|
24
|
+
statusText: updateResponse.statusText,
|
|
25
|
+
}, "Failed to update variable");
|
|
26
|
+
printDiagnosticsToConsole("Error: Failed to update variable. Check the arguments.");
|
|
39
27
|
}
|
|
40
28
|
}
|
|
41
29
|
//# sourceMappingURL=handler.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zuplo/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.43.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": "https://github.com/zuplo/cli",
|
|
6
6
|
"author": "Zuplo, Inc.",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"execa": "^6.1.0",
|
|
57
57
|
"fast-glob": "^3.2.12",
|
|
58
58
|
"ignore": "^5.2.4",
|
|
59
|
+
"jsonc-parser": "^3.2.0",
|
|
59
60
|
"pino": "^8.11.0",
|
|
60
61
|
"pino-pretty": "^9.4.0",
|
|
61
62
|
"prettier": "^2.8.7",
|