MCPcopy Create free account
hub / github.com/cloudflare/computer / runTokenCreate

Function runTokenCreate

packages/computer/src/artifacts/cli.ts:490–525  ·  view source on GitHub ↗
(client: ArtifactClient, args: string[])

Source from the content-addressed store, hash-verified

488}
489
490async function runTokenCreate(client: ArtifactClient, args: string[]): Promise<ArtifactsCLIResult> {
491 const parsed = parseFlags(args, {
492 scope: { kind: "value" },
493 ttl: { kind: "value" },
494 });
495 if ("error" in parsed) return argvError("token create", parsed.error);
496 const repo = parsed.positional[0];
497 if (repo === undefined) return argvError("token create", "missing <repo>");
498 if (parsed.positional.length > 1) {
499 return argvError("token create", `unexpected argument '${parsed.positional[1]}'`);
500 }
501
502 let scope: ArtifactScope | undefined;
503 if (parsed.flags.scope !== undefined) {
504 const s = parsed.flags.scope as string;
505 if (s !== "read" && s !== "write") {
506 return argvError("token create", `--scope must be 'read' or 'write' (got '${s}')`);
507 }
508 scope = s;
509 }
510
511 let ttl: number | undefined;
512 if (parsed.flags.ttl !== undefined) {
513 try {
514 ttl = parseDuration(parsed.flags.ttl as string);
515 } catch (cause) {
516 return argvError("token create", cause instanceof Error ? cause.message : String(cause));
517 }
518 }
519
520 try {
521 return ok(json(await client.createToken(repo, scope, ttl)));
522 } catch (cause) {
523 return mapError("token create", cause);
524 }
525}
526
527async function runTokenList(client: ArtifactClient, args: string[]): Promise<ArtifactsCLIResult> {
528 const parsed = parseFlags(args, {});

Callers 1

runTokenFunction · 0.85

Calls 7

argvErrorFunction · 0.85
parseDurationFunction · 0.85
okFunction · 0.85
jsonFunction · 0.85
mapErrorFunction · 0.85
parseFlagsFunction · 0.70
createTokenMethod · 0.65

Tested by

no test coverage detected