Improve owner config parsing

This commit is contained in:
Theodor S. Midtlien
2026-09-07 12:28:36 +02:00
parent 1c93b3f845
commit e5e5e73ebb
2 changed files with 31 additions and 4 deletions
+15
View File
@@ -186,3 +186,18 @@ func OwnerPrincipalForIdentity(id Identity) string {
}
return UIDPrincipal(id.UID)
}
func IdentityFromPrincipal(p Principal) (Identity, error) {
switch p.Kind {
case KindUID:
uid, err := strconv.ParseUint(p.Value, 10, 32)
if err != nil {
return Identity{}, err
}
return Identity{UID: uint32(uid)}, nil
case KindSID:
return Identity{SID: p.Value}, nil
default:
return Identity{}, nil
}
}
+16 -4
View File
@@ -578,16 +578,28 @@ func readProfileName(path string) string {
}
// nolint: unused,unusedfunc
func readProfileOwner(path string) []string {
func readProfileOwner(path string) (ipcauth.Identity, error) {
data, err := os.ReadFile(path)
if err != nil {
return []string{}
return ipcauth.Identity{}, err
}
var meta ownerMeta
if err := json.Unmarshal(data, &meta); err != nil {
return []string{}
return ipcauth.Identity{}, err
}
return meta.Owners
if len(meta.Owners) < 1 {
return ipcauth.Identity{}, nil
}
owner := meta.Owners[0]
principal, ok := ipcauth.ParsePrincipal(owner)
if !ok {
return ipcauth.Identity{}, fmt.Errorf("unexpected owner principal: %s", owner)
}
id, err := ipcauth.IdentityFromPrincipal(principal)
if err != nil {
return id, fmt.Errorf("parsing identity from principal failed: %w", err)
}
return id, nil
}
// nolint: unused,unusedfunc