Compare commits
3 Commits
eeaf366e28
...
cc53d7bdea
| Author | SHA1 | Date | |
|---|---|---|---|
| cc53d7bdea | |||
| 7fc7584984 | |||
| 858c5889f1 |
+10
-9
@@ -1,14 +1,14 @@
|
||||
package proxmoxaas_common_lib
|
||||
|
||||
type Pool struct {
|
||||
PoolID string `json:"poolid"`
|
||||
Path string `json:"-"` // typically /pool/poolid from proxmox, only used internally
|
||||
Groups []Group `json:"groups"`
|
||||
Resources map[string]any `json:"resources"`
|
||||
Templates Templates `json:"templates"`
|
||||
AllowedNodes map[string]bool `json:"nodes-allowed"`
|
||||
VMIDRange VMID `json:"vmid-allowed"`
|
||||
Backups Backups `json:"backups-allowed"` // measured in numbers
|
||||
PoolID string `json:"poolid"`
|
||||
Path string `json:"-"` // typically /pool/poolid from proxmox, only used internally
|
||||
Groups []Group `json:"groups"`
|
||||
Resources map[string]any `json:"resources"`
|
||||
Templates Templates `json:"templates"`
|
||||
AllowedNodes map[string]bool `json:"nodes-allowed"`
|
||||
AllowedVMIDRange VMID `json:"vmid-allowed"`
|
||||
AllowedBackups Backups `json:"backups-allowed"`
|
||||
}
|
||||
|
||||
// proxmox typically formats as gid-realm for non pve realms
|
||||
@@ -44,7 +44,8 @@ type VMID struct {
|
||||
}
|
||||
|
||||
type Backups struct {
|
||||
Max int `json:"max"`
|
||||
MaxPerInstance int `json:"max-per-instance"`
|
||||
MaxTotal int `json:"max-total"`
|
||||
}
|
||||
|
||||
type Templates struct {
|
||||
|
||||
+18
-13
@@ -2,7 +2,7 @@ package proxmoxaas_common_lib
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func (g Groupname) ToString() string {
|
||||
@@ -14,19 +14,23 @@ func (u Username) ToString() string {
|
||||
}
|
||||
|
||||
// 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) {
|
||||
g := Groupname{}
|
||||
x := strings.Split(groupname, "-")
|
||||
if len(x) == 1 {
|
||||
// <groupid>-<realm>
|
||||
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.Realm = "pve"
|
||||
return g, nil
|
||||
} else if len(x) == 2 {
|
||||
g.GroupID = x[0]
|
||||
g.Realm = x[1]
|
||||
return g, nil
|
||||
} else {
|
||||
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
|
||||
func ParseUsername(username string) (Username, error) {
|
||||
u := Username{}
|
||||
x := strings.Split(username, "@")
|
||||
if len(x) == 2 {
|
||||
u.UserID = x[0]
|
||||
u.Realm = x[1]
|
||||
m := regexp.MustCompilePOSIX("([[:alnum:]]+)@([[:alnum:]]+)")
|
||||
x := m.FindStringSubmatch(username)
|
||||
if len(x) == 3 {
|
||||
u.UserID = x[1]
|
||||
u.Realm = x[2]
|
||||
return u, nil
|
||||
} else {
|
||||
return u, fmt.Errorf("userid did not follow the format <userid>@<realm>")
|
||||
|
||||
Reference in New Issue
Block a user