add disk id to config

This commit is contained in:
Melora Hugues 2023-08-19 10:54:18 +02:00
parent 639f4e60ea
commit 475a444129
5 changed files with 20 additions and 12 deletions

View file

@ -114,13 +114,13 @@ func displayAppList(l *logger.SimpleLogger) {
if a.Active { if a.Active {
prefix = "*" prefix = "*"
} }
l.Infof("\t- %s[%d] %s: %s", prefix, a.ID, a.Name, a.Path) l.Infof("\t- %s[%d] %s: %s (disk id %s)", prefix, a.ID, a.Name, a.Path, a.DiskID)
} }
} }
func getRemoteConfig(l *logger.SimpleLogger, host string, id uuid.UUID, pretty bool) { func getRemoteConfig(l *logger.SimpleLogger, host string, id uuid.UUID, pretty bool) {
l.Info("Getting config from remote server...")
if pretty { if pretty {
l.Info("Getting config from remote server...")
if err := remote.DisplayRemoteConfigPretty(context.Background(), host, id, l); err != nil { if err := remote.DisplayRemoteConfigPretty(context.Background(), host, id, l); err != nil {
l.Fatal(err.Error()) l.Fatal(err.Error())
} }

View file

@ -12,13 +12,14 @@ import (
"git.faercol.me/faercol/http-boot-config/config/logger" "git.faercol.me/faercol/http-boot-config/config/logger"
) )
var efiBootmgrRegexp = regexp.MustCompile(`Boot(?P<id>\d+)\* (?P<name>[\w ]+)\t(\w+\(.*\))/File\((?P<filepath>.+)\)`) var efiBootmgrRegexp = regexp.MustCompile(`Boot(?P<id>\d+)\* (?P<name>[\w ]+)\t(HD\(.+,.+,(?P<disk_id>[0-9a-f-]+),.+,.+\))/File\((?P<filepath>.+)\)`)
var activeRegexp = regexp.MustCompile(`BootCurrent: (\d+)`) var activeRegexp = regexp.MustCompile(`BootCurrent: (\d+)`)
type EfiApp struct { type EfiApp struct {
ID int ID int
Name string Name string
Path string Path string
DiskID string
Active bool Active bool
} }
@ -49,11 +50,16 @@ func efiAppFromBootMgrOutput(rawVal string, activeId int) (app EfiApp, ok bool)
if !ok { if !ok {
return return
} }
disk_id, ok := result["disk_id"]
if !ok {
return
}
return EfiApp{ return EfiApp{
ID: idInt, ID: idInt,
Name: strings.TrimSpace(name), Name: strings.TrimSpace(name),
Path: strings.TrimSpace(filepath), Path: strings.TrimSpace(filepath),
Active: idInt == activeId, Active: idInt == activeId,
DiskID: disk_id,
}, true }, true
} }

View file

@ -10,7 +10,7 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - Windows", func(t *testing.T) { t.Run("OK - Windows", func(t *testing.T) {
rawVal := (`Boot0000* Windows Boot Manager HD(1,GPT,4ad714ba-6a01-4f76-90e3-1bb93a59b67e,0x800,0x32000)/File(\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI)` + rawVal := (`Boot0000* Windows Boot Manager HD(1,GPT,4ad714ba-6a01-4f76-90e3-1bb93a59b67e,0x800,0x32000)/File(\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI)` +
`57494e444f5753000100000088000000780000004200430044004f0042004a004500430054003d007b00390064006500610038003600320063002d0035006300640064002d00`) `57494e444f5753000100000088000000780000004200430044004f0042004a004500430054003d007b00390064006500610038003600320063002d0035006300640064002d00`)
expected := EfiApp{ID: 0, Name: "Windows Boot Manager", Path: `\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI`, Active: true} expected := EfiApp{ID: 0, Name: "Windows Boot Manager", Path: `\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI`, Active: true, DiskID: "4ad714ba-6a01-4f76-90e3-1bb93a59b67e"}
app, ok := efiAppFromBootMgrOutput(rawVal, 0) app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok) assert.True(t, ok)
assert.Equal(t, expected, app) assert.Equal(t, expected, app)
@ -18,7 +18,7 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - Manjaro", func(t *testing.T) { t.Run("OK - Manjaro", func(t *testing.T) {
rawVal := `Boot0001* Manjaro HD(1,GPT,16f06d01-50da-6544-86bd-f3457f980086,0x1000,0x96000)/File(\EFI\MANJARO\GRUBX64.EFI)` rawVal := `Boot0001* Manjaro HD(1,GPT,16f06d01-50da-6544-86bd-f3457f980086,0x1000,0x96000)/File(\EFI\MANJARO\GRUBX64.EFI)`
expected := EfiApp{ID: 1, Name: "Manjaro", Path: `\EFI\MANJARO\GRUBX64.EFI`, Active: false} expected := EfiApp{ID: 1, Name: "Manjaro", Path: `\EFI\MANJARO\GRUBX64.EFI`, Active: false, DiskID: "16f06d01-50da-6544-86bd-f3457f980086"}
app, ok := efiAppFromBootMgrOutput(rawVal, 0) app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok) assert.True(t, ok)
assert.Equal(t, expected, app) assert.Equal(t, expected, app)
@ -26,7 +26,7 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - EFI Base", func(t *testing.T) { t.Run("OK - EFI Base", func(t *testing.T) {
rawVal := `Boot0002* UEFI OS HD(1,GPT,16f06d01-50da-6544-86bd-f3457f980086,0x1000,0x96000)/File(\EFI\BOOT\BOOTX64.EFI)0000424f` rawVal := `Boot0002* UEFI OS HD(1,GPT,16f06d01-50da-6544-86bd-f3457f980086,0x1000,0x96000)/File(\EFI\BOOT\BOOTX64.EFI)0000424f`
expected := EfiApp{ID: 2, Name: "UEFI OS", Path: `\EFI\BOOT\BOOTX64.EFI`, Active: false} expected := EfiApp{ID: 2, Name: "UEFI OS", Path: `\EFI\BOOT\BOOTX64.EFI`, Active: false, DiskID: "16f06d01-50da-6544-86bd-f3457f980086"}
app, ok := efiAppFromBootMgrOutput(rawVal, 0) app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok) assert.True(t, ok)
assert.Equal(t, expected, app) assert.Equal(t, expected, app)

View file

@ -16,8 +16,9 @@ import (
const enrollURL = "/enroll" const enrollURL = "/enroll"
type enrollEFIOption struct { type enrollEFIOption struct {
Name string `json:"name"` Name string `json:"name"`
Path string `json:"path"` Path string `json:"path"`
DiskID string `json:"disk_id"`
} }
type enrollPayload struct { type enrollPayload struct {
@ -37,7 +38,7 @@ func enrollToServer(ctx context.Context, host string, name string, apps []prober
} }
for _, a := range apps { for _, a := range apps {
appID := uuid.New() appID := uuid.New()
payload.Options[appID.String()] = enrollEFIOption{Name: a.Name, Path: a.Path} payload.Options[appID.String()] = enrollEFIOption{Name: a.Name, Path: a.Path, DiskID: a.DiskID}
if a.Active { if a.Active {
payload.SelectedOption = appID.String() payload.SelectedOption = appID.String()
} }

View file

@ -24,8 +24,9 @@ type clientConfig struct {
ID string `json:"ID"` ID string `json:"ID"`
Name string `json:"name"` Name string `json:"name"`
Options map[string]struct { Options map[string]struct {
Name string `json:"name"` Name string `json:"name"`
Path string `json:"path"` Path string `json:"path"`
DiskID string `json:"disk_id"`
} `json:"options"` } `json:"options"`
SelectedOption string `json:"selected_option"` SelectedOption string `json:"selected_option"`
} `json:"efi_config"` } `json:"efi_config"`
@ -103,7 +104,7 @@ func DisplayRemoteConfigPretty(ctx context.Context, host string, id uuid.UUID, l
} }
l.Info(" * Available options are:") l.Info(" * Available options are:")
for _, option := range parsedConf.EFIConfig.Options { for _, option := range parsedConf.EFIConfig.Options {
l.Infof("\t - %s: %s", option.Name, option.Path) l.Infof("\t - %s: %s (disk id %s)", option.Name, option.Path, option.DiskID)
} }
l.Infof(" * Remote boot server is listening on %s:%d", parsedConf.NetConfig.MulticastGroup, parsedConf.NetConfig.Port) l.Infof(" * Remote boot server is listening on %s:%d", parsedConf.NetConfig.MulticastGroup, parsedConf.NetConfig.Port)