93 lines
3.1 KiB
Go
93 lines
3.1 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"bee/audit/internal/platform"
|
|
)
|
|
|
|
func (a *App) ListRemovableTargets() ([]platform.RemovableTarget, error) {
|
|
return a.exports.ListRemovableTargets()
|
|
}
|
|
|
|
// ListScenarioFilesOnRemovableMedia lists scenarios/*.json found on any
|
|
// mounted removable target (e.g. the blackbox USB stick) — see
|
|
// platform.System.ListScenarioFilesOnRemovableMedia.
|
|
func (a *App) ListScenarioFilesOnRemovableMedia() ([]platform.ScenarioFileOnRemovableMedia, error) {
|
|
return a.exports.ListScenarioFilesOnRemovableMedia()
|
|
}
|
|
|
|
// ReadScenarioFromRemovableMedia reads scenarios/<name>.json from whichever
|
|
// mounted removable target has it — see
|
|
// platform.System.ReadScenarioFromRemovableMedia.
|
|
func (a *App) ReadScenarioFromRemovableMedia(name string) ([]byte, error) {
|
|
return a.exports.ReadScenarioFromRemovableMedia(name)
|
|
}
|
|
|
|
// ListAvailableScenarios lists every scenario runnable via ReadScenario:
|
|
// shipped with the image plus anything found on removable media — see
|
|
// platform.System.ListAvailableScenarios.
|
|
func (a *App) ListAvailableScenarios() ([]platform.ScenarioFileOnRemovableMedia, error) {
|
|
return a.exports.ListAvailableScenarios()
|
|
}
|
|
|
|
// ReadScenario resolves scenarios/<name>.json, preferring the copy shipped
|
|
// with the image over one on removable media — see
|
|
// platform.System.ReadScenario.
|
|
func (a *App) ReadScenario(name string) ([]byte, error) {
|
|
return a.exports.ReadScenario(name)
|
|
}
|
|
|
|
func (a *App) ExportLatestAudit(target platform.RemovableTarget) (string, error) {
|
|
if _, err := os.Stat(DefaultAuditJSONPath); err != nil {
|
|
return "", err
|
|
}
|
|
filename := fmt.Sprintf("audit-%s-%s.json", sanitizeFilename(hostnameOr("unknown")), time.Now().UTC().Format("20060102-150405"))
|
|
tmpPath := filepath.Join(os.TempDir(), filename)
|
|
data, err := readFileLimited(DefaultAuditJSONPath, 100<<20)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if normalized, normErr := ApplySATOverlay(data); normErr == nil {
|
|
data = normalized
|
|
}
|
|
if err := os.WriteFile(tmpPath, data, 0644); err != nil {
|
|
return "", err
|
|
}
|
|
defer os.Remove(tmpPath)
|
|
return a.exports.ExportFileToTarget(tmpPath, target)
|
|
}
|
|
|
|
func (a *App) ExportSupportBundle(target platform.RemovableTarget) (string, error) {
|
|
archive, err := BuildSupportBundle(DefaultExportDir)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer os.Remove(archive)
|
|
return a.exports.ExportFileToTarget(archive, target)
|
|
}
|
|
|
|
func (a *App) ExportSupportBundleResult(target platform.RemovableTarget) (ActionResult, error) {
|
|
path, err := a.ExportSupportBundle(target)
|
|
body := "Support bundle export failed."
|
|
if err == nil {
|
|
body = "Support bundle exported. USB target unmounted and safe to remove."
|
|
}
|
|
if err == nil && path != "" {
|
|
body = "Support bundle exported to " + path + ".\n\nUSB target unmounted and safe to remove."
|
|
}
|
|
return ActionResult{Title: "Export support bundle", Body: body}, err
|
|
}
|
|
|
|
func (a *App) ListInstallDisks() ([]platform.InstallDisk, error) {
|
|
return a.installer.ListInstallDisks()
|
|
}
|
|
|
|
func (a *App) InstallToDisk(ctx context.Context, device string, logFile string) error {
|
|
return a.installer.InstallToDisk(ctx, device, logFile)
|
|
}
|