@greenmind/cli 0.9.31 → 0.9.40
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/package.json +6 -5
- package/src/client.ts +155 -121
- package/src/command.ts +509 -93
- package/src/commands.ts +47 -24
- package/src/constants.ts +8 -6
- package/src/credentials.ts +2 -2
- package/src/environment-commands.ts +54 -133
- package/src/index.ts +1 -1
- package/src/load.ts +7 -3
- package/src/org-commands.ts +579 -0
- package/src/protocol.ts +5 -7
- package/src/runner-command.ts +118 -0
- package/src/session.ts +20 -7
package/src/command.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import {
|
|
3
|
+
Argument,
|
|
4
|
+
Command,
|
|
5
|
+
type CommandUnknownOpts,
|
|
6
|
+
InvalidArgumentError,
|
|
7
|
+
Option,
|
|
8
|
+
type OptionValues,
|
|
9
|
+
} from '@commander-js/extra-typings'
|
|
10
|
+
import {
|
|
11
|
+
ENVIRONMENT_COLLECTION_STORAGE,
|
|
12
|
+
ENVIRONMENT_FUNCTION_RUNTIMES,
|
|
13
|
+
type Json,
|
|
14
|
+
KEY_PERMISSIONS,
|
|
15
|
+
parseJsonText,
|
|
16
|
+
POOL_KINDS,
|
|
17
|
+
SCHEDULE_TICK_DAYS,
|
|
18
|
+
} from '@greenmind/ext-schema'
|
|
3
19
|
import { PlatformError } from './client'
|
|
4
20
|
import { runCheck, runCompile, runFunction, runPush, runUpload } from './commands'
|
|
5
|
-
import { ENV_ISSUER, ENV_KEY, ENV_URL } from './constants'
|
|
21
|
+
import { ENV_ISSUER, ENV_KEY, ENV_ORG, ENV_URL } from './constants'
|
|
6
22
|
import {
|
|
7
23
|
flowKeysOf,
|
|
8
24
|
readSeedFile,
|
|
@@ -11,10 +27,8 @@ import {
|
|
|
11
27
|
runDeploy,
|
|
12
28
|
runEnvironmentList,
|
|
13
29
|
runEnvironmentStatus,
|
|
30
|
+
runEventsReplay,
|
|
14
31
|
runFlowSwitch,
|
|
15
|
-
runKeysCreate,
|
|
16
|
-
runKeysList,
|
|
17
|
-
runKeysRevoke,
|
|
18
32
|
runRuntimeGet,
|
|
19
33
|
runRuntimeSet,
|
|
20
34
|
runStorageGet,
|
|
@@ -23,6 +37,28 @@ import {
|
|
|
23
37
|
import { ExtConfigError, loadExtConfig } from './ext-config'
|
|
24
38
|
import { IdentityError, type IdentityOptions } from './identity'
|
|
25
39
|
import { LoadError } from './load'
|
|
40
|
+
import {
|
|
41
|
+
runJobCancel,
|
|
42
|
+
runJobEnqueue,
|
|
43
|
+
runJobList,
|
|
44
|
+
runJobRetry,
|
|
45
|
+
runJobShow,
|
|
46
|
+
runKeyCreate,
|
|
47
|
+
runKeyList,
|
|
48
|
+
runKeyRevoke,
|
|
49
|
+
runKeyUpdate,
|
|
50
|
+
runPoolCreate,
|
|
51
|
+
runPoolList,
|
|
52
|
+
runPoolRemove,
|
|
53
|
+
runPoolShow,
|
|
54
|
+
runPoolUpdate,
|
|
55
|
+
runRunnerDrop,
|
|
56
|
+
runRunnerList,
|
|
57
|
+
runScheduleList,
|
|
58
|
+
runSchedulePause,
|
|
59
|
+
runScheduleRun,
|
|
60
|
+
} from './org-commands'
|
|
61
|
+
import { runnerCommand } from './runner-command'
|
|
26
62
|
import { connect, runLogin, runLogout, runWhoami, SessionError } from './session'
|
|
27
63
|
|
|
28
64
|
/**
|
|
@@ -108,12 +144,15 @@ function sourceFrom(options: { repository?: string; commit?: string; branch?: st
|
|
|
108
144
|
return Object.fromEntries(Object.entries(source).filter(([, value]) => value))
|
|
109
145
|
}
|
|
110
146
|
|
|
111
|
-
const URL_HELP = `The
|
|
112
|
-
const
|
|
147
|
+
const URL_HELP = `The developer API's address (or ${ENV_URL})`
|
|
148
|
+
const ORG_HELP = `The handle of the organisation the environment is in (or ${ENV_ORG})`
|
|
149
|
+
const KEY_HELP = `An org key reaching the environment, holding edit_config there to change it (or ${ENV_KEY}); with one, no sign-in is read`
|
|
113
150
|
const CONFIG_HELP = 'The project config (default: ext.config.ts in this directory)'
|
|
114
151
|
const APP_KEY_HELP = "The environment's app key"
|
|
115
152
|
const ENV_HELP =
|
|
116
|
-
"The environment's app key:
|
|
153
|
+
"The environment's app key: with an org key whose scope names one app alone, that app"
|
|
154
|
+
const RETIRE_HELP =
|
|
155
|
+
'With a live push, take the flows and schedules the files no longer define off the live set'
|
|
117
156
|
|
|
118
157
|
/** `gm login`, `gm logout` and `gm whoami`: one sign-in for every product. */
|
|
119
158
|
function signInCommands({ identity, loginScopes = [] }: GmCommandContext): CommandUnknownOpts[] {
|
|
@@ -163,12 +202,15 @@ const envCommand: CommandBuilder = ({ identity }) =>
|
|
|
163
202
|
.description('The environments you can read')
|
|
164
203
|
.addCommand(
|
|
165
204
|
new Command('list')
|
|
166
|
-
.description('List the environments you can read')
|
|
205
|
+
.description('List the environments of a project you can read')
|
|
206
|
+
.requiredOption('--project <key>', "The project's key")
|
|
167
207
|
.option('--url <url>', URL_HELP)
|
|
168
|
-
.
|
|
208
|
+
.option('--org <handle>', ORG_HELP)
|
|
209
|
+
.action(({ project, ...options }) =>
|
|
169
210
|
guarded(() =>
|
|
170
211
|
runEnvironmentList(
|
|
171
212
|
connect({ ...options, identity }, 'person', 'Listing environments'),
|
|
213
|
+
project,
|
|
172
214
|
print,
|
|
173
215
|
),
|
|
174
216
|
),
|
|
@@ -177,10 +219,11 @@ const envCommand: CommandBuilder = ({ identity }) =>
|
|
|
177
219
|
.addCommand(
|
|
178
220
|
new Command('status')
|
|
179
221
|
.description(
|
|
180
|
-
'Show where an environment stands: placement, writer, runtime, definitions, flows, landing and keys',
|
|
222
|
+
'Show where an environment stands: placement, writer, runtime, definitions, flows, landing and the org keys reaching it',
|
|
181
223
|
)
|
|
182
224
|
.argument('<env>', APP_KEY_HELP)
|
|
183
225
|
.option('--url <url>', URL_HELP)
|
|
226
|
+
.option('--org <handle>', ORG_HELP)
|
|
184
227
|
.option('--key <key>', KEY_HELP)
|
|
185
228
|
.action((appKey, options) =>
|
|
186
229
|
guarded(() =>
|
|
@@ -193,82 +236,15 @@ const envCommand: CommandBuilder = ({ identity }) =>
|
|
|
193
236
|
),
|
|
194
237
|
)
|
|
195
238
|
|
|
196
|
-
/** `gm pub keys`: an environment's server keys and publish keys. */
|
|
197
|
-
const keysCommand: CommandBuilder = ({ identity }) => {
|
|
198
|
-
const keyCommands = (kind: 'server' | 'publish') =>
|
|
199
|
-
new Command(kind)
|
|
200
|
-
.description(
|
|
201
|
-
kind === 'server'
|
|
202
|
-
? 'The keys the game backend calls the platform with (needs manage_server_keys)'
|
|
203
|
-
: 'The keys a build publishes with (needs manage_server_keys)',
|
|
204
|
-
)
|
|
205
|
-
.addCommand(
|
|
206
|
-
new Command('create')
|
|
207
|
-
.description(`Create a ${kind} key; its secret is printed once`)
|
|
208
|
-
.argument('<env>', APP_KEY_HELP)
|
|
209
|
-
.option('--name <name>', `The key's ${kind === 'server' ? 'name' : 'label'}`, 'gm')
|
|
210
|
-
.option('--url <url>', URL_HELP)
|
|
211
|
-
.action((appKey, options) =>
|
|
212
|
-
guarded(() =>
|
|
213
|
-
runKeysCreate(
|
|
214
|
-
connect({ ...options, identity }, 'person', 'Creating a key'),
|
|
215
|
-
kind,
|
|
216
|
-
appKey,
|
|
217
|
-
options.name,
|
|
218
|
-
print,
|
|
219
|
-
),
|
|
220
|
-
),
|
|
221
|
-
),
|
|
222
|
-
)
|
|
223
|
-
.addCommand(
|
|
224
|
-
new Command('list')
|
|
225
|
-
.description(`List an environment's ${kind} keys, by prefix`)
|
|
226
|
-
.argument('<env>', APP_KEY_HELP)
|
|
227
|
-
.option('--url <url>', URL_HELP)
|
|
228
|
-
.action((appKey, options) =>
|
|
229
|
-
guarded(() =>
|
|
230
|
-
runKeysList(
|
|
231
|
-
connect({ ...options, identity }, 'person', 'Listing keys'),
|
|
232
|
-
kind,
|
|
233
|
-
appKey,
|
|
234
|
-
print,
|
|
235
|
-
),
|
|
236
|
-
),
|
|
237
|
-
),
|
|
238
|
-
)
|
|
239
|
-
.addCommand(
|
|
240
|
-
new Command('revoke')
|
|
241
|
-
.description(`Revoke a ${kind} key`)
|
|
242
|
-
.argument('<env>', APP_KEY_HELP)
|
|
243
|
-
.argument('<key>', "The key's id, or its prefix")
|
|
244
|
-
.option('--url <url>', URL_HELP)
|
|
245
|
-
.action((appKey, key, options) =>
|
|
246
|
-
guarded(() =>
|
|
247
|
-
runKeysRevoke(
|
|
248
|
-
connect({ ...options, identity }, 'person', 'Revoking a key'),
|
|
249
|
-
kind,
|
|
250
|
-
appKey,
|
|
251
|
-
key,
|
|
252
|
-
print,
|
|
253
|
-
),
|
|
254
|
-
),
|
|
255
|
-
),
|
|
256
|
-
)
|
|
257
|
-
return new Command('keys')
|
|
258
|
-
.description('Server keys and publish keys')
|
|
259
|
-
.addCommand(keyCommands('server'))
|
|
260
|
-
.addCommand(keyCommands('publish'))
|
|
261
|
-
}
|
|
262
|
-
|
|
263
239
|
/**
|
|
264
|
-
* The project's definitions: flows, functions, events,
|
|
265
|
-
* TypeScript. Check, compile, push and upload them, run a function on a recorded event, and deploy
|
|
240
|
+
* The project's definitions: flows, functions, events, collections, sockets, webhooks and
|
|
241
|
+
* permissions written in TypeScript. Check, compile, push and upload them, run a function on a recorded event, and deploy
|
|
266
242
|
* everything `ext.config.ts` names at once.
|
|
267
243
|
*/
|
|
268
244
|
function definitionCommands({ identity }: GmCommandContext): CommandUnknownOpts[] {
|
|
269
245
|
const check = new Command('check')
|
|
270
246
|
.description(
|
|
271
|
-
'Compile definitions, so what the SDK and the stored form refuse is refused here, and with a platform address and a key or sign-in check them against that environment',
|
|
247
|
+
'Compile definitions and hold them to the gateway rules (a GET flow never writes; an anonymous caller is limited and never granted to), so what the SDK and the stored form refuse is refused here, and with a platform address and a key or sign-in check them against that environment',
|
|
272
248
|
)
|
|
273
249
|
.argument(
|
|
274
250
|
'<paths...>',
|
|
@@ -276,6 +252,7 @@ function definitionCommands({ identity }: GmCommandContext): CommandUnknownOpts[
|
|
|
276
252
|
)
|
|
277
253
|
.option('--env <env>', ENV_HELP)
|
|
278
254
|
.option('--url <url>', URL_HELP)
|
|
255
|
+
.option('--org <handle>', ORG_HELP)
|
|
279
256
|
.option('--key <key>', KEY_HELP)
|
|
280
257
|
.action(async (paths, { env: appKey, ...options }) => {
|
|
281
258
|
finish(
|
|
@@ -318,21 +295,20 @@ function definitionCommands({ identity }: GmCommandContext): CommandUnknownOpts[
|
|
|
318
295
|
|
|
319
296
|
const push = new Command('push')
|
|
320
297
|
.description(
|
|
321
|
-
'Check definitions against the environment
|
|
298
|
+
'Check definitions against the environment, and if it accepts them and you may change it, push them as new versions',
|
|
322
299
|
)
|
|
323
300
|
.argument(
|
|
324
301
|
'<paths...>',
|
|
325
302
|
'TypeScript or JavaScript modules, JSON files in the stored form, or directories of them',
|
|
326
303
|
)
|
|
327
304
|
.option('--url <url>', URL_HELP)
|
|
305
|
+
.option('--org <handle>', ORG_HELP)
|
|
328
306
|
.option('--key <key>', KEY_HELP)
|
|
329
307
|
.option('--repository <name>', 'The repository the definitions are in, kept with each version')
|
|
330
308
|
.option('--commit <sha>', 'The commit, kept with each version')
|
|
331
309
|
.option('--branch <name>', 'The branch, kept with each version')
|
|
332
|
-
.option(
|
|
333
|
-
|
|
334
|
-
'Also make each pushed version live (a test environment only; without it a push only saves versions)',
|
|
335
|
-
)
|
|
310
|
+
.option('--live', 'Also make each pushed version live (without it a push only saves versions)')
|
|
311
|
+
.option('--retire', RETIRE_HELP)
|
|
336
312
|
.option('--env <env>', ENV_HELP)
|
|
337
313
|
.action(async (paths, { env: appKey, ...options }) => {
|
|
338
314
|
const client = connect({ ...options, identity }, 'any', 'Pushing')
|
|
@@ -343,6 +319,7 @@ function definitionCommands({ identity }: GmCommandContext): CommandUnknownOpts[
|
|
|
343
319
|
client,
|
|
344
320
|
source: sourceFrom(options),
|
|
345
321
|
live: options.live ? true : undefined,
|
|
322
|
+
retire: options.retire ? true : undefined,
|
|
346
323
|
appKey,
|
|
347
324
|
},
|
|
348
325
|
print,
|
|
@@ -352,10 +329,11 @@ function definitionCommands({ identity }: GmCommandContext): CommandUnknownOpts[
|
|
|
352
329
|
|
|
353
330
|
const upload = new Command('upload')
|
|
354
331
|
.description(
|
|
355
|
-
|
|
332
|
+
'Build the hosted functions the modules define into one bundle and upload it to the environment, with each function saved as a version that runs it',
|
|
356
333
|
)
|
|
357
334
|
.argument('<paths...>', 'TypeScript or JavaScript modules, or directories of them')
|
|
358
335
|
.option('--url <url>', URL_HELP)
|
|
336
|
+
.option('--org <handle>', ORG_HELP)
|
|
359
337
|
.option('--key <key>', KEY_HELP)
|
|
360
338
|
.option('--repository <name>', 'The repository the functions are in, kept with each version')
|
|
361
339
|
.option('--commit <sha>', 'The commit, kept with each version')
|
|
@@ -372,16 +350,27 @@ function definitionCommands({ identity }: GmCommandContext): CommandUnknownOpts[
|
|
|
372
350
|
)
|
|
373
351
|
.option('--env <env>', ENV_HELP)
|
|
374
352
|
.option('--url <url>', URL_HELP)
|
|
353
|
+
.option('--org <handle>', ORG_HELP)
|
|
375
354
|
.option('--key <key>', KEY_HELP)
|
|
376
355
|
.option('--config <file>', CONFIG_HELP)
|
|
377
356
|
.option('--repository <name>', 'The repository the definitions are in, kept with each version')
|
|
378
357
|
.option('--commit <sha>', 'The commit, kept with each version')
|
|
379
358
|
.option('--branch <name>', 'The branch, kept with each version')
|
|
359
|
+
.option('--retire', RETIRE_HELP)
|
|
380
360
|
.action(({ env: appKey, ...options }) =>
|
|
381
361
|
guarded(async () => {
|
|
382
362
|
const loaded = await loadExtConfig(options.config)
|
|
383
363
|
const client = connect({ ...options, identity }, 'any', 'Deploying')
|
|
384
|
-
return runDeploy(
|
|
364
|
+
return runDeploy(
|
|
365
|
+
{
|
|
366
|
+
client,
|
|
367
|
+
config: loaded,
|
|
368
|
+
source: sourceFrom(options),
|
|
369
|
+
appKey,
|
|
370
|
+
retire: options.retire ? true : undefined,
|
|
371
|
+
},
|
|
372
|
+
print,
|
|
373
|
+
)
|
|
385
374
|
}),
|
|
386
375
|
)
|
|
387
376
|
|
|
@@ -392,11 +381,12 @@ function definitionCommands({ identity }: GmCommandContext): CommandUnknownOpts[
|
|
|
392
381
|
const flowsCommand: CommandBuilder = ({ identity }) => {
|
|
393
382
|
const switchCommand = (name: 'on' | 'off') =>
|
|
394
383
|
new Command(name)
|
|
395
|
-
.description(`Switch flows ${name} in
|
|
384
|
+
.description(`Switch flows ${name} in an environment`)
|
|
396
385
|
.argument('[keys...]', 'The flows to switch, by key')
|
|
397
386
|
.option('--all', "Every flow the project's paths define")
|
|
398
387
|
.option('--env <env>', ENV_HELP)
|
|
399
388
|
.option('--url <url>', URL_HELP)
|
|
389
|
+
.option('--org <handle>', ORG_HELP)
|
|
400
390
|
.option('--key <key>', KEY_HELP)
|
|
401
391
|
.option('--config <file>', CONFIG_HELP)
|
|
402
392
|
.action((flowKeys, { env: appKey, ...options }) =>
|
|
@@ -425,6 +415,49 @@ const flowsCommand: CommandBuilder = ({ identity }) => {
|
|
|
425
415
|
.addCommand(switchCommand('off'))
|
|
426
416
|
}
|
|
427
417
|
|
|
418
|
+
/** An ISO time a person typed, as the wire takes it; anything else is refused before a call. */
|
|
419
|
+
function isoTime(text: string): string {
|
|
420
|
+
const at = new Date(text)
|
|
421
|
+
if (Number.isNaN(at.getTime())) throw new SessionError(`${text} is not a date and time.`)
|
|
422
|
+
return at.toISOString()
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** The window a replay asks for, each edge given only when typed, as the wire takes it. */
|
|
426
|
+
function replayWindow(flow: string, from?: string, to?: string) {
|
|
427
|
+
if (from !== undefined && to !== undefined) {
|
|
428
|
+
return { flow, from: isoTime(from), to: isoTime(to) }
|
|
429
|
+
}
|
|
430
|
+
if (from !== undefined) return { flow, from: isoTime(from) }
|
|
431
|
+
if (to !== undefined) return { flow, to: isoTime(to) }
|
|
432
|
+
return { flow }
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** `gm pub events replay`: kept events re-delivered to one flow. */
|
|
436
|
+
const eventsCommand: CommandBuilder = ({ identity }) =>
|
|
437
|
+
new Command('events').description("An environment's kept events").addCommand(
|
|
438
|
+
new Command('replay')
|
|
439
|
+
.description(
|
|
440
|
+
"Replay the events an environment kept into one of its flows, over a window its plan's kept days hold; a run the flow already has is not started again",
|
|
441
|
+
)
|
|
442
|
+
.argument('<flow>', 'The flow, by key: a live, switched-on flow started by an event')
|
|
443
|
+
.option('--from <time>', 'The window starts here; the oldest event kept when left out')
|
|
444
|
+
.option('--to <time>', 'The window ends here; now when left out')
|
|
445
|
+
.option('--env <env>', ENV_HELP)
|
|
446
|
+
.option('--url <url>', URL_HELP)
|
|
447
|
+
.option('--org <handle>', ORG_HELP)
|
|
448
|
+
.option('--key <key>', KEY_HELP)
|
|
449
|
+
.action((flow, { env: appKey, from, to, ...options }) =>
|
|
450
|
+
guarded(() =>
|
|
451
|
+
runEventsReplay(
|
|
452
|
+
connect({ ...options, identity }, 'any', 'Replaying events'),
|
|
453
|
+
replayWindow(flow, from, to),
|
|
454
|
+
print,
|
|
455
|
+
appKey,
|
|
456
|
+
),
|
|
457
|
+
),
|
|
458
|
+
),
|
|
459
|
+
)
|
|
460
|
+
|
|
428
461
|
/** `gm pub functions runtime get|set`: where an environment's hosted functions run. */
|
|
429
462
|
const functionsCommand: CommandBuilder = ({ identity }) =>
|
|
430
463
|
new Command('functions').description("An environment's hosted functions").addCommand(
|
|
@@ -435,6 +468,7 @@ const functionsCommand: CommandBuilder = ({ identity }) =>
|
|
|
435
468
|
.description('Show where its functions are to run, and where they run now')
|
|
436
469
|
.argument('<env>', APP_KEY_HELP)
|
|
437
470
|
.option('--url <url>', URL_HELP)
|
|
471
|
+
.option('--org <handle>', ORG_HELP)
|
|
438
472
|
.action((appKey, options) =>
|
|
439
473
|
guarded(() =>
|
|
440
474
|
runRuntimeGet(
|
|
@@ -456,6 +490,7 @@ const functionsCommand: CommandBuilder = ({ identity }) =>
|
|
|
456
490
|
] as const),
|
|
457
491
|
)
|
|
458
492
|
.option('--url <url>', URL_HELP)
|
|
493
|
+
.option('--org <handle>', ORG_HELP)
|
|
459
494
|
.action((appKey, chosen, options) =>
|
|
460
495
|
guarded(() =>
|
|
461
496
|
runRuntimeSet(
|
|
@@ -485,6 +520,7 @@ const storageCommand: CommandBuilder = ({ identity }) =>
|
|
|
485
520
|
)
|
|
486
521
|
.argument('<env>', APP_KEY_HELP)
|
|
487
522
|
.option('--url <url>', URL_HELP)
|
|
523
|
+
.option('--org <handle>', ORG_HELP)
|
|
488
524
|
.action((appKey, options) =>
|
|
489
525
|
guarded(() =>
|
|
490
526
|
runStorageGet(
|
|
@@ -509,6 +545,7 @@ const storageCommand: CommandBuilder = ({ identity }) =>
|
|
|
509
545
|
] as const),
|
|
510
546
|
)
|
|
511
547
|
.option('--url <url>', URL_HELP)
|
|
548
|
+
.option('--org <handle>', ORG_HELP)
|
|
512
549
|
.action((appKey, chosen, options) =>
|
|
513
550
|
guarded(() =>
|
|
514
551
|
runStorageSetDefault(
|
|
@@ -533,6 +570,7 @@ const connectorCommand: CommandBuilder = ({ identity }) =>
|
|
|
533
570
|
.argument('<env>', APP_KEY_HELP)
|
|
534
571
|
.argument('<connection>', 'The data connection, by its key on the Connections page')
|
|
535
572
|
.option('--url <url>', URL_HELP)
|
|
573
|
+
.option('--org <handle>', ORG_HELP)
|
|
536
574
|
.action((appKey, connection, options) =>
|
|
537
575
|
guarded(() =>
|
|
538
576
|
runConnectorCheck(
|
|
@@ -555,6 +593,7 @@ const configCommand: CommandBuilder = ({ identity }) =>
|
|
|
555
593
|
.argument('[file]', 'A JSON file: the list of values, or { values: [...] }')
|
|
556
594
|
.option('--env <env>', ENV_HELP)
|
|
557
595
|
.option('--url <url>', URL_HELP)
|
|
596
|
+
.option('--org <handle>', ORG_HELP)
|
|
558
597
|
.option('--key <key>', KEY_HELP)
|
|
559
598
|
.option('--config <file>', CONFIG_HELP)
|
|
560
599
|
.action((file, { env: appKey, ...options }) =>
|
|
@@ -572,21 +611,396 @@ const configCommand: CommandBuilder = ({ identity }) =>
|
|
|
572
611
|
),
|
|
573
612
|
)
|
|
574
613
|
|
|
614
|
+
const SIGNED_IN_OR_KEY_HELP = `An org key holding the permission the command needs (or ${ENV_KEY}); without one, your sign-in`
|
|
615
|
+
|
|
616
|
+
/** Where to call, which org, and as whom: what every command below hands `connect`. */
|
|
617
|
+
interface CallOptions {
|
|
618
|
+
url?: string
|
|
619
|
+
org?: string
|
|
620
|
+
key?: string
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/** Options every command below takes: where, which org, and as whom. */
|
|
624
|
+
function orgLevel<A extends unknown[], O extends OptionValues, G extends OptionValues>(
|
|
625
|
+
command: Command<A, O, G>,
|
|
626
|
+
) {
|
|
627
|
+
return command
|
|
628
|
+
.option('--url <url>', URL_HELP)
|
|
629
|
+
.option('--org <handle>', ORG_HELP)
|
|
630
|
+
.option('--key <key>', SIGNED_IN_OR_KEY_HELP)
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/** A whole number of at least `min`, as an option's value. */
|
|
634
|
+
function wholeNumber(min: number) {
|
|
635
|
+
return (value: string): number => {
|
|
636
|
+
const parsed = Number(value)
|
|
637
|
+
if (!/^\d+$/.test(value.trim()) || parsed < min) {
|
|
638
|
+
throw new InvalidArgumentError(`Give a whole number of at least ${min}.`)
|
|
639
|
+
}
|
|
640
|
+
return parsed
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/** `gm pub keys`: the org's keys, which servers and pipelines call the platform with. */
|
|
645
|
+
const keysCommand: CommandBuilder = ({ identity }) => {
|
|
646
|
+
const client = (options: CallOptions, what: string) =>
|
|
647
|
+
connect({ ...options, identity }, 'any', what)
|
|
648
|
+
return new Command('keys')
|
|
649
|
+
.description("The org's keys, which servers and pipelines call the platform with")
|
|
650
|
+
.addCommand(
|
|
651
|
+
orgLevel(
|
|
652
|
+
new Command('list')
|
|
653
|
+
.description("List the org's keys, by the start of each; never a secret")
|
|
654
|
+
.option('--project <key>', 'Only those reaching this project')
|
|
655
|
+
.option('--app <key>', 'Only those reaching this environment'),
|
|
656
|
+
).action(({ project, app, ...options }) =>
|
|
657
|
+
guarded(() => runKeyList(client(options, 'Listing keys'), { project, app }, print)),
|
|
658
|
+
),
|
|
659
|
+
)
|
|
660
|
+
.addCommand(
|
|
661
|
+
orgLevel(
|
|
662
|
+
new Command('create')
|
|
663
|
+
.description(
|
|
664
|
+
'Make a key; its secret is printed once, here, and never again. With no --project or --app it reaches the whole org',
|
|
665
|
+
)
|
|
666
|
+
.argument('<name>', 'What it is for, such as backend or ci')
|
|
667
|
+
.addOption(
|
|
668
|
+
new Option('--permission <permission...>', 'What it may do')
|
|
669
|
+
.choices(KEY_PERMISSIONS)
|
|
670
|
+
.makeOptionMandatory(),
|
|
671
|
+
)
|
|
672
|
+
.option('--project <key...>', 'Reach only these projects')
|
|
673
|
+
.option('--app <key...>', 'Reach only these environments, by app key')
|
|
674
|
+
.addOption(
|
|
675
|
+
new Option(
|
|
676
|
+
'--expires-in-days <days>',
|
|
677
|
+
'Days until it stops working by itself',
|
|
678
|
+
).argParser(wholeNumber(1)),
|
|
679
|
+
),
|
|
680
|
+
).action((name, { permission, project, app, expiresInDays, ...options }) =>
|
|
681
|
+
guarded(() =>
|
|
682
|
+
runKeyCreate(
|
|
683
|
+
client(options, 'Creating a key'),
|
|
684
|
+
{ name, permissions: permission, projects: project, apps: app, expiresInDays },
|
|
685
|
+
print,
|
|
686
|
+
),
|
|
687
|
+
),
|
|
688
|
+
),
|
|
689
|
+
)
|
|
690
|
+
.addCommand(
|
|
691
|
+
orgLevel(
|
|
692
|
+
new Command('update')
|
|
693
|
+
.description(
|
|
694
|
+
'Rename a key, or change what it may do or reach; what you leave out stays as it is',
|
|
695
|
+
)
|
|
696
|
+
.argument('<keyId>', 'The key, by its id from `gm pub keys list`')
|
|
697
|
+
.option('--name <name>', 'Its new name')
|
|
698
|
+
.addOption(
|
|
699
|
+
new Option('--permission <permission...>', 'Everything it may do from now on').choices(
|
|
700
|
+
KEY_PERMISSIONS,
|
|
701
|
+
),
|
|
702
|
+
)
|
|
703
|
+
.option('--project <key...>', 'Reach only these projects from now on')
|
|
704
|
+
.option('--app <key...>', 'Reach only these environments from now on'),
|
|
705
|
+
).action((keyId, { name, permission, project, app, ...options }) =>
|
|
706
|
+
guarded(() =>
|
|
707
|
+
runKeyUpdate(
|
|
708
|
+
client(options, 'Changing a key'),
|
|
709
|
+
keyId,
|
|
710
|
+
{ name, permissions: permission, projects: project, apps: app },
|
|
711
|
+
print,
|
|
712
|
+
),
|
|
713
|
+
),
|
|
714
|
+
),
|
|
715
|
+
)
|
|
716
|
+
.addCommand(
|
|
717
|
+
orgLevel(
|
|
718
|
+
new Command('revoke')
|
|
719
|
+
.description('Revoke a key: it stops working at once, everywhere, and cannot be restored')
|
|
720
|
+
.argument('<keyId>', 'The key, by its id from `gm pub keys list`'),
|
|
721
|
+
).action((keyId, options) =>
|
|
722
|
+
guarded(() => runKeyRevoke(client(options, 'Revoking a key'), keyId, print)),
|
|
723
|
+
),
|
|
724
|
+
)
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/** `gm pub pools`: the org's job pools and the runners connected to them. */
|
|
728
|
+
const poolsCommand: CommandBuilder = ({ identity }) => {
|
|
729
|
+
const client = (options: CallOptions, what: string) =>
|
|
730
|
+
connect({ ...options, identity }, 'any', what)
|
|
731
|
+
const settings = <A extends unknown[], O extends OptionValues, G extends OptionValues>(
|
|
732
|
+
command: Command<A, O, G>,
|
|
733
|
+
) =>
|
|
734
|
+
command
|
|
735
|
+
.option('--label <label...>', 'The labels a job must ask for to be taken here')
|
|
736
|
+
.option('--app <key...>', 'The environments it serves, by app key')
|
|
737
|
+
.addOption(
|
|
738
|
+
new Option('--max-running <jobs>', 'Jobs at once across its runners').argParser(
|
|
739
|
+
wholeNumber(1),
|
|
740
|
+
),
|
|
741
|
+
)
|
|
742
|
+
.addOption(
|
|
743
|
+
new Option('--max-runners <runners>', 'Runners connected at once').argParser(
|
|
744
|
+
wholeNumber(1),
|
|
745
|
+
),
|
|
746
|
+
)
|
|
747
|
+
return new Command('pools')
|
|
748
|
+
.description("The org's job pools, and the runners connected to them")
|
|
749
|
+
.addCommand(
|
|
750
|
+
orgLevel(new Command('list').description("List the org's pools, with their queues")).action(
|
|
751
|
+
(options) => guarded(() => runPoolList(client(options, 'Listing pools'), print)),
|
|
752
|
+
),
|
|
753
|
+
)
|
|
754
|
+
.addCommand(
|
|
755
|
+
orgLevel(
|
|
756
|
+
new Command('show').description('Show one pool').argument('<pool>', "The pool's name"),
|
|
757
|
+
).action((pool, options) =>
|
|
758
|
+
guarded(() => runPoolShow(client(options, 'Reading a pool'), pool, print)),
|
|
759
|
+
),
|
|
760
|
+
)
|
|
761
|
+
.addCommand(
|
|
762
|
+
settings(
|
|
763
|
+
orgLevel(
|
|
764
|
+
new Command('create')
|
|
765
|
+
.description('Make a pool')
|
|
766
|
+
.argument('<name>', 'Its name: lower case letters, digits and dashes')
|
|
767
|
+
.addOption(
|
|
768
|
+
new Option('--kind <kind>', 'Who runs its jobs')
|
|
769
|
+
.choices(POOL_KINDS)
|
|
770
|
+
.makeOptionMandatory(),
|
|
771
|
+
),
|
|
772
|
+
),
|
|
773
|
+
).action((name, { kind, label, app, maxRunning, maxRunners, ...options }) =>
|
|
774
|
+
guarded(() =>
|
|
775
|
+
runPoolCreate(
|
|
776
|
+
client(options, 'Creating a pool'),
|
|
777
|
+
{ name, kind, labels: label, apps: app, maxRunning, maxRunners },
|
|
778
|
+
print,
|
|
779
|
+
),
|
|
780
|
+
),
|
|
781
|
+
),
|
|
782
|
+
)
|
|
783
|
+
.addCommand(
|
|
784
|
+
settings(
|
|
785
|
+
orgLevel(
|
|
786
|
+
new Command('update')
|
|
787
|
+
.description("Change a pool's labels, environments or limits; what you leave out stays")
|
|
788
|
+
.argument('<pool>', "The pool's name"),
|
|
789
|
+
),
|
|
790
|
+
).action((pool, { label, app, maxRunning, maxRunners, ...options }) =>
|
|
791
|
+
guarded(() =>
|
|
792
|
+
runPoolUpdate(
|
|
793
|
+
client(options, 'Changing a pool'),
|
|
794
|
+
pool,
|
|
795
|
+
{ labels: label, apps: app, maxRunning, maxRunners },
|
|
796
|
+
print,
|
|
797
|
+
),
|
|
798
|
+
),
|
|
799
|
+
),
|
|
800
|
+
)
|
|
801
|
+
.addCommand(
|
|
802
|
+
orgLevel(
|
|
803
|
+
new Command('remove')
|
|
804
|
+
.description('Remove a pool; its jobs go back to the queue')
|
|
805
|
+
.argument('<pool>', "The pool's name"),
|
|
806
|
+
).action((pool, options) =>
|
|
807
|
+
guarded(() => runPoolRemove(client(options, 'Removing a pool'), pool, print)),
|
|
808
|
+
),
|
|
809
|
+
)
|
|
810
|
+
.addCommand(
|
|
811
|
+
orgLevel(
|
|
812
|
+
new Command('runners')
|
|
813
|
+
.description('List the runners connected to a pool now')
|
|
814
|
+
.argument('<pool>', "The pool's name"),
|
|
815
|
+
).action((pool, options) =>
|
|
816
|
+
guarded(() => runRunnerList(client(options, 'Listing runners'), pool, print)),
|
|
817
|
+
),
|
|
818
|
+
)
|
|
819
|
+
.addCommand(
|
|
820
|
+
orgLevel(
|
|
821
|
+
new Command('drop-runner')
|
|
822
|
+
.description('Drop one runner from a pool; the jobs it holds go back to the queue')
|
|
823
|
+
.argument('<pool>', "The pool's name")
|
|
824
|
+
.argument('<runner>', 'The runner, by its id from `gm pub pools runners`'),
|
|
825
|
+
).action((pool, runner, options) =>
|
|
826
|
+
guarded(() => runRunnerDrop(client(options, 'Dropping a runner'), pool, runner, print)),
|
|
827
|
+
),
|
|
828
|
+
)
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/** A job's input, from `--input` or `--input-file`; an empty object with neither. */
|
|
832
|
+
function jobInputOf(options: { input?: string; inputFile?: string }): Json {
|
|
833
|
+
if (options.input !== undefined && options.inputFile !== undefined) {
|
|
834
|
+
throw new PlatformError('Give --input or --input-file, not both.', 400)
|
|
835
|
+
}
|
|
836
|
+
const text =
|
|
837
|
+
options.inputFile !== undefined ? readFileSync(options.inputFile, 'utf8') : options.input
|
|
838
|
+
if (text === undefined) return {}
|
|
839
|
+
try {
|
|
840
|
+
return parseJsonText(text)
|
|
841
|
+
} catch {
|
|
842
|
+
throw new PlatformError("The job's input is not JSON.", 400)
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/** `gm pub jobs`: an environment's jobs. */
|
|
847
|
+
const jobsCommand: CommandBuilder = ({ identity }) => {
|
|
848
|
+
const client = (options: CallOptions, what: string) =>
|
|
849
|
+
connect({ ...options, identity }, 'any', what)
|
|
850
|
+
return new Command('jobs')
|
|
851
|
+
.description("An environment's jobs")
|
|
852
|
+
.addCommand(
|
|
853
|
+
orgLevel(
|
|
854
|
+
new Command('list')
|
|
855
|
+
.description('List its jobs, newest first')
|
|
856
|
+
.argument('<env>', APP_KEY_HELP)
|
|
857
|
+
.option('--state <states>', 'Only these states, comma separated, such as failed,queued')
|
|
858
|
+
.option('--type <type>', 'Only jobs of this type')
|
|
859
|
+
.option('--schedule <key>', 'Only jobs this schedule queued')
|
|
860
|
+
.addOption(new Option('--limit <count>', 'At most this many').argParser(wholeNumber(1)))
|
|
861
|
+
.option('--cursor <cursor>', 'The page after the one that printed it'),
|
|
862
|
+
).action((appKey, { state, type, schedule, limit, cursor, ...options }) =>
|
|
863
|
+
guarded(() =>
|
|
864
|
+
runJobList(
|
|
865
|
+
client(options, 'Listing jobs'),
|
|
866
|
+
appKey,
|
|
867
|
+
{ state, type, schedule, limit, cursor },
|
|
868
|
+
print,
|
|
869
|
+
),
|
|
870
|
+
),
|
|
871
|
+
),
|
|
872
|
+
)
|
|
873
|
+
.addCommand(
|
|
874
|
+
orgLevel(
|
|
875
|
+
new Command('show')
|
|
876
|
+
.description('Show one job: its state, attempts, progress, input, outputs and log')
|
|
877
|
+
.argument('<env>', APP_KEY_HELP)
|
|
878
|
+
.argument('<job>', "The job's id"),
|
|
879
|
+
).action((appKey, job, options) =>
|
|
880
|
+
guarded(() => runJobShow(client(options, 'Reading a job'), appKey, job, print)),
|
|
881
|
+
),
|
|
882
|
+
)
|
|
883
|
+
.addCommand(
|
|
884
|
+
orgLevel(
|
|
885
|
+
new Command('enqueue')
|
|
886
|
+
.description('Queue a job')
|
|
887
|
+
.argument('<env>', APP_KEY_HELP)
|
|
888
|
+
.argument('<type>', "The job's type")
|
|
889
|
+
.option('--input <json>', 'Its input, as JSON')
|
|
890
|
+
.option('--input-file <file>', 'Its input, from a JSON file')
|
|
891
|
+
.option('--idempotency-key <key>', 'A repeat with the same key answers the first job')
|
|
892
|
+
.addOption(
|
|
893
|
+
new Option('--delay <seconds>', 'Seconds before it may run').argParser(wholeNumber(0)),
|
|
894
|
+
),
|
|
895
|
+
).action((appKey, type, { input, inputFile, idempotencyKey, delay, ...options }) =>
|
|
896
|
+
guarded(() =>
|
|
897
|
+
runJobEnqueue(
|
|
898
|
+
client(options, 'Queueing a job'),
|
|
899
|
+
appKey,
|
|
900
|
+
{
|
|
901
|
+
type,
|
|
902
|
+
input: jobInputOf({ input, inputFile }),
|
|
903
|
+
idempotencyKey,
|
|
904
|
+
delaySeconds: delay,
|
|
905
|
+
},
|
|
906
|
+
print,
|
|
907
|
+
),
|
|
908
|
+
),
|
|
909
|
+
),
|
|
910
|
+
)
|
|
911
|
+
.addCommand(
|
|
912
|
+
orgLevel(
|
|
913
|
+
new Command('retry')
|
|
914
|
+
.description('Queue a failed or dead-lettered job again')
|
|
915
|
+
.argument('<env>', APP_KEY_HELP)
|
|
916
|
+
.argument('<job>', "The job's id"),
|
|
917
|
+
).action((appKey, job, options) =>
|
|
918
|
+
guarded(() => runJobRetry(client(options, 'Retrying a job'), appKey, job, print)),
|
|
919
|
+
),
|
|
920
|
+
)
|
|
921
|
+
.addCommand(
|
|
922
|
+
orgLevel(
|
|
923
|
+
new Command('cancel')
|
|
924
|
+
.description('Cancel a job; a running one stops at its next heartbeat')
|
|
925
|
+
.argument('<env>', APP_KEY_HELP)
|
|
926
|
+
.argument('<job>', "The job's id"),
|
|
927
|
+
).action((appKey, job, options) =>
|
|
928
|
+
guarded(() => runJobCancel(client(options, 'Cancelling a job'), appKey, job, print)),
|
|
929
|
+
),
|
|
930
|
+
)
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/** `gm pub schedules`: an environment's schedules. */
|
|
934
|
+
const schedulesCommand: CommandBuilder = ({ identity }) => {
|
|
935
|
+
const client = (options: CallOptions, what: string) =>
|
|
936
|
+
connect({ ...options, identity }, 'any', what)
|
|
937
|
+
const switching = (name: 'pause' | 'resume', description: string) =>
|
|
938
|
+
orgLevel(
|
|
939
|
+
new Command(name)
|
|
940
|
+
.description(description)
|
|
941
|
+
.argument('<env>', APP_KEY_HELP)
|
|
942
|
+
.argument('<schedule>', "The schedule's key"),
|
|
943
|
+
).action((appKey, schedule, options) =>
|
|
944
|
+
guarded(() =>
|
|
945
|
+
runSchedulePause(
|
|
946
|
+
client(options, name === 'pause' ? 'Pausing a schedule' : 'Resuming a schedule'),
|
|
947
|
+
appKey,
|
|
948
|
+
schedule,
|
|
949
|
+
name === 'pause',
|
|
950
|
+
print,
|
|
951
|
+
),
|
|
952
|
+
),
|
|
953
|
+
)
|
|
954
|
+
return new Command('schedules')
|
|
955
|
+
.description("An environment's schedules")
|
|
956
|
+
.addCommand(
|
|
957
|
+
orgLevel(
|
|
958
|
+
new Command('list')
|
|
959
|
+
.description('List its live schedules, and whether each is paused')
|
|
960
|
+
.argument('<env>', APP_KEY_HELP),
|
|
961
|
+
).action((appKey, options) =>
|
|
962
|
+
guarded(() => runScheduleList(client(options, 'Listing schedules'), appKey, print)),
|
|
963
|
+
),
|
|
964
|
+
)
|
|
965
|
+
.addCommand(switching('pause', 'Stop a schedule ticking'))
|
|
966
|
+
.addCommand(switching('resume', 'Start it again; ticks missed while paused are skipped'))
|
|
967
|
+
.addCommand(
|
|
968
|
+
orgLevel(
|
|
969
|
+
new Command('run')
|
|
970
|
+
.description('Fire one tick now, outside the schedule')
|
|
971
|
+
.argument('<env>', APP_KEY_HELP)
|
|
972
|
+
.argument('<schedule>', "The schedule's key")
|
|
973
|
+
.option(
|
|
974
|
+
'--at <time>',
|
|
975
|
+
`The tick to fire, as an RFC 3339 time no more than ${SCHEDULE_TICK_DAYS} days ago, as long as the engine keeps a schedule's ticks; now when left out`,
|
|
976
|
+
),
|
|
977
|
+
).action((appKey, schedule, { at, ...options }) =>
|
|
978
|
+
guarded(() =>
|
|
979
|
+
runScheduleRun(client(options, 'Running a schedule'), appKey, schedule, at, print),
|
|
980
|
+
),
|
|
981
|
+
),
|
|
982
|
+
)
|
|
983
|
+
}
|
|
984
|
+
|
|
575
985
|
/** `gm pub`: GreenMind's publishing platform. */
|
|
576
986
|
export const PUBLISHING: ProductGroup = {
|
|
577
987
|
name: 'pub',
|
|
578
988
|
aliases: ['publishing'],
|
|
579
989
|
description:
|
|
580
|
-
"GreenMind's publishing platform: environments,
|
|
990
|
+
"GreenMind's publishing platform: environments, the project's flows, functions and config, the org's keys and job pools, and environments' jobs and schedules",
|
|
581
991
|
commands: (context) => [
|
|
582
992
|
envCommand(context),
|
|
583
|
-
keysCommand(context),
|
|
584
993
|
...definitionCommands(context),
|
|
585
994
|
flowsCommand(context),
|
|
995
|
+
eventsCommand(context),
|
|
586
996
|
functionsCommand(context),
|
|
587
997
|
storageCommand(context),
|
|
588
998
|
connectorCommand(context),
|
|
589
999
|
configCommand(context),
|
|
1000
|
+
keysCommand(context),
|
|
1001
|
+
poolsCommand(context),
|
|
1002
|
+
jobsCommand(context),
|
|
1003
|
+
schedulesCommand(context),
|
|
590
1004
|
],
|
|
591
1005
|
}
|
|
592
1006
|
|
|
@@ -608,7 +1022,9 @@ export function buildGmCommand(
|
|
|
608
1022
|
if (taken.has(name)) throw new Error(`Two commands are both named ${name}.`)
|
|
609
1023
|
taken.add(name)
|
|
610
1024
|
}
|
|
611
|
-
|
|
1025
|
+
// A runner serves an org's pool with an org key rather than a sign-in, and belongs to no one
|
|
1026
|
+
// product, so it sits beside the sign-in commands.
|
|
1027
|
+
for (const command of [...signInCommands(context), runnerCommand()]) {
|
|
612
1028
|
claim(command.name())
|
|
613
1029
|
root.addCommand(command)
|
|
614
1030
|
}
|