Let task agents use client Macs directly: bash, copy and hands
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"g.fc.run/misc/byre/internal/api"
|
||||
"g.fc.run/misc/byre/internal/store"
|
||||
@@ -41,63 +36,6 @@ func (s *Server) GetInboxItem(w http.ResponseWriter, r *http.Request, itemID str
|
||||
writeJSON(w, http.StatusOK, item)
|
||||
}
|
||||
|
||||
func (s *Server) GetRunBundle(w http.ResponseWriter, r *http.Request, itemID string) {
|
||||
item, err := s.store.GetInboxItem(r.Context(), itemID)
|
||||
if err != nil {
|
||||
writeStoreError(w, err)
|
||||
return
|
||||
}
|
||||
if item.Kind != api.ClientRun {
|
||||
writeError(w, http.StatusBadRequest, fmt.Errorf("item %s is a %s, not a client_run", itemID, item.Kind))
|
||||
return
|
||||
}
|
||||
if item.State != api.Open {
|
||||
writeError(w, http.StatusConflict, fmt.Errorf("run request %s is %s", itemID, item.State))
|
||||
return
|
||||
}
|
||||
|
||||
f, err := os.Open(s.store.BundlePath(itemID))
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
info, err := f.Stat()
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/gzip")
|
||||
http.ServeContent(w, r, "", info.ModTime(), f)
|
||||
}
|
||||
|
||||
func (s *Server) ReportRun(w http.ResponseWriter, r *http.Request, itemID string) {
|
||||
req := api.RunReport{}
|
||||
if !readJSON(w, r, &req) {
|
||||
return
|
||||
}
|
||||
|
||||
item, err := s.agents.ReportRun(r.Context(), actor(r), itemID, req)
|
||||
if err != nil {
|
||||
writeAgentError(w, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, item)
|
||||
}
|
||||
|
||||
func (s *Server) removeClosedBundles(events []api.Event) {
|
||||
for _, ev := range events {
|
||||
if ev.Kind != "inbox.updated" || ev.Payload["kind"] != string(api.ClientRun) || ev.Payload["state"] == string(api.Open) {
|
||||
continue
|
||||
}
|
||||
id, _ := ev.Payload["id"].(string)
|
||||
err := os.Remove(s.store.BundlePath(id))
|
||||
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
||||
slog.Error("remove run bundle", "item", id, "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) RespondInbox(w http.ResponseWriter, r *http.Request) {
|
||||
req := api.InboxRespond{}
|
||||
if !readJSON(w, r, &req) {
|
||||
|
||||
Reference in New Issue
Block a user