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

Function runShare

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

Source from the content-addressed store, hash-verified

225// the common case for handing a link to a consumer.
226
227async function runShare(client: ArtifactClient, args: string[]): Promise<ArtifactsCLIResult> {
228 const parsed = parseFlags(args, {
229 scope: { kind: "value" },
230 ttl: { kind: "value" },
231 });
232 if ("error" in parsed) return argvError("share", parsed.error);
233 const name = parsed.positional[0];
234 if (name === undefined) return argvError("share", "missing <name>");
235 if (parsed.positional.length > 1) {
236 return argvError("share", `unexpected argument '${parsed.positional[1]}'`);
237 }
238
239 let scope: ArtifactScope = "read";
240 if (parsed.flags.scope !== undefined) {
241 const s = parsed.flags.scope as string;
242 if (s !== "read" && s !== "write") {
243 return argvError("share", `--scope must be 'read' or 'write' (got '${s}')`);
244 }
245 scope = s;
246 }
247
248 let ttl: number | undefined;
249 if (parsed.flags.ttl !== undefined) {
250 try {
251 ttl = parseDuration(parsed.flags.ttl as string);
252 } catch (cause) {
253 return argvError("share", cause instanceof Error ? cause.message : String(cause));
254 }
255 }
256
257 try {
258 // Resolve the repo first so a missing repo fails before a token
259 // is minted.
260 const info = await client.get(name);
261 const token = await client.createToken(name, scope, ttl);
262 return ok(`${credentialURL(info.remote, token.plaintext)}\n`);
263 } catch (cause) {
264 return mapError("share", cause);
265 }
266}
267
268/** Resolve a repo, returning undefined on a clean not-found miss. */
269async function tryGet(

Callers 1

runArtifactsCLIFunction · 0.85

Calls 8

argvErrorFunction · 0.85
parseDurationFunction · 0.85
okFunction · 0.85
credentialURLFunction · 0.85
mapErrorFunction · 0.85
parseFlagsFunction · 0.70
getMethod · 0.65
createTokenMethod · 0.65

Tested by

no test coverage detected