basic implementation of create/delete pool

This commit is contained in:
2026-03-02 21:45:39 +00:00
parent 75dd027c59
commit 322f233718
16 changed files with 922 additions and 162 deletions

47
app/common/config.go Normal file
View File

@@ -0,0 +1,47 @@
package app
import (
"encoding/json"
"os"
)
type LDAPConfig struct {
LdapURL string `json:"ldapURL"`
StartTLS bool `json:"startTLS"`
BaseDN string `json:"baseDN"`
}
type PVEConfig struct {
URL string `json:"url"`
}
type RealmConfig struct {
Handler string `json:"handler"`
}
type Config struct {
ListenPort int `json:"listenPort"`
SessionCookieName string `json:"sessionCookieName"`
SessionCookie struct {
Path string `json:"path"`
HttpOnly bool `json:"httpOnly"`
Secure bool `json:"secure"`
MaxAge int `json:"maxAge"`
}
LDAP LDAPConfig `json:"ldap"`
PVE PVEConfig `json:"pve"`
Realms map[string]RealmConfig `json:"realms"`
}
func GetConfig(configPath string) (Config, error) {
content, err := os.ReadFile(configPath)
if err != nil {
return Config{}, err
}
var config Config
err = json.Unmarshal(content, &config)
if err != nil {
return Config{}, err
}
return config, nil
}

7
app/common/schema.go Normal file
View File

@@ -0,0 +1,7 @@
package app
type Login struct { // login body struct
UsernameRaw string `form:"username" binding:"required"`
Username Username
Password string `form:"password" binding:"required"`
}

111
app/common/types.go Normal file
View File

@@ -0,0 +1,111 @@
package app
type BackendClient interface {
BindUser(username string, password string) error
//GetAllUsers() ([]User, int, error)
GetUser(username string) (User, int, error)
AddUser(username string, user User) (int, error)
ModUser(username string, user User) (int, error)
DelUser(username string) (int, error)
//GetAllGroups() ([]Group, int, error)
GetGroup(groupname string) (Group, int, error)
AddGroup(groupname string, group Group) (int, error)
ModGroup(groupname string, group Group) (int, error)
DelGroup(groupname string) (int, error)
AddUserToGroup(username string, groupname string)
RemoveUserFromGroup(username string, groupname string)
}
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"`
Cluster Cluster `json:"cluster"`
Templates Templates `json:"templates"`
}
type Groupname struct { // proxmox typically formats as gid-realm for non pve realms
GroupID string `json:"gid"`
Realm string `json:"realm"`
}
type Group struct {
Groupname Groupname `json:"groupname"`
Handler string `json:"-"`
Role string `json:"role"`
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"`
Handler string `json:"-"`
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 Cluster struct {
Nodes map[string]bool `json:"nodes"`
VMID VMID `json:"vmid"`
//Pools map[string]bool `json:"pools"`
Backups Backups `json:"backups"`
}
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"`
}

42
app/common/utils.go Normal file
View 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)
}