Compare commits

..
8 Commits
Author SHA1 Message Date
alu e7341e3d9e remove go mod 2026-10-26 23:12:14 +00:00
alu 8b73652c9b add basic logging middleware
tronnet/workflows: Static Analysis -- Golang / static-go (push) Failing after 28s
2026-10-26 18:28:37 +00:00
alu 35ecaf84e0 add JSON helper to HTTP utils
tronnet/workflows: Static Analysis -- Golang / static-go (push) Failing after 21s
2026-10-23 21:55:27 +00:00
alu 01c1f0389a add http html and html fragment template execute code to common lib
tronnet/workflows: Static Analysis -- Golang / static-go (push) Failing after 22s
2026-10-23 21:52:53 +00:00
alu 8284ffbc43 fix issue in username to string format
tronnet/workflows: Static Analysis -- Golang / static-go (push) Successful in 42s
2026-08-18 23:01:58 +00:00
alu f4deeb1ab6 add quota related types 2026-07-23 16:23:31 +00:00
alu 05519694e1 add vmid to instance 2026-07-07 16:42:07 +00:00
alu 78e6de32d7 add uint to uint64 for SafeUint64 2026-07-07 03:36:32 +00:00
7 changed files with 138 additions and 50 deletions

No files matched your search

-45
View File
@@ -49,48 +49,3 @@ type VMID struct {
Min int `json:"min" mapstructure:"min"` Min int `json:"min" mapstructure:"min"`
Max int `json:"max" mapstructure:"max"` Max int `json:"max" mapstructure:"max"`
} }
type Backups struct {
MaxPerInstance int `json:"max-per-instance" mapstructure:"max-per-instance"`
MaxTotal int `json:"max-total" mapstructure:"max-total"`
}
type Templates struct {
Instances struct {
LXC map[string]ResourceTemplate `json:"lxc" mapstructure:"lxc"`
QEMU map[string]ResourceTemplate `json:"qemu" mapstructure:"qemu"`
} `json:"instances"`
}
type SimpleResource struct {
Limits struct {
Global SimpleLimit `json:"global" mapstructure:"global"`
Nodes map[string]SimpleLimit `json:"nodes" mapstructure:"nodes"`
} `json:"limits"`
}
type SimpleLimit struct {
Max int `json:"max" mapstructure:"max"`
}
type MatchResource struct {
Limits struct {
Global []MatchLimit `json:"global" mapstructure:""`
Nodes map[string][]MatchLimit `json:"nodes" mapstructure:""`
} `json:"limits"`
}
type MatchLimit struct {
Match string `json:"match" mapstructure:""`
Name string `json:"name" mapstructure:""`
Max int `json:"max" mapstructure:""`
}
type ResourceTemplate struct {
Value string `json:"value" mapstructure:"value"`
Resource struct {
Enabled bool `json:"enabled" mapstructure:"enabled"`
Name string `json:"name" mapstructure:"name"`
Amount int `json:"amount" mapstructure:"amount"`
} `json:"resource" mapstructure:"resource"`
}
+1 -1
View File
@@ -14,7 +14,7 @@ func (g Groupname) ToString() string {
// Converts input username object to string representation. // Converts input username object to string representation.
// Uses the format uid@realm. // Uses the format uid@realm.
func (u Username) ToString() string { func (u Username) ToString() string {
return fmt.Sprintf("%s-%s", u.UserID, u.Realm) return fmt.Sprintf("%s@%s", u.UserID, u.Realm)
} }
// Parses input groupname string to gid and realm. // Parses input groupname string to gid and realm.
-3
View File
@@ -1,3 +0,0 @@
module proxmoxaas-common-lib
go 1.26.0
+57
View File
@@ -0,0 +1,57 @@
package proxmoxaas_common_lib
import (
"bytes"
"encoding/json"
"html/template"
"log"
"net/http"
"time"
)
func HTTPExecuteHTMLTemplate(w http.ResponseWriter, t *template.Template, name string, d any) {
w.Header().Set("Content-Type", "text/html")
body := bytes.Buffer{}
err := t.ExecuteTemplate(&body, name, d)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
} else {
w.Write(body.Bytes())
return
}
}
func HTTPExecuteHTMLFragmentTemplate(w http.ResponseWriter, t *template.Template, name string, d any) {
w.Header().Set("Content-Type", "text/plain")
body := bytes.Buffer{}
err := t.ExecuteTemplate(&body, name, d)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
} else {
w.Write(body.Bytes())
return
}
}
func HTTPWriteJson(w http.ResponseWriter, code int, obj any) {
w.Header().Set("Content-Type", "application/json")
json, err := json.Marshal(obj)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
} else {
w.WriteHeader(code)
w.Write(json)
return
}
}
func LoggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
next.ServeHTTP(w, r)
log.Printf("%s %s %s", r.Method, r.URL.Path, time.Since(start))
})
}
+78
View File
@@ -0,0 +1,78 @@
package proxmoxaas_common_lib
// numerical constraint
type Constraint struct {
Max int64 `json:"max" mapstructure:"max"`
Used int64 `json:"used" mapstructure:"used"`
Avail int64 `json:"avail" mapstructure:"avail"`
}
// match constraint
type Match struct {
Constraint `mapstructure:",squash"`
Name string `json:"name" mapstructure:"name"`
Match string `json:"match" mapstructure:"match"`
}
// numerical resource
type NumericResource struct {
Type string
Name string
Multiplier int64
Base uint64
Compact bool
Unit string
Display bool
Global Constraint
Nodes map[string]Constraint
Total Constraint
Category string
}
// storage resource
type StorageResource struct {
Type string
Name string
Multiplier int64
Base uint64
Compact bool
Unit string
Display bool
Disks []string
Global Constraint
Nodes map[string]Constraint
Total Constraint
Category string
}
// list resource
type ListResource struct {
Type string
Whitelist bool
Display bool
Global []Match
Nodes map[string][]Match
Total []Match
Category string
}
type Templates struct {
Instances struct {
LXC map[string]ResourceTemplate `json:"lxc" mapstructure:"lxc"`
QEMU map[string]ResourceTemplate `json:"qemu" mapstructure:"qemu"`
} `json:"instances"`
}
type ResourceTemplate struct {
Value string `json:"value" mapstructure:"value"`
Resource struct {
Enabled bool `json:"enabled" mapstructure:"enabled"`
Name string `json:"name" mapstructure:"name"`
Amount int `json:"amount" mapstructure:"amount"`
} `json:"resource" mapstructure:"resource"`
}
type Backups struct {
MaxPerInstance int `json:"max-per-instance" mapstructure:"max-per-instance"`
MaxTotal int `json:"max-total" mapstructure:"max-total"`
}
+1
View File
@@ -21,6 +21,7 @@ const VM InstanceType = "VM"
const CT InstanceType = "CT" const CT InstanceType = "CT"
type Instance struct { type Instance struct {
VMID InstanceID `json:"vmid" mapstructure:"vmid"`
Type InstanceType `json:"type" mapstructure:"type"` Type InstanceType `json:"type" mapstructure:"type"`
Name string `json:"name" mapstructure:"name"` Name string `json:"name" mapstructure:"name"`
Proctype string `json:"cpu" mapstructure:"cpu"` Proctype string `json:"cpu" mapstructure:"cpu"`
+1 -1
View File
@@ -48,7 +48,7 @@ func FormatNumber(val uint64, base uint64) (string, string) {
} }
// Converts int, int32, and int64 to uint64. Less than 0 check. // Converts int, int32, and int64 to uint64. Less than 0 check.
func SafeUint64[I int | int32 | int64](i I) uint64 { func SafeUint64[I int | int32 | int64 | uint | uint32](i I) uint64 {
if i < 0 { if i < 0 {
log.Printf("Tried to cast %d to uint64", i) log.Printf("Tried to cast %d to uint64", i)
return 0 return 0