benignswarm 0.12.95 → 0.12.97

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.
@@ -44,10 +44,63 @@ export async function cloudAdmin(action, rest, p, out) {
44
44
  }
45
45
  case "launch": {
46
46
  const machine = need(p.flags, "machine"), idempotency = need(p.flags, "idempotency-key");
47
- const r = await c.call("POST", "/cloud/operations", { machine_id: machine, idempotency_key: idempotency });
48
- out.print(`Cloud operation ${r.operation.id}: ${r.operation.state} (${r.operation.idempotency_key})`, r);
47
+ const r = await c.call("POST", "/cloud/operations", {
48
+ machine_id: machine,
49
+ idempotency_key: idempotency,
50
+ ...(str(p.flags, "project") ? { project: str(p.flags, "project") } : {}),
51
+ ...(str(p.flags, "machine-name") ? { machine_name: str(p.flags, "machine-name") } : {}),
52
+ ...(str(p.flags, "recipe-version") ? { recipe_version: str(p.flags, "recipe-version") } : {}),
53
+ ...(str(p.flags, "node-version") ? { node_version: str(p.flags, "node-version") } : {}),
54
+ ...(str(p.flags, "node-sha256") ? { node_sha256: str(p.flags, "node-sha256") } : {}),
55
+ ...(str(p.flags, "b9s-version") ? { b9s_version: str(p.flags, "b9s-version") } : {}),
56
+ ...(str(p.flags, "base-image") ? { base_image: str(p.flags, "base-image") } : {}),
57
+ });
58
+ const bootNote = r.bootstrap?.token_prefix ? `\nSingle-use sealed bootstrap token prefix ${r.bootstrap.token_prefix} (expires ${r.bootstrap.expires_at}); retrieved once by the launched instance via ${r.bootstrap.retrieve_path ?? "/cloud/bootstrap/retrieve"}.` : "";
59
+ out.print(`Cloud operation ${r.operation.id}: ${r.operation.state} (${r.operation.idempotency_key})${bootNote}`, r);
49
60
  return;
50
61
  }
62
+ case "bootstrap-script": {
63
+ const q = new URLSearchParams();
64
+ for (const k of ["recipe-version", "node-version", "node-sha256", "b9s-version", "base-image"]) {
65
+ const v = str(p.flags, k);
66
+ if (v)
67
+ q.set(k.replace(/-/g, "_"), v);
68
+ }
69
+ const qs = q.toString();
70
+ const r = await c.call("GET", `/cloud/connections/bootstrap-script${qs ? `?${qs}` : ""}`);
71
+ out.print(r.cloud_init_script, r);
72
+ return;
73
+ }
74
+ case "secret": {
75
+ const sub = rest[0];
76
+ if (sub === "set") {
77
+ const r = await c.call("POST", "/cloud/secrets", {
78
+ harness: need(p.flags, "harness"),
79
+ secret_arn: need(p.flags, "arn"),
80
+ ...(str(p.flags, "provider") ? { provider: str(p.flags, "provider") } : {}),
81
+ ...(str(p.flags, "project") ? { project: str(p.flags, "project") } : {}),
82
+ ...(str(p.flags, "region") ? { region: str(p.flags, "region") } : {}),
83
+ ...(str(p.flags, "name") ? { secret_name: str(p.flags, "name") } : {}),
84
+ });
85
+ out.print(`Registered ${r.secret.harness}/${r.secret.provider} secret reference ${r.secret.secret_name} (${r.secret.region})`, r);
86
+ return;
87
+ }
88
+ if (sub === "list") {
89
+ const proj = str(p.flags, "project");
90
+ const r = await c.call("GET", `/cloud/secrets${proj ? `?project=${encodeURIComponent(proj)}` : ""}`);
91
+ out.print(r.secrets.map((s) => `${s.id} ${s.harness}/${s.provider} ${s.secret_name} ${s.secret_arn}`).join("\n") || "No cloud harness secret references.", r);
92
+ return;
93
+ }
94
+ if (sub === "remove") {
95
+ const id = rest[1];
96
+ if (!id)
97
+ throw new CliError("usage", "cloud secret remove <id>");
98
+ const r = await c.call("DELETE", `/cloud/secrets/${encodeURIComponent(id)}`);
99
+ out.print(`Removed cloud secret reference ${id}.`, r);
100
+ return;
101
+ }
102
+ throw new CliError("usage", "cloud secret <set --harness h --arn arn [--provider p] [--project p] [--region r] | list [--project p] | remove <id>>");
103
+ }
51
104
  case "operations": {
52
105
  const r = await c.call("GET", "/cloud/operations");
53
106
  out.print(JSON.stringify(r.operations, null, 2), r);
@@ -69,6 +122,6 @@ export async function cloudAdmin(action, rest, p, out) {
69
122
  out.print(`Operation ${id}: ${r.state}`, r);
70
123
  return;
71
124
  }
72
- default: throw new CliError("usage", "cloud connect|show|policy|test|disconnect|launch|operations|inspect|terminate");
125
+ default: throw new CliError("usage", "cloud connect|show|policy|test|disconnect|bootstrap-script|secret|launch|operations|inspect|terminate");
73
126
  }
74
127
  }