@solti/cli 0.0.0-stage → 0.1.2
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/LICENSE +21 -0
- package/README.md +57 -2
- package/dist/api/client.js +166 -0
- package/dist/auth/oauth.js +342 -0
- package/dist/commands/account.js +87 -0
- package/dist/commands/connection.js +59 -0
- package/dist/commands/cronjob.js +81 -0
- package/dist/commands/job.js +155 -0
- package/dist/commands/key.js +32 -0
- package/dist/commands/organization.js +59 -0
- package/dist/commands/profile.js +83 -0
- package/dist/commands/project.js +101 -0
- package/dist/commands/resource.js +26 -0
- package/dist/config/paths.js +25 -0
- package/dist/config/store.js +97 -0
- package/dist/index.js +329 -0
- package/dist/lib/parse.js +136 -0
- package/package.json +29 -4
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { accountsDir, activeStorePath, authFilePath, profileConfigPath, profilesDir, } from "./paths.js";
|
|
4
|
+
async function readJson(filePath) {
|
|
5
|
+
try {
|
|
6
|
+
const raw = await fs.readFile(filePath, "utf8");
|
|
7
|
+
return JSON.parse(raw);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
async function writeJson(filePath, value, mode) {
|
|
14
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
15
|
+
await fs.writeFile(filePath, JSON.stringify(value, null, 2) + "\n", { mode });
|
|
16
|
+
}
|
|
17
|
+
// --- active store -----------------------------------------------------------
|
|
18
|
+
export async function readActive() {
|
|
19
|
+
return (await readJson(activeStorePath)) ?? {};
|
|
20
|
+
}
|
|
21
|
+
export async function writeActive(store) {
|
|
22
|
+
await writeJson(activeStorePath, store);
|
|
23
|
+
}
|
|
24
|
+
export async function getActiveAccount() {
|
|
25
|
+
return (await readActive()).active_account ?? null;
|
|
26
|
+
}
|
|
27
|
+
export async function getActiveProfileName() {
|
|
28
|
+
return (await readActive()).active_profile ?? null;
|
|
29
|
+
}
|
|
30
|
+
// --- accounts ---------------------------------------------------------------
|
|
31
|
+
export async function listAccounts() {
|
|
32
|
+
try {
|
|
33
|
+
const entries = await fs.readdir(accountsDir, { withFileTypes: true });
|
|
34
|
+
return entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export async function readAuth(email) {
|
|
41
|
+
return readJson(authFilePath(email));
|
|
42
|
+
}
|
|
43
|
+
export async function writeAuth(email, auth) {
|
|
44
|
+
// Credentials are stored with owner-only permissions (0600).
|
|
45
|
+
await writeJson(authFilePath(email), { ...auth, email }, 0o600);
|
|
46
|
+
}
|
|
47
|
+
export async function deleteAuth(email) {
|
|
48
|
+
try {
|
|
49
|
+
await fs.unlink(authFilePath(email));
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// already gone
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// --- profiles ---------------------------------------------------------------
|
|
56
|
+
export async function listProfiles(email) {
|
|
57
|
+
try {
|
|
58
|
+
const entries = await fs.readdir(profilesDir(email), { withFileTypes: true });
|
|
59
|
+
return entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export async function readProfile(email, profileName) {
|
|
66
|
+
return readJson(profileConfigPath(email, profileName));
|
|
67
|
+
}
|
|
68
|
+
export async function writeProfile(email, profileName, config) {
|
|
69
|
+
await writeJson(profileConfigPath(email, profileName), config);
|
|
70
|
+
}
|
|
71
|
+
export async function deleteProfile(email, profileName) {
|
|
72
|
+
try {
|
|
73
|
+
await fs.rm(profileConfigPath(email, profileName).replace("/config.json", ""), {
|
|
74
|
+
recursive: true,
|
|
75
|
+
force: true,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
// already gone
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Resolves the active profile per spec §1.1: `SOLTI_PROFILE` env var wins,
|
|
84
|
+
* then `active_profile` from active.json.
|
|
85
|
+
*/
|
|
86
|
+
export async function resolveActiveProfile() {
|
|
87
|
+
const account = await getActiveAccount();
|
|
88
|
+
if (account === null)
|
|
89
|
+
return null;
|
|
90
|
+
const profileName = process.env.SOLTI_PROFILE ?? (await getActiveProfileName());
|
|
91
|
+
if (profileName === null || profileName === undefined)
|
|
92
|
+
return null;
|
|
93
|
+
const config = await readProfile(account, profileName);
|
|
94
|
+
if (config === null)
|
|
95
|
+
return null;
|
|
96
|
+
return { account, profileName, config };
|
|
97
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import * as account from "./commands/account.js";
|
|
4
|
+
import * as connection from "./commands/connection.js";
|
|
5
|
+
import * as cronjob from "./commands/cronjob.js";
|
|
6
|
+
import * as job from "./commands/job.js";
|
|
7
|
+
import * as key from "./commands/key.js";
|
|
8
|
+
import * as organization from "./commands/organization.js";
|
|
9
|
+
import * as profile from "./commands/profile.js";
|
|
10
|
+
import * as project from "./commands/project.js";
|
|
11
|
+
import * as resource from "./commands/resource.js";
|
|
12
|
+
const program = new Command();
|
|
13
|
+
program
|
|
14
|
+
.name("solti")
|
|
15
|
+
.description("Solti Platform CLI — schedule and run asynchronous workloads without managing infrastructure.")
|
|
16
|
+
.version("0.1.2")
|
|
17
|
+
.option("--profile <name>", "override the active profile (or set SOLTI_PROFILE)")
|
|
18
|
+
.option("--api-key <key>", "override the API key (or set SOLTI_API_KEY)");
|
|
19
|
+
function fail(error) {
|
|
20
|
+
console.error(`error: ${error.message}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
/** Commander collector for repeatable valued options: each occurrence appends
|
|
24
|
+
* (plain non-collect options overwrite — last value wins). Comma-separated
|
|
25
|
+
* values stay joined here; commands split them via parseStringList. */
|
|
26
|
+
function collectValues(value, previous) {
|
|
27
|
+
return [...previous, value];
|
|
28
|
+
}
|
|
29
|
+
// --- account ----------------------------------------------------------------
|
|
30
|
+
const accountCommand = program.command("account").description("Manage logged-in accounts");
|
|
31
|
+
accountCommand
|
|
32
|
+
.command("login")
|
|
33
|
+
.description("Log in via your browser (LogTo OAuth)")
|
|
34
|
+
.option("--no-launch-browser", "print the sign-in URL instead of opening a browser")
|
|
35
|
+
.action(async (_args, command) => {
|
|
36
|
+
const { launchBrowser } = command.opts();
|
|
37
|
+
await account.accountLogin({ launchBrowser }).catch(fail);
|
|
38
|
+
});
|
|
39
|
+
accountCommand
|
|
40
|
+
.command("logout")
|
|
41
|
+
.description("Log out the active account")
|
|
42
|
+
.action(async () => {
|
|
43
|
+
await account.accountLogout().catch(fail);
|
|
44
|
+
});
|
|
45
|
+
accountCommand
|
|
46
|
+
.command("list")
|
|
47
|
+
.description("List locally logged-in accounts")
|
|
48
|
+
.action(async () => {
|
|
49
|
+
await account.accountList().catch(fail);
|
|
50
|
+
});
|
|
51
|
+
accountCommand
|
|
52
|
+
.command("switch <email>")
|
|
53
|
+
.description("Switch the active account")
|
|
54
|
+
.action(async (email) => {
|
|
55
|
+
await account.accountSwitch(email).catch(fail);
|
|
56
|
+
});
|
|
57
|
+
accountCommand
|
|
58
|
+
.command("show [email]")
|
|
59
|
+
.description("Show account information (defaults to the active account)")
|
|
60
|
+
.action(async (email) => {
|
|
61
|
+
await account.accountShow(email).catch(fail);
|
|
62
|
+
});
|
|
63
|
+
// --- profile ----------------------------------------------------------------
|
|
64
|
+
const profileCommand = program
|
|
65
|
+
.command("profile")
|
|
66
|
+
.description("Manage project profiles of the active account");
|
|
67
|
+
profileCommand
|
|
68
|
+
.command("list")
|
|
69
|
+
.description("List profiles of the active account")
|
|
70
|
+
.action(async () => {
|
|
71
|
+
await profile.profileList().catch(fail);
|
|
72
|
+
});
|
|
73
|
+
profileCommand
|
|
74
|
+
.command("set <profile_name>")
|
|
75
|
+
.description("Create or update a profile")
|
|
76
|
+
.requiredOption("--project-id <id>", "the project UUID")
|
|
77
|
+
.option("--api-key <key>", "the Solti API key (Zitadel PAT); omit to use OAuth tokens")
|
|
78
|
+
.option("--api-url <url>", "custom base API URL override")
|
|
79
|
+
.action(async (profileName, options) => {
|
|
80
|
+
await profile.profileSet(profileName, options).catch(fail);
|
|
81
|
+
});
|
|
82
|
+
profileCommand
|
|
83
|
+
.command("use <profile_name>")
|
|
84
|
+
.description("Switch the active profile (prints `export SOLTI_PROFILE=...` for eval)")
|
|
85
|
+
.action(async (profileName) => {
|
|
86
|
+
await profile.profileUse(profileName).catch(fail);
|
|
87
|
+
});
|
|
88
|
+
profileCommand
|
|
89
|
+
.command("show [profile_name]")
|
|
90
|
+
.description("Show profile details (API key is redacted)")
|
|
91
|
+
.action(async (profileName) => {
|
|
92
|
+
await profile.profileShow(profileName).catch(fail);
|
|
93
|
+
});
|
|
94
|
+
profileCommand
|
|
95
|
+
.command("delete <profile_name>")
|
|
96
|
+
.description("Delete a profile")
|
|
97
|
+
.action(async (profileName) => {
|
|
98
|
+
await profile.profileDelete(profileName).catch(fail);
|
|
99
|
+
});
|
|
100
|
+
// --- organization -----------------------------------------------------------
|
|
101
|
+
const orgCommand = program
|
|
102
|
+
.command("organization")
|
|
103
|
+
.description("Manage organizations (requires OAuth login)");
|
|
104
|
+
orgCommand
|
|
105
|
+
.command("list")
|
|
106
|
+
.description("List organizations you belong to")
|
|
107
|
+
.action(async () => {
|
|
108
|
+
await organization.organizationList().catch(fail);
|
|
109
|
+
});
|
|
110
|
+
orgCommand
|
|
111
|
+
.command("create <name>")
|
|
112
|
+
.description("Create an organization (you become its owner)")
|
|
113
|
+
.action(async (name) => {
|
|
114
|
+
await organization.organizationCreate(name).catch(fail);
|
|
115
|
+
});
|
|
116
|
+
orgCommand
|
|
117
|
+
.command("show <org_id_or_name>")
|
|
118
|
+
.description("Show organization details, including members")
|
|
119
|
+
.action(async (orgIdOrName) => {
|
|
120
|
+
await organization.organizationShow(orgIdOrName).catch(fail);
|
|
121
|
+
});
|
|
122
|
+
orgCommand
|
|
123
|
+
.command("delete <org_id_or_name>")
|
|
124
|
+
.description("Delete an organization (owner only)")
|
|
125
|
+
.option("--yes", "skip the confirmation prompt")
|
|
126
|
+
.action(async (orgIdOrName, options) => {
|
|
127
|
+
await organization.organizationDelete(orgIdOrName, options).catch(fail);
|
|
128
|
+
});
|
|
129
|
+
// --- project ----------------------------------------------------------------
|
|
130
|
+
const projectCommand = program
|
|
131
|
+
.command("project")
|
|
132
|
+
.description("Manage projects (requires OAuth login)");
|
|
133
|
+
projectCommand
|
|
134
|
+
.command("list")
|
|
135
|
+
.description("List projects (across your organizations, or --org to filter)")
|
|
136
|
+
.option("--org <org_id_or_name>", "filter by organization")
|
|
137
|
+
.action(async (options) => {
|
|
138
|
+
await project.projectList(options).catch(fail);
|
|
139
|
+
});
|
|
140
|
+
projectCommand
|
|
141
|
+
.command("create <name>")
|
|
142
|
+
.description("Create a project in an organization")
|
|
143
|
+
.requiredOption("--org <org_id_or_name>", "target organization")
|
|
144
|
+
.action(async (name, options) => {
|
|
145
|
+
await project.projectCreate(name, options).catch(fail);
|
|
146
|
+
});
|
|
147
|
+
projectCommand
|
|
148
|
+
.command("show <project_id>")
|
|
149
|
+
.description("Show project details")
|
|
150
|
+
.action(async (projectId) => {
|
|
151
|
+
await project.projectShow(projectId).catch(fail);
|
|
152
|
+
});
|
|
153
|
+
projectCommand
|
|
154
|
+
.command("use <project_id>")
|
|
155
|
+
.description("Set the active project of the current profile")
|
|
156
|
+
.action(async (projectId) => {
|
|
157
|
+
await project.projectUse(projectId).catch(fail);
|
|
158
|
+
});
|
|
159
|
+
projectCommand
|
|
160
|
+
.command("delete <project_id>")
|
|
161
|
+
.description("Delete a project (org owner only)")
|
|
162
|
+
.option("--yes", "skip the confirmation prompt")
|
|
163
|
+
.action(async (projectId, options) => {
|
|
164
|
+
await project.projectDelete(projectId, options).catch(fail);
|
|
165
|
+
});
|
|
166
|
+
// --- resource ---------------------------------------------------------------
|
|
167
|
+
program
|
|
168
|
+
.command("resource")
|
|
169
|
+
.description("Discover cloud resources of the active project")
|
|
170
|
+
.command("list")
|
|
171
|
+
.option("--type <type>", "storages | repositories | vm-pools")
|
|
172
|
+
.option("--connection <name>", "filter by connection name")
|
|
173
|
+
.description("List discovered resources")
|
|
174
|
+
.action(async (options) => {
|
|
175
|
+
await resource.resourceList(options).catch(fail);
|
|
176
|
+
});
|
|
177
|
+
// --- job --------------------------------------------------------------------
|
|
178
|
+
const jobCommand = program.command("job").description("Manage workloads");
|
|
179
|
+
jobCommand
|
|
180
|
+
.command("run")
|
|
181
|
+
.description("Submit a workload (-f workload.yaml, or --image with a command)")
|
|
182
|
+
.option("-f, --file <path>", "declarative workload YAML/JSON file")
|
|
183
|
+
.option("--image <image>", "container image")
|
|
184
|
+
.option("--command <cmd...>", "container command override")
|
|
185
|
+
.option("--args <args...>", "container command arguments")
|
|
186
|
+
.option("--name <name>", "explicit job name")
|
|
187
|
+
.option("--name-prefix <prefix>", "prefix for auto-generated names")
|
|
188
|
+
.option("--max-retries <n>", "maximum container retries")
|
|
189
|
+
.option("--env <key=value>", "environment variable (repeatable)")
|
|
190
|
+
.option("--env-from-file <path>", "load KEY=VALUE lines from a .env file (explicit --env flags win)")
|
|
191
|
+
.option("--volume <spec>", "storage volume mount: <bucket>[/<prefix>]:<mountPath> or bucket=<b>,mountPath=<p>[,connection=...][,prefix=...] (repeatable)")
|
|
192
|
+
.option("--volume-name <name>", "explicit volume name (map key) for --volume")
|
|
193
|
+
.option("--resources <spec>", "e.g. cpu=4,memory=16Gi,gpu=24Gi or gpu.model=A100,gpu.count=2")
|
|
194
|
+
.option("--label <key=value>", "label (repeatable)")
|
|
195
|
+
.option("--tag <tag>", "tag (repeatable)")
|
|
196
|
+
.option("--cloud <provider>", "cloud constraint (aws | gcp | azure; repeatable or comma-separated)", collectValues, [])
|
|
197
|
+
.option("--region <region>", "region constraint (repeatable or comma-separated)", collectValues, [])
|
|
198
|
+
.allowUnknownOption(true)
|
|
199
|
+
.argument("[operands...]", "positional command and args (after --)")
|
|
200
|
+
.action(async (_operands, options, command) => {
|
|
201
|
+
const positional = (command.args ?? []).filter((a) => a !== "--");
|
|
202
|
+
await job.jobRun({ ...options, positional }).catch(fail);
|
|
203
|
+
});
|
|
204
|
+
jobCommand
|
|
205
|
+
.command("list")
|
|
206
|
+
.description("List recent workloads")
|
|
207
|
+
.option("--tag <tag>", "filter by tag (repeatable)")
|
|
208
|
+
.option("--label <key:value>", "filter by label (repeatable; key=value accepted)")
|
|
209
|
+
.action(async (options) => {
|
|
210
|
+
await job.jobList(options).catch(fail);
|
|
211
|
+
});
|
|
212
|
+
jobCommand
|
|
213
|
+
.command("status <job_id_or_name>")
|
|
214
|
+
.description("Show detailed status of a workload (--watch streams until a terminal state)")
|
|
215
|
+
.option("--watch", "poll and stream status until the job reaches a terminal state")
|
|
216
|
+
.action(async (jobIdOrName, options) => {
|
|
217
|
+
await job.jobStatus(jobIdOrName, { watch: options.watch }).catch(fail);
|
|
218
|
+
});
|
|
219
|
+
jobCommand
|
|
220
|
+
.command("cancel <job_id_or_name>")
|
|
221
|
+
.description("Cancel a workload")
|
|
222
|
+
.action(async (jobIdOrName) => {
|
|
223
|
+
await job.jobCancel(jobIdOrName).catch(fail);
|
|
224
|
+
});
|
|
225
|
+
// --- cronjob ----------------------------------------------------------------
|
|
226
|
+
const cronjobCommand = program
|
|
227
|
+
.command("cronjob")
|
|
228
|
+
.description("Manage cron-based schedulers (schedules evaluated in UTC)");
|
|
229
|
+
cronjobCommand
|
|
230
|
+
.command("list")
|
|
231
|
+
.description("List cronjobs")
|
|
232
|
+
.action(async () => {
|
|
233
|
+
await cronjob.cronjobList().catch(fail);
|
|
234
|
+
});
|
|
235
|
+
cronjobCommand
|
|
236
|
+
.command("show <id_or_name>")
|
|
237
|
+
.description("Show cronjob details")
|
|
238
|
+
.action(async (idOrName) => {
|
|
239
|
+
await cronjob.cronjobShow(idOrName).catch(fail);
|
|
240
|
+
});
|
|
241
|
+
cronjobCommand
|
|
242
|
+
.command("create")
|
|
243
|
+
.description("Create a cronjob (--image form, or --file with a workload YAML/JSON template)")
|
|
244
|
+
.requiredOption("--name <name>", "cronjob name")
|
|
245
|
+
.requiredOption("--schedule <cron>", "UTC crontab expression")
|
|
246
|
+
.option("--file <path>", "workload YAML/JSON file to use as the job definition template")
|
|
247
|
+
.option("--image <image>", "container image (inline form; required without --file)")
|
|
248
|
+
.option("--command <cmd>", "container command (space-separated)")
|
|
249
|
+
.option("--args <args>", "container arguments (space-separated)")
|
|
250
|
+
.option("--active <true|false>", "start active (default true)")
|
|
251
|
+
.action(async (options) => {
|
|
252
|
+
await cronjob.cronjobCreate(options).catch(fail);
|
|
253
|
+
});
|
|
254
|
+
cronjobCommand
|
|
255
|
+
.command("update <id_or_name>")
|
|
256
|
+
.description("Update a cronjob without recreating it")
|
|
257
|
+
.option("--schedule <cron>", "new UTC crontab expression")
|
|
258
|
+
.option("--active <true|false>", "toggle active state")
|
|
259
|
+
.option("--image <image>", "new container image")
|
|
260
|
+
.action(async (idOrName, options) => {
|
|
261
|
+
await cronjob.cronjobUpdate(idOrName, options).catch(fail);
|
|
262
|
+
});
|
|
263
|
+
cronjobCommand
|
|
264
|
+
.command("delete <id_or_name>")
|
|
265
|
+
.description("Delete a cronjob")
|
|
266
|
+
.action(async (idOrName) => {
|
|
267
|
+
await cronjob.cronjobDelete(idOrName).catch(fail);
|
|
268
|
+
});
|
|
269
|
+
// --- connection -------------------------------------------------------------
|
|
270
|
+
const connectionCommand = program
|
|
271
|
+
.command("connection")
|
|
272
|
+
.description("Manage cloud credential connections (admin only)");
|
|
273
|
+
connectionCommand
|
|
274
|
+
.command("list")
|
|
275
|
+
.description("List connections")
|
|
276
|
+
.action(async () => {
|
|
277
|
+
await connection.connectionList().catch(fail);
|
|
278
|
+
});
|
|
279
|
+
connectionCommand
|
|
280
|
+
.command("get <name>")
|
|
281
|
+
.description("Show connection details (credentials redacted)")
|
|
282
|
+
.action(async (name) => {
|
|
283
|
+
await connection.connectionGet(name).catch(fail);
|
|
284
|
+
});
|
|
285
|
+
connectionCommand
|
|
286
|
+
.command("create")
|
|
287
|
+
.description("Create a cloud connection")
|
|
288
|
+
.requiredOption("--name <name>", "connection name")
|
|
289
|
+
.requiredOption("--type <type>", "aws | gcp | azure | r2 | github")
|
|
290
|
+
.option("--access-key <key>", "access key id (aws) / client id (azure)")
|
|
291
|
+
.option("--secret-key <key>", "secret access key (aws) / client secret (azure)")
|
|
292
|
+
.option("--keyfile <path>", "GCP service-account keyfile (gcp)")
|
|
293
|
+
.option("--project-id <id>", "GCP project id (gcp) / Azure subscription id (azure)")
|
|
294
|
+
.option("--tenant-id <id>", "Azure tenant id")
|
|
295
|
+
.option("--account <id>", "Cloudflare account id (r2)")
|
|
296
|
+
.option("--token <token>", "GitHub personal access token (github)")
|
|
297
|
+
.action(async (options) => {
|
|
298
|
+
await connection.connectionCreate(options).catch(fail);
|
|
299
|
+
});
|
|
300
|
+
connectionCommand
|
|
301
|
+
.command("delete <name>")
|
|
302
|
+
.description("Delete a connection")
|
|
303
|
+
.action(async (name) => {
|
|
304
|
+
await connection.connectionDelete(name).catch(fail);
|
|
305
|
+
});
|
|
306
|
+
// --- key --------------------------------------------------------------------
|
|
307
|
+
const keyCommand = program.command("key").description("Manage API keys (admin only)");
|
|
308
|
+
keyCommand
|
|
309
|
+
.command("list")
|
|
310
|
+
.description("List API keys")
|
|
311
|
+
.action(async () => {
|
|
312
|
+
await key.keyList().catch(fail);
|
|
313
|
+
});
|
|
314
|
+
keyCommand
|
|
315
|
+
.command("create")
|
|
316
|
+
.description("Create an API key (the token is shown only once)")
|
|
317
|
+
.requiredOption("--name <name>", "key name")
|
|
318
|
+
.requiredOption("--role <role>", "admin | developer | viewer")
|
|
319
|
+
.option("--expires-at <date>", "optional expiration (ISO date)")
|
|
320
|
+
.action(async (options) => {
|
|
321
|
+
await key.keyCreate(options).catch(fail);
|
|
322
|
+
});
|
|
323
|
+
keyCommand
|
|
324
|
+
.command("delete <id_or_name>")
|
|
325
|
+
.description("Delete an API key")
|
|
326
|
+
.action(async (idOrName) => {
|
|
327
|
+
await key.keyDelete(idOrName).catch(fail);
|
|
328
|
+
});
|
|
329
|
+
program.parseAsync(process.argv).catch(fail);
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure parsers for `solti job run` flag payloads (constitution tools/cli.md
|
|
3
|
+
* §2.2). Kept free of I/O so they can be unit-tested directly (tests/parse.test.ts).
|
|
4
|
+
*/
|
|
5
|
+
/** Normalizes repeatable + comma-separated flag values (cli.md §2.2:
|
|
6
|
+
* `--cloud aws,gcp` and `--cloud aws --cloud gcp` are both valid). Returns a
|
|
7
|
+
* flat, trimmed, empty-item-free array so the API always receives a JSON
|
|
8
|
+
* array — a scalar `cloud`/`region` payload is what poisoned jobs.cloud on
|
|
9
|
+
* the live API (Change 048). */
|
|
10
|
+
export function parseStringList(values) {
|
|
11
|
+
const list = values === undefined ? [] : Array.isArray(values) ? values : [values];
|
|
12
|
+
return list
|
|
13
|
+
.flatMap((value) => value.split(","))
|
|
14
|
+
.map((value) => value.trim())
|
|
15
|
+
.filter((value) => value !== "");
|
|
16
|
+
}
|
|
17
|
+
/** Parses `.env`-style content: KEY=VALUE lines; blank lines and `#`
|
|
18
|
+
* comments are ignored; whitespace is trimmed; matching surrounding quotes
|
|
19
|
+
* are stripped from values. */
|
|
20
|
+
export function parseEnvFile(text) {
|
|
21
|
+
const env = {};
|
|
22
|
+
for (const rawLine of text.split(/\r?\n/)) {
|
|
23
|
+
const line = rawLine.trim();
|
|
24
|
+
if (line === "" || line.startsWith("#"))
|
|
25
|
+
continue;
|
|
26
|
+
const eq = line.indexOf("=");
|
|
27
|
+
if (eq <= 0) {
|
|
28
|
+
throw new Error(`Invalid env line '${line}' — expected KEY=VALUE`);
|
|
29
|
+
}
|
|
30
|
+
const key = line.slice(0, eq).trim();
|
|
31
|
+
let value = line.slice(eq + 1).trim();
|
|
32
|
+
if ((value.startsWith('"') && value.endsWith('"') && value.length >= 2) ||
|
|
33
|
+
(value.startsWith("'") && value.endsWith("'") && value.length >= 2)) {
|
|
34
|
+
value = value.slice(1, -1);
|
|
35
|
+
}
|
|
36
|
+
env[key] = value;
|
|
37
|
+
}
|
|
38
|
+
return env;
|
|
39
|
+
}
|
|
40
|
+
const VRAM_RE = /^\d+(\.\d+)?(Gi|Mi)?$/;
|
|
41
|
+
/** Parses a `--resources` spec, e.g. `cpu=4,memory=16Gi,gpu=24Gi` or
|
|
42
|
+
* `cpu=4,memory=16Gi,gpu.model=A100,gpu.count=2`. Unknown keys, duplicates
|
|
43
|
+
* of the same key, non-numeric cpu/count values, and `gpu.count` without
|
|
44
|
+
* `gpu.model` throw — nothing is silently dropped. */
|
|
45
|
+
export function parseResources(spec) {
|
|
46
|
+
const resources = {};
|
|
47
|
+
const gpu = {};
|
|
48
|
+
let gpuSeen = false;
|
|
49
|
+
const seen = new Set();
|
|
50
|
+
for (const rawPair of spec.split(",")) {
|
|
51
|
+
const pair = rawPair.trim();
|
|
52
|
+
if (pair === "")
|
|
53
|
+
continue;
|
|
54
|
+
const eq = pair.indexOf("=");
|
|
55
|
+
if (eq <= 0) {
|
|
56
|
+
throw new Error(`Invalid --resources entry '${pair}' — expected key=value (e.g. cpu=4,memory=16Gi,gpu=24Gi)`);
|
|
57
|
+
}
|
|
58
|
+
const key = pair.slice(0, eq).trim();
|
|
59
|
+
const value = pair.slice(eq + 1).trim();
|
|
60
|
+
if (seen.has(key)) {
|
|
61
|
+
throw new Error(`Duplicate --resources key '${key}'`);
|
|
62
|
+
}
|
|
63
|
+
seen.add(key);
|
|
64
|
+
switch (key) {
|
|
65
|
+
case "cpu": {
|
|
66
|
+
const cpu = Number(value);
|
|
67
|
+
if (!Number.isFinite(cpu) || cpu <= 0) {
|
|
68
|
+
throw new Error(`Invalid --resources cpu value '${value}' — expected a positive number`);
|
|
69
|
+
}
|
|
70
|
+
resources.cpu = cpu;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case "memory":
|
|
74
|
+
if (value === "")
|
|
75
|
+
throw new Error("Invalid --resources memory value — expected e.g. memory=16Gi");
|
|
76
|
+
resources.memory = value;
|
|
77
|
+
break;
|
|
78
|
+
case "gpu":
|
|
79
|
+
case "gpu.vram": {
|
|
80
|
+
if (!VRAM_RE.test(value)) {
|
|
81
|
+
throw new Error(`Invalid --resources GPU VRAM '${value}' — expected a quantity like 24Gi (or gpu.model=A100)`);
|
|
82
|
+
}
|
|
83
|
+
gpu.vram = value;
|
|
84
|
+
gpuSeen = true;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case "gpu.model":
|
|
88
|
+
if (value === "")
|
|
89
|
+
throw new Error("Invalid --resources gpu.model value — expected e.g. gpu.model=A100");
|
|
90
|
+
gpu.model = value;
|
|
91
|
+
gpuSeen = true;
|
|
92
|
+
break;
|
|
93
|
+
case "gpu.count": {
|
|
94
|
+
const count = Number(value);
|
|
95
|
+
if (!Number.isInteger(count) || count < 1) {
|
|
96
|
+
throw new Error(`Invalid --resources gpu.count '${value}' — expected a positive integer`);
|
|
97
|
+
}
|
|
98
|
+
gpu.count = count;
|
|
99
|
+
gpuSeen = true;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
default:
|
|
103
|
+
throw new Error(`Unknown --resources key '${key}' — supported: cpu, memory, gpu=<vram>, gpu.vram, gpu.model, gpu.count`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (gpuSeen) {
|
|
107
|
+
if (gpu.count !== undefined && gpu.model === undefined) {
|
|
108
|
+
throw new Error("--resources gpu.count requires gpu.model (e.g. gpu.model=A100,gpu.count=2)");
|
|
109
|
+
}
|
|
110
|
+
resources.gpu = gpu;
|
|
111
|
+
}
|
|
112
|
+
return resources;
|
|
113
|
+
}
|
|
114
|
+
/** Parses the volume shorthand `<bucket>[/<prefix>]:<mountPath>` (the first
|
|
115
|
+
* colon separates the bucket part from the mount path; the first slash of the
|
|
116
|
+
* bucket part separates bucket from prefix). */
|
|
117
|
+
export function parseVolumeShorthand(spec) {
|
|
118
|
+
const colon = spec.indexOf(":");
|
|
119
|
+
if (colon === -1) {
|
|
120
|
+
throw new Error(`Invalid --volume spec '${spec}' — expected <bucket>[/<prefix>]:<mountPath>`);
|
|
121
|
+
}
|
|
122
|
+
const bucketPart = spec.slice(0, colon);
|
|
123
|
+
const mountPath = spec.slice(colon + 1);
|
|
124
|
+
if (bucketPart === "" || mountPath === "") {
|
|
125
|
+
throw new Error(`Invalid --volume spec '${spec}' — expected <bucket>[/<prefix>]:<mountPath>`);
|
|
126
|
+
}
|
|
127
|
+
const slash = bucketPart.indexOf("/");
|
|
128
|
+
if (slash === -1)
|
|
129
|
+
return { bucket: bucketPart, mountPath };
|
|
130
|
+
const bucket = bucketPart.slice(0, slash);
|
|
131
|
+
const prefix = bucketPart.slice(slash + 1);
|
|
132
|
+
if (bucket === "" || prefix === "") {
|
|
133
|
+
throw new Error(`Invalid --volume spec '${spec}' — expected <bucket>[/<prefix>]:<mountPath>`);
|
|
134
|
+
}
|
|
135
|
+
return { bucket, prefix, mountPath };
|
|
136
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solti/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Solti Platform CLI \u2014 schedule and run asynchronous workloads without managing infrastructure.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md",
|
|
10
|
+
"LICENSE"
|
|
11
|
+
],
|
|
12
|
+
"bin": {
|
|
13
|
+
"solti": "dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=20"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"dev": "tsc --watch",
|
|
21
|
+
"test": "bun test"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"commander": "^14.0.2",
|
|
25
|
+
"yaml": "^2.9.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^24.10.1",
|
|
29
|
+
"typescript": "^5.9.3"
|
|
30
|
+
}
|
|
31
|
+
}
|