Initial commit: AetherForge Linux (forge-mesh) v0.1.0-dev
Some checks failed
Test / test (push) Has been cancelled
Some checks failed
Test / test (push) Has been cancelled
This commit is contained in:
62
internal/api/handlers/dropper.go
Normal file
62
internal/api/handlers/dropper.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"forge-mesh/internal/auth"
|
||||
"forge-mesh/internal/forge"
|
||||
)
|
||||
|
||||
// DropperHandler serves the dropper URL and one-liner info to the operator.
|
||||
type DropperHandler struct {
|
||||
DB *sql.DB
|
||||
PublicKeyHex string
|
||||
FleetSecret string
|
||||
Version string
|
||||
}
|
||||
|
||||
type DropperInfo struct {
|
||||
DropperURL string `json:"dropper_url"`
|
||||
InstallURL string `json:"install_url"`
|
||||
OneLiner string `json:"one_liner"`
|
||||
FleetSecret string `json:"fleet_secret"`
|
||||
PublicKey string `json:"public_key"`
|
||||
HasBuild bool `json:"has_build"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
func deckURL(r *http.Request) string {
|
||||
scheme := "http"
|
||||
if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" {
|
||||
scheme = "https"
|
||||
}
|
||||
return fmt.Sprintf("%s://%s", scheme, r.Host)
|
||||
}
|
||||
|
||||
// Info handles GET /api/v1/dropper — returns dropper link, one-liner, and build status.
|
||||
func (h *DropperHandler) Info(w http.ResponseWriter, r *http.Request) {
|
||||
base := deckURL(r)
|
||||
installURL := base + "/install.sh"
|
||||
dropperURL := base + "/get"
|
||||
|
||||
oneLiner := fmt.Sprintf(
|
||||
"FORGE_MESH_FLEET_SECRET=%s bash <(curl -fsSL %s)",
|
||||
h.FleetSecret, installURL,
|
||||
)
|
||||
|
||||
// Check whether a public build exists so the UI can warn if not.
|
||||
_, err := forge.LatestPublic(h.DB, "linux", "amd64")
|
||||
hasBuild := err == nil
|
||||
|
||||
auth.JSON(w, http.StatusOK, DropperInfo{
|
||||
DropperURL: dropperURL,
|
||||
InstallURL: installURL,
|
||||
OneLiner: oneLiner,
|
||||
FleetSecret: h.FleetSecret,
|
||||
PublicKey: h.PublicKeyHex,
|
||||
HasBuild: hasBuild,
|
||||
Version: h.Version,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user