Explorer

definy.run-io-on-server

description
(en) RunService/RunIo: run a compiled wasi.io program (wasmBase64, parts for get_parts) on this server to done, with the HTTP and the secrets of the server (run_wasi_io). Only for administrators (DEFINY_ADMIN_ACCOUNT_IDS) signed with the Authorization header, and only on a server that can run programs (docs/run-location.md)
type
Fn(request: @definy.json, http_request: @http.request) -> @definy.service-io
expression
fn(request$0, http_request$9000) =>
  @definy.read-rpc-authorization(
    request: $9000,
    then: fn(authorization$1) =>
      match $1 {
        #anonymous(_) =>
          @definy.rpc-error(code: "unauthenticated", message: "RunService/RunIo requires an Authorization header"),
        #invalid(message$2) =>
          @definy.rpc-error(code: "unauthenticated", message: $2),
        #account(account_id$3) =>
          @definy.is-admin-account(
            account_id: $3,
            then: fn(is_admin$4) =>
              match $4 {
                false =>
                  @definy.rpc-error(
                    code: "permission_denied",
                    message: "Only the administrators of this server (DEFINY_ADMIN_ACCOUNT_IDS) can run programs on it"
                  ),
                true =>
                  #read_host_settings<@definy.service-io>({
                    then: fn(settings$5) =>
                      match $5.run_expressions {
                        false =>
                          @definy.rpc-error(
                            code: "failed_precondition",
                            message: "This server cannot run programs (only a definy server on Node.js such as node host.js can). Run it in the browser"
                          ),
                        true =>
                          #run_wasi_io<@definy.service-io>({
                            wasm: match @definy.json-get-string(value: $0, key: "wasmBase64") {
                              #some(wasm$6) =>
                                $6,
                              #none(_) =>
                                ""
                            },
                            parts: match @definy.json-get(value: $0, key: "parts") {
                              #some(#array(items$7)) =>
                                @definy.json-wasi-io-parts(items: $7),
                              _ =>
                                []
                            },
                            then: fn(result$8) =>
                              @definy.json-response(
                                status: 200,
                                body: #object<@definy.json>([
                                  {key: "ok", value: #boolean<@definy.json>($8.ok)},
                                  {key: "message", value: #string<@definy.json>($8.message)},
                                  {
                                    key: "steps",
                                    value: #array<@definy.json>(@core.list-map(
                                      T: String,
                                      U: @definy.json,
                                      f: fn(item$9) =>
                                        #string<@definy.json>($9),
                                      xs: $8.steps
                                    ))
                                  }
                                ])
                              )
                          })
                      }
                  })
              }
          )
      }
  )
visibility
public
definy.run-io-on-server (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: daEHkXo5nraKkzUbYPFHZF2yTOfHwkxh8mCbCEgtGto
content hash: IISFIErSLAyphcs0F6EuUInU8RD1s8ANikuwCxYrPmc