51 lines
1.3 KiB
Text
51 lines
1.3 KiB
Text
|
|
#!/usr/bin/env nu
|
||
|
|
# Reference Nu script implementing the ScriptRequest/ScriptResponse contract.
|
||
|
|
#
|
||
|
|
# Usage: nu reference.nu --stdin-json
|
||
|
|
# Reads a JSON request from stdin, dispatches on `op`, writes a JSON response to stdout.
|
||
|
|
#
|
||
|
|
# This file is a starting point — copy and adapt it for your provider logic.
|
||
|
|
|
||
|
|
let req = $in | from json
|
||
|
|
|
||
|
|
match $req.op {
|
||
|
|
"spawn" => {
|
||
|
|
# Allocate a handle (use a UUID or provider-assigned ID in real scripts).
|
||
|
|
let handle = (random uuid)
|
||
|
|
{
|
||
|
|
result: "spawn",
|
||
|
|
handle: $handle,
|
||
|
|
ip: null,
|
||
|
|
ssh_host: null,
|
||
|
|
ssh_port: null,
|
||
|
|
expires_at: null,
|
||
|
|
provider: "script-nu",
|
||
|
|
metadata: {}
|
||
|
|
} | to json
|
||
|
|
},
|
||
|
|
|
||
|
|
"destroy" => {
|
||
|
|
# Idempotent: always return ack, even for unknown handles.
|
||
|
|
{ result: "ack" } | to json
|
||
|
|
},
|
||
|
|
|
||
|
|
"status" => {
|
||
|
|
# Return "not_found" if unknown; "running" if known.
|
||
|
|
{ result: "status", value: "running" } | to json
|
||
|
|
},
|
||
|
|
|
||
|
|
"list" => {
|
||
|
|
# Return an array of Instance objects matching the selector.
|
||
|
|
{ result: "list", value: [] } | to json
|
||
|
|
},
|
||
|
|
|
||
|
|
"health" => {
|
||
|
|
{ result: "health", value: true } | to json
|
||
|
|
},
|
||
|
|
|
||
|
|
_ => {
|
||
|
|
eprintln $"unknown op: ($req.op)"
|
||
|
|
exit 1
|
||
|
|
}
|
||
|
|
}
|