A (hardware-ingest-json v2.8-2.9): remove sensor location fields from schema and collector; tag HardwareMemory.Location as json:"-"; add PlatformConfig to HardwareSnapshot. B (no-hardcoded-vendors): consolidate PCI vendor IDs into collector/pci_vendors.go; replace all vendor-name string checks in isGPUDevice, isNVIDIADevice, isMellanoxDevice, isAMDGPUDevice, matchesGPUVendor (sat_overlay), and validateIsVendorGPU (page_validate) with numeric vendor_id comparisons. C (module-structure): split app/app.go (1413 lines) into app.go + app_format.go, app_network.go, app_services.go, app_packs.go, app_install.go — no logic changes. D (go-code-style): wrap bare return err in interfaceAdminState and interfaceIPv4Addrs (platform/network.go) with fmt.Errorf context including the interface name. E (go-project-bible): add bible-local/architecture/data-model.md and bible-local/architecture/api-surface.md. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
107 lines
2.9 KiB
Go
107 lines
2.9 KiB
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"bee/audit/internal/platform"
|
|
)
|
|
|
|
func (a *App) ListInterfaces() ([]platform.InterfaceInfo, error) {
|
|
return a.network.ListInterfaces()
|
|
}
|
|
|
|
func (a *App) DefaultRoute() string {
|
|
return a.network.DefaultRoute()
|
|
}
|
|
|
|
func (a *App) DHCPOne(iface string) (string, error) {
|
|
return a.network.DHCPOne(iface)
|
|
}
|
|
|
|
func (a *App) DHCPOneResult(iface string) (ActionResult, error) {
|
|
body, err := a.network.DHCPOne(iface)
|
|
return ActionResult{Title: "DHCP: " + iface, Body: bodyOr(body, "DHCP completed.")}, err
|
|
}
|
|
|
|
func (a *App) DHCPAll() (string, error) {
|
|
return a.network.DHCPAll()
|
|
}
|
|
|
|
func (a *App) DHCPAllResult() (ActionResult, error) {
|
|
body, err := a.network.DHCPAll()
|
|
return ActionResult{Title: "DHCP: all interfaces", Body: bodyOr(body, "DHCP completed.")}, err
|
|
}
|
|
|
|
func (a *App) SetStaticIPv4(cfg platform.StaticIPv4Config) (string, error) {
|
|
return a.network.SetStaticIPv4(cfg)
|
|
}
|
|
|
|
func (a *App) SetInterfaceState(iface string, up bool) error {
|
|
return a.network.SetInterfaceState(iface, up)
|
|
}
|
|
|
|
func (a *App) GetInterfaceState(iface string) (bool, error) {
|
|
return a.network.GetInterfaceState(iface)
|
|
}
|
|
|
|
func (a *App) CaptureNetworkSnapshot() (platform.NetworkSnapshot, error) {
|
|
return a.network.CaptureNetworkSnapshot()
|
|
}
|
|
|
|
func (a *App) RestoreNetworkSnapshot(snapshot platform.NetworkSnapshot) error {
|
|
return a.network.RestoreNetworkSnapshot(snapshot)
|
|
}
|
|
|
|
func (a *App) SetStaticIPv4Result(cfg platform.StaticIPv4Config) (ActionResult, error) {
|
|
body, err := a.network.SetStaticIPv4(cfg)
|
|
return ActionResult{Title: "Static IPv4: " + cfg.Interface, Body: bodyOr(body, "Static IPv4 updated.")}, err
|
|
}
|
|
|
|
func (a *App) NetworkStatus() (ActionResult, error) {
|
|
ifaces, err := a.network.ListInterfaces()
|
|
if err != nil {
|
|
return ActionResult{Title: "Network status"}, err
|
|
}
|
|
if len(ifaces) == 0 {
|
|
return ActionResult{Title: "Network status", Body: "No physical interfaces found."}, nil
|
|
}
|
|
var body strings.Builder
|
|
for _, iface := range ifaces {
|
|
ipv4 := "(no IPv4)"
|
|
if len(iface.IPv4) > 0 {
|
|
ipv4 = strings.Join(iface.IPv4, ", ")
|
|
}
|
|
fmt.Fprintf(&body, "- %s: state=%s ip=%s\n", iface.Name, iface.State, ipv4)
|
|
}
|
|
if gw := a.network.DefaultRoute(); gw != "" {
|
|
fmt.Fprintf(&body, "\nDefault route: %s\n", gw)
|
|
}
|
|
return ActionResult{Title: "Network status", Body: strings.TrimSpace(body.String())}, nil
|
|
}
|
|
|
|
func (a *App) DefaultStaticIPv4FormFields(iface string) []string {
|
|
return []string{
|
|
"",
|
|
"24",
|
|
strings.TrimSpace(a.network.DefaultRoute()),
|
|
"77.88.8.8 77.88.8.1 1.1.1.1 8.8.8.8",
|
|
}
|
|
}
|
|
|
|
func (a *App) ParseStaticIPv4Config(iface string, fields []string) platform.StaticIPv4Config {
|
|
get := func(index int) string {
|
|
if index >= 0 && index < len(fields) {
|
|
return strings.TrimSpace(fields[index])
|
|
}
|
|
return ""
|
|
}
|
|
return platform.StaticIPv4Config{
|
|
Interface: iface,
|
|
Address: get(0),
|
|
Prefix: get(1),
|
|
Gateway: get(2),
|
|
DNS: strings.Fields(get(3)),
|
|
}
|
|
}
|