Compare commits

..

3 Commits

2 changed files with 28 additions and 22 deletions
+10 -9
View File
@@ -1,14 +1,14 @@
package proxmoxaas_common_lib package proxmoxaas_common_lib
type Pool struct { type Pool struct {
PoolID string `json:"poolid"` PoolID string `json:"poolid"`
Path string `json:"-"` // typically /pool/poolid from proxmox, only used internally Path string `json:"-"` // typically /pool/poolid from proxmox, only used internally
Groups []Group `json:"groups"` Groups []Group `json:"groups"`
Resources map[string]any `json:"resources"` Resources map[string]any `json:"resources"`
Templates Templates `json:"templates"` Templates Templates `json:"templates"`
AllowedNodes map[string]bool `json:"nodes-allowed"` AllowedNodes map[string]bool `json:"nodes-allowed"`
VMIDRange VMID `json:"vmid-allowed"` AllowedVMIDRange VMID `json:"vmid-allowed"`
Backups Backups `json:"backups-allowed"` // measured in numbers AllowedBackups Backups `json:"backups-allowed"`
} }
// proxmox typically formats as gid-realm for non pve realms // proxmox typically formats as gid-realm for non pve realms
@@ -44,7 +44,8 @@ type VMID struct {
} }
type Backups struct { type Backups struct {
Max int `json:"max"` MaxPerInstance int `json:"max-per-instance"`
MaxTotal int `json:"max-total"`
} }
type Templates struct { type Templates struct {
+18 -13
View File
@@ -2,7 +2,7 @@ package proxmoxaas_common_lib
import ( import (
"fmt" "fmt"
"strings" "regexp"
) )
func (g Groupname) ToString() string { func (g Groupname) ToString() string {
@@ -14,19 +14,23 @@ func (u Username) ToString() string {
} }
// returns an error if the groupname format was not correct // returns an error if the groupname format was not correct
// TODO: handle group names with x-y format where y is not a registered realm
// TODO: handle group names with x-y-z-... format
func ParseGroupname(groupname string) (Groupname, error) { func ParseGroupname(groupname string) (Groupname, error) {
g := Groupname{} g := Groupname{}
x := strings.Split(groupname, "-") // <groupid>-<realm>
if len(x) == 1 { m1 := regexp.MustCompilePOSIX("([[:alnum:]]+)-([[:alnum:]]+)")
// <groupid> (implied pve realm)
m2 := regexp.MustCompilePOSIX("([[:alnum:]]+)")
x1 := m1.FindStringSubmatch(groupname)
x2 := m2.FindStringSubmatch(groupname)
if len(x1) == 3 {
g.GroupID = x1[1]
g.Realm = x1[2]
return g, nil
} else if len(x2) == 2 {
g.GroupID = groupname g.GroupID = groupname
g.Realm = "pve" g.Realm = "pve"
return g, nil return g, nil
} else if len(x) == 2 {
g.GroupID = x[0]
g.Realm = x[1]
return g, nil
} else { } else {
return g, fmt.Errorf("groupid did not follow the format <groupid> or <groupid>-<realm>") return g, fmt.Errorf("groupid did not follow the format <groupid> or <groupid>-<realm>")
} }
@@ -35,10 +39,11 @@ func ParseGroupname(groupname string) (Groupname, error) {
// returns an error if the username format was not correct // returns an error if the username format was not correct
func ParseUsername(username string) (Username, error) { func ParseUsername(username string) (Username, error) {
u := Username{} u := Username{}
x := strings.Split(username, "@") m := regexp.MustCompilePOSIX("([[:alnum:]]+)@([[:alnum:]]+)")
if len(x) == 2 { x := m.FindStringSubmatch(username)
u.UserID = x[0] if len(x) == 3 {
u.Realm = x[1] u.UserID = x[1]
u.Realm = x[2]
return u, nil return u, nil
} else { } else {
return u, fmt.Errorf("userid did not follow the format <userid>@<realm>") return u, fmt.Errorf("userid did not follow the format <userid>@<realm>")