add proxmoxaas-common-lib dependency, update types and functions to use proxmoxaas-common-lib
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "proxmoxaas-common-lib"]
|
||||||
|
path = proxmoxaas-common-lib
|
||||||
|
url = https://git.tronnet.net/tronnet/proxmoxaas-common-lib
|
||||||
+15
-86
@@ -1,5 +1,7 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
|
import paas "proxmoxaas-common-lib"
|
||||||
|
|
||||||
type Backend interface {
|
type Backend interface {
|
||||||
NewPool(poolname string) (int, error)
|
NewPool(poolname string) (int, error)
|
||||||
DelPool(poolname string) (int, error)
|
DelPool(poolname string) (int, error)
|
||||||
@@ -13,89 +15,16 @@ type Backend interface {
|
|||||||
DelUserFromGroup(username Username, groupname Groupname) (int, error)
|
DelUserFromGroup(username Username, groupname Groupname) (int, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Pool struct {
|
type Pool = paas.Pool
|
||||||
PoolID string `json:"poolid"`
|
type Groupname = paas.Groupname
|
||||||
Path string `json:"-"` // typically /pool/poolid from proxmox, only used internally
|
type Group = paas.Group
|
||||||
Groups []Group `json:"groups"`
|
type Username = paas.Username
|
||||||
Resources map[string]any `json:"resources"`
|
type User = paas.User
|
||||||
Templates Templates `json:"templates"`
|
type VMID = paas.VMID
|
||||||
AllowedNodes map[string]bool `json:"nodes-allowed"`
|
type Backups = paas.Backups
|
||||||
VMIDRange VMID `json:"vmid-allowed"`
|
type Templates = paas.Templates
|
||||||
Backups Backups `json:"backups-allowed"` // measured in numbers
|
type SimpleResource = paas.SimpleResource
|
||||||
}
|
type SimpleLimit = paas.SimpleLimit
|
||||||
|
type MatchResource = paas.MatchResource
|
||||||
// proxmox typically formats as gid-realm for non pve realms
|
type MatchLimit = paas.MatchLimit
|
||||||
// proxmox realms are formatted without realm values
|
type ResourceTemplate = paas.ResourceTemplate
|
||||||
// I assume that backends store groups by ID only and only proxmox will append the realm string
|
|
||||||
type Groupname struct {
|
|
||||||
GroupID string `json:"gid"`
|
|
||||||
Realm string `json:"realm"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Group struct {
|
|
||||||
Groupname Groupname `json:"groupname"`
|
|
||||||
Role string `json:"role"` // role in owner pool
|
|
||||||
Users []User `json:"users"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Username struct { // ie userid@realm
|
|
||||||
UserID string `json:"uid"`
|
|
||||||
Realm string `json:"realm"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type User struct {
|
|
||||||
Username Username `json:"username"`
|
|
||||||
CN string `json:"cn"` // aka first name
|
|
||||||
SN string `json:"sn"` // aka last name
|
|
||||||
Mail string `json:"mail"`
|
|
||||||
Password string `json:"password"` // only used for POST requests
|
|
||||||
}
|
|
||||||
|
|
||||||
type VMID struct {
|
|
||||||
Min int `json:"min"`
|
|
||||||
MAx int `json:"max"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Backups struct {
|
|
||||||
Max int `json:"max"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Templates struct {
|
|
||||||
Instances struct {
|
|
||||||
LXC map[string]ResourceTemplate `json:"lxc"`
|
|
||||||
QEMU map[string]ResourceTemplate `json:"qemu"`
|
|
||||||
} `json:"instances"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SimpleResource struct {
|
|
||||||
Limits struct {
|
|
||||||
Global SimpleLimit `json:"global"`
|
|
||||||
Nodes map[string]SimpleLimit `json:"nodes"`
|
|
||||||
} `json:"limits"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SimpleLimit struct {
|
|
||||||
Max int `json:"max"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type MatchResource struct {
|
|
||||||
Limits struct {
|
|
||||||
Global []MatchLimit `json:"global"`
|
|
||||||
Nodes map[string][]MatchLimit `json:"nodes"`
|
|
||||||
} `json:"limits"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type MatchLimit struct {
|
|
||||||
Match string `json:"match"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Max int `json:"max"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ResourceTemplate struct {
|
|
||||||
Value string `json:"value"`
|
|
||||||
Resource struct {
|
|
||||||
Enabled bool `json:"enabled"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Amount int `json:"amount"`
|
|
||||||
} `json:"resource"`
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 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 {
|
|
||||||
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>")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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]
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
+6
-5
@@ -9,6 +9,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
paas "proxmoxaas-common-lib"
|
||||||
common "user-manager-api/app/common"
|
common "user-manager-api/app/common"
|
||||||
ldap "user-manager-api/app/ldap"
|
ldap "user-manager-api/app/ldap"
|
||||||
pve "user-manager-api/app/pve"
|
pve "user-manager-api/app/pve"
|
||||||
@@ -58,7 +59,7 @@ func Run(configPath *string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// attempt to parse username
|
// attempt to parse username
|
||||||
body.Username, err = common.ParseUsername(body.UsernameRaw)
|
body.Username, err = paas.ParseUsername(body.UsernameRaw)
|
||||||
if err != nil { // username format incorrect
|
if err != nil { // username format incorrect
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"auth": false, "error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"auth": false, "error": err.Error()})
|
||||||
return
|
return
|
||||||
@@ -167,7 +168,7 @@ func Run(configPath *string) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter groupid")})
|
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter groupid")})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
groupname, err := common.ParseGroupname(groupid)
|
groupname, err := paas.ParseGroupname(groupid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err})
|
||||||
return
|
return
|
||||||
@@ -193,7 +194,7 @@ func Run(configPath *string) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter groupid")})
|
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("Missing required path parameter groupid")})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
groupname, err := common.ParseGroupname(groupid)
|
groupname, err := paas.ParseGroupname(groupid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err})
|
||||||
return
|
return
|
||||||
@@ -225,7 +226,7 @@ func Run(configPath *string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
groupname, err := common.ParseGroupname(groupid)
|
groupname, err := paas.ParseGroupname(groupid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err})
|
||||||
return
|
return
|
||||||
@@ -257,7 +258,7 @@ func Run(configPath *string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
groupname, err := common.ParseGroupname(groupid)
|
groupname, err := paas.ParseGroupname(groupid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -8,8 +8,11 @@ require (
|
|||||||
github.com/go-ldap/ldap/v3 v3.4.13
|
github.com/go-ldap/ldap/v3 v3.4.13
|
||||||
github.com/luthermonson/go-proxmox v0.4.1
|
github.com/luthermonson/go-proxmox v0.4.1
|
||||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
|
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
|
||||||
|
proxmoxaas-common-lib v0.0.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
replace proxmoxaas-common-lib => ./proxmoxaas-common-lib
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Azure/go-ntlmssp v0.1.0 // indirect
|
github.com/Azure/go-ntlmssp v0.1.0 // indirect
|
||||||
github.com/buger/goterm v1.0.4 // indirect
|
github.com/buger/goterm v1.0.4 // indirect
|
||||||
|
|||||||
Submodule
+1
Submodule proxmoxaas-common-lib added at eeaf366e28
Reference in New Issue
Block a user