package main // The zoo's robot as a creator: git and `ratcloud` over ssh, as `zoo-robot`, the robot creator whose // apps are the zoo's samples it looks after (zoo-broken). A wasm app runs no process of its own: // git and ssh are the platform's named capabilities (`capabilities = git, ssh` in ratcloud.conf, // granted by root with `rc cap zoo git ssh --as zoo-robot`). Each call is one fixed shape (rc.git, // rc.ssh: clone, checkout, write, read, add, commit, push, rev-parse, rm; keygen, ratcloud), run as // the zoo's own unix user in its own workspace, with the robot creator's key from the zoo's secrets, // which never enters this program. It logs in exactly as a creator's laptop does: git, `ratcloud`, // nothing that is a shell. // // Exhibit 8's nightly (broken.odin), 18 (a machine key of its own for a minute) and 30 (asking for a // preview) use it. import "core:strings" import "ratcloud:rc" CREATOR :: "zoo-robot" Ran_Tool :: struct { code: int, // the tool's exit code; -1: it did not run (out says why) out: string, } // git as the robot creator: its exit code and output (git's messages included). creator_git :: proc(t: rc.Tool) -> Ran_Tool { r := rc.git(t) if r.code < 0 do return {-1, r.err} return {r.code, strings.trim_space(string(r.out))} } // `ratcloud ...` over ssh, the verbs a creator's laptop has (tools PLATFORM.md). creator_ratcloud :: proc(words: ..string) -> Ran_Tool { ws := make([]string, len(words)) copy(ws, words) r := rc.ssh({op = "ratcloud", words = ws}) if r.code < 0 do return {-1, r.err} return {r.code, strings.trim_space(string(r.out))} } // git's "remote: " prefixes off, as a person reads a push's answer. unremote :: proc(s: string) -> string { b := strings.builder_make() for line, i in strings.split_lines(s) { if i > 0 do strings.write_byte(&b, '\n') strings.write_string(&b, strings.trim_left_space(strings.trim_prefix(line, "remote:")) if strings.has_prefix(line, "remote:") else line) } return strings.trim_space(strings.to_string(b)) }