basic implementation of create/delete pool
This commit is contained in:
42
app/common/utils.go
Normal file
42
app/common/utils.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ParseGroupname(groupname string) (Groupname, error) {
|
||||
g := Groupname{}
|
||||
x := strings.Split(groupname, "-")
|
||||
if len(x) == 1 {
|
||||
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>")
|
||||
}
|
||||
}
|
||||
|
||||
func ParseUsername(username string) (Username, error) {
|
||||
u := Username{}
|
||||
x := strings.Split(username, "@")
|
||||
if len(x) == 2 {
|
||||
u.UserID = x[0]
|
||||
u.Realm = x[1]
|
||||
return u, nil
|
||||
} else {
|
||||
return u, fmt.Errorf("userid did not follow the format <userid>@<realm>")
|
||||
}
|
||||
}
|
||||
|
||||
func (g Groupname) ToString() string {
|
||||
return fmt.Sprintf("%s-%s", g.GroupID, g.Realm)
|
||||
}
|
||||
|
||||
func (u Username) ToString() string {
|
||||
return fmt.Sprintf("%s-%s", u.UserID, u.Realm)
|
||||
}
|
||||
Reference in New Issue
Block a user