mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-17 04:09:07 +02:00
Improve owner config parsing
This commit is contained in:
@@ -186,3 +186,18 @@ func OwnerPrincipalForIdentity(id Identity) string {
|
|||||||
}
|
}
|
||||||
return UIDPrincipal(id.UID)
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -578,16 +578,28 @@ func readProfileName(path string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// nolint: unused,unusedfunc
|
// nolint: unused,unusedfunc
|
||||||
func readProfileOwner(path string) []string {
|
func readProfileOwner(path string) (ipcauth.Identity, error) {
|
||||||
data, err := os.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []string{}
|
return ipcauth.Identity{}, err
|
||||||
}
|
}
|
||||||
var meta ownerMeta
|
var meta ownerMeta
|
||||||
if err := json.Unmarshal(data, &meta); err != nil {
|
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
|
// nolint: unused,unusedfunc
|
||||||
|
|||||||
Reference in New Issue
Block a user