move some util definitions and code to common lib
This commit is contained in:
@@ -22,13 +22,6 @@ type StaticFile struct {
|
|||||||
MimeType MimeType
|
MimeType MimeType
|
||||||
}
|
}
|
||||||
|
|
||||||
// parsed vmpath data (ie node/type/vmid)
|
|
||||||
type VMPath struct {
|
|
||||||
Node string
|
|
||||||
Type string
|
|
||||||
VMID string
|
|
||||||
}
|
|
||||||
|
|
||||||
// type used for templated <select>
|
// type used for templated <select>
|
||||||
type Select struct {
|
type Select struct {
|
||||||
ID string
|
ID string
|
||||||
@@ -43,17 +36,6 @@ type Option struct {
|
|||||||
Display string
|
Display string
|
||||||
}
|
}
|
||||||
|
|
||||||
type RequestContext struct {
|
|
||||||
Cookies map[string]string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Auth struct {
|
|
||||||
Username string
|
|
||||||
Token string
|
|
||||||
CSRF string
|
|
||||||
AccessManagerTicket string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Icon struct {
|
type Icon struct {
|
||||||
ID string
|
ID string
|
||||||
Src string
|
Src string
|
||||||
|
|||||||
+30
-20
@@ -14,10 +14,13 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/tdewolff/minify/v2"
|
"github.com/tdewolff/minify/v2"
|
||||||
|
|
||||||
|
paas "proxmoxaas-common-lib"
|
||||||
)
|
)
|
||||||
|
|
||||||
// get config file from configPath
|
// get config file from configPath
|
||||||
@@ -173,13 +176,16 @@ func HandleNonFatalError(c *gin.Context, err error) {
|
|||||||
c.Status(http.StatusInternalServerError)
|
c.Status(http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequestGetAPI(path string, context RequestContext, body any) (*http.Response, int, error) {
|
func RequestGetAPI(path string, auth *paas.Auth, body any) (*http.Response, int, error) {
|
||||||
req, err := http.NewRequest("GET", Global.API+path, nil)
|
req, err := http.NewRequest("GET", Global.API+path, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
for k, v := range context.Cookies {
|
|
||||||
req.AddCookie(&http.Cookie{Name: k, Value: v, Secure: true})
|
if auth != nil {
|
||||||
|
for k, v := range GetRequestContextFromCookies(*auth) {
|
||||||
|
req.AddCookie(&http.Cookie{Name: k, Value: v, Secure: true})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
@@ -216,30 +222,36 @@ func RequestGetAPI(path string, context RequestContext, body any) (*http.Respons
|
|||||||
return response, response.StatusCode, nil
|
return response, response.StatusCode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAuth(c *gin.Context) (Auth, error) {
|
func GetAuthFromRequest(c *gin.Context) (paas.Auth, error) {
|
||||||
_, errAuth := c.Cookie("auth")
|
_, errAuth := c.Cookie("auth")
|
||||||
username, errUsername := c.Cookie("username")
|
username, errUsername := c.Cookie("username")
|
||||||
token, errToken := c.Cookie("PVEAuthCookie")
|
token, errToken := c.Cookie("PVEAuthCookie")
|
||||||
csrf, errCSRF := c.Cookie("CSRFPreventionToken")
|
csrf, errCSRF := c.Cookie("CSRFPreventionToken")
|
||||||
access, errAccess := c.Cookie("PAASAccessManagerTicket")
|
access, errAccess := c.Cookie("PAASAccessManagerTicket")
|
||||||
if errUsername != nil || errAuth != nil || errToken != nil || errCSRF != nil || errAccess != nil {
|
if errUsername != nil || errAuth != nil || errToken != nil || errCSRF != nil || errAccess != nil {
|
||||||
return Auth{}, fmt.Errorf("error occured getting user cookies: (auth: %s, token: %s, csrf: %s)", errAuth, errToken, errCSRF)
|
return paas.Auth{}, fmt.Errorf("error occured getting user cookies: (auth: %s, token: %s, csrf: %s)", errAuth, errToken, errCSRF)
|
||||||
} else {
|
} else {
|
||||||
return Auth{username, token, csrf, access}, nil
|
return paas.Auth{Username: username, Token: token, CSRF: csrf, AccessManagerTicket: access}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExtractVMPath(c *gin.Context) (VMPath, error) {
|
func GetInstancePathFromRequest(c *gin.Context) (paas.InstancePath, error) {
|
||||||
req_node := c.Query("node")
|
req_node := c.Query("node")
|
||||||
req_type := c.Query("type")
|
req_type := c.Query("type")
|
||||||
req_vmid := c.Query("vmid")
|
req_vmid := c.Query("vmid")
|
||||||
if req_node == "" || req_type == "" || req_vmid == "" {
|
if req_node == "" || req_type == "" || req_vmid == "" {
|
||||||
return VMPath{}, fmt.Errorf("request missing required values: (node: %s, type: %s, vmid: %s)", req_node, req_type, req_vmid)
|
return paas.InstancePath{}, fmt.Errorf("request missing required values: (node: %s, type: %s, vmid: %s)", req_node, req_type, req_vmid)
|
||||||
}
|
}
|
||||||
vm_path := VMPath{
|
|
||||||
Node: req_node,
|
vmid_int, err := strconv.ParseUint(req_vmid, 10, 64)
|
||||||
Type: req_type,
|
if err != nil {
|
||||||
VMID: req_vmid,
|
return paas.InstancePath{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
vm_path := paas.InstancePath{
|
||||||
|
NodeName: req_node,
|
||||||
|
InstanceType: paas.InstanceType(req_type),
|
||||||
|
InstanceID: paas.InstanceID(vmid_int),
|
||||||
}
|
}
|
||||||
return vm_path, nil
|
return vm_path, nil
|
||||||
}
|
}
|
||||||
@@ -271,13 +283,11 @@ func FormatNumber(val int64, base int64) (string, string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRequestContextFromCookies(auth Auth) RequestContext {
|
func GetRequestContextFromCookies(auth paas.Auth) map[string]string {
|
||||||
return RequestContext{
|
return map[string]string{
|
||||||
Cookies: map[string]string{
|
"username": auth.Username,
|
||||||
"username": auth.Username,
|
"PVEAuthCookie": auth.Token,
|
||||||
"PVEAuthCookie": auth.Token,
|
"CSRFPreventionToken": auth.CSRF,
|
||||||
"CSRFPreventionToken": auth.CSRF,
|
"PAASAccessManagerTicket": auth.AccessManagerTicket,
|
||||||
"PAASAccessManagerTicket": auth.AccessManagerTicket,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ var Green = color.RGB{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HandleGETAccount(c *gin.Context) {
|
func HandleGETAccount(c *gin.Context) {
|
||||||
auth, err := common.GetAuth(c)
|
auth, err := common.GetAuthFromRequest(c)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
||||||
account, err := GetUser(auth)
|
account, err := GetUser(auth)
|
||||||
@@ -186,11 +186,10 @@ func HandleGETAccount(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUser(auth common.Auth) (Account, error) {
|
func GetUser(auth paas.Auth) (Account, error) {
|
||||||
account := Account{}
|
account := Account{}
|
||||||
ctx := common.GetRequestContextFromCookies(auth)
|
|
||||||
body := map[string]any{}
|
body := map[string]any{}
|
||||||
res, code, err := common.RequestGetAPI(fmt.Sprintf("/access/users/%s", auth.Username), ctx, &body)
|
res, code, err := common.RequestGetAPI(fmt.Sprintf("/access/users/%s", auth.Username), &auth, &body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return account, err
|
return account, err
|
||||||
}
|
}
|
||||||
@@ -201,13 +200,12 @@ func GetUser(auth common.Auth) (Account, error) {
|
|||||||
return account, err
|
return account, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUserPools(auth common.Auth) (map[string]paas.Pool, error) {
|
func GetUserPools(auth paas.Auth) (map[string]paas.Pool, error) {
|
||||||
pools := map[string]paas.Pool{}
|
pools := map[string]paas.Pool{}
|
||||||
|
|
||||||
// get all pools
|
// get all pools
|
||||||
ctx := common.GetRequestContextFromCookies(auth)
|
|
||||||
body := map[string]any{}
|
body := map[string]any{}
|
||||||
res, code, err := common.RequestGetAPI("/access/pools", ctx, &body)
|
res, code, err := common.RequestGetAPI("/access/pools", &auth, &body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return pools, err
|
return pools, err
|
||||||
}
|
}
|
||||||
@@ -222,7 +220,7 @@ func GetUserPools(auth common.Auth) (map[string]paas.Pool, error) {
|
|||||||
// get global config for resource type metadata
|
// get global config for resource type metadata
|
||||||
body = map[string]any{}
|
body = map[string]any{}
|
||||||
// get resource meta data
|
// get resource meta data
|
||||||
res, code, err = common.RequestGetAPI("/global/config/resources", ctx, &body)
|
res, code, err = common.RequestGetAPI("/global/config/resources", &auth, &body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return pools, err
|
return pools, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package routes
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
paas "proxmoxaas-common-lib"
|
||||||
"proxmoxaas-dashboard/app/common"
|
"proxmoxaas-dashboard/app/common"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -20,9 +21,9 @@ type InstanceBackup struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HandleGETBackups(c *gin.Context) {
|
func HandleGETBackups(c *gin.Context) {
|
||||||
auth, err := common.GetAuth(c)
|
auth, err := common.GetAuthFromRequest(c)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
vm_path, err := common.ExtractVMPath(c)
|
vm_path, err := common.GetInstancePathFromRequest(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.HandleNonFatalError(c, err)
|
common.HandleNonFatalError(c, err)
|
||||||
return
|
return
|
||||||
@@ -50,9 +51,9 @@ func HandleGETBackups(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HandleGETBackupsFragment(c *gin.Context) {
|
func HandleGETBackupsFragment(c *gin.Context) {
|
||||||
auth, err := common.GetAuth(c)
|
auth, err := common.GetAuthFromRequest(c)
|
||||||
if err == nil { // user should be authed, try to return index with population
|
if err == nil { // user should be authed, try to return index with population
|
||||||
vm_path, err := common.ExtractVMPath(c)
|
vm_path, err := common.GetInstancePathFromRequest(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.HandleNonFatalError(c, err)
|
common.HandleNonFatalError(c, err)
|
||||||
return
|
return
|
||||||
@@ -77,12 +78,11 @@ func HandleGETBackupsFragment(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetInstanceBackups(vm common.VMPath, auth common.Auth) ([]InstanceBackup, error) {
|
func GetInstanceBackups(vm paas.InstancePath, auth paas.Auth) ([]InstanceBackup, error) {
|
||||||
backups := []InstanceBackup{}
|
backups := []InstanceBackup{}
|
||||||
path := fmt.Sprintf("/cluster/%s/%s/%s/backup", vm.Node, vm.Type, vm.VMID)
|
path := fmt.Sprintf("/cluster/%s/%s/%d/backup", vm.NodeName, string(vm.InstanceType), uint64(vm.InstanceID))
|
||||||
ctx := common.GetRequestContextFromCookies(auth)
|
|
||||||
body := []any{}
|
body := []any{}
|
||||||
res, code, err := common.RequestGetAPI(path, ctx, &body)
|
res, code, err := common.RequestGetAPI(path, &auth, &body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return backups, err
|
return backups, err
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-22
@@ -34,9 +34,9 @@ type PoolConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HandleGETConfig(c *gin.Context) {
|
func HandleGETConfig(c *gin.Context) {
|
||||||
auth, err := common.GetAuth(c)
|
auth, err := common.GetAuthFromRequest(c)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
vm_path, err := common.ExtractVMPath(c)
|
vm_path, err := common.GetInstancePathFromRequest(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.HandleNonFatalError(c, err)
|
common.HandleNonFatalError(c, err)
|
||||||
return
|
return
|
||||||
@@ -70,9 +70,9 @@ func HandleGETConfig(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HandleGETConfigVolumesFragment(c *gin.Context) {
|
func HandleGETConfigVolumesFragment(c *gin.Context) {
|
||||||
auth, err := common.GetAuth(c)
|
auth, err := common.GetAuthFromRequest(c)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
vm_path, err := common.ExtractVMPath(c)
|
vm_path, err := common.GetInstancePathFromRequest(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.HandleNonFatalError(c, err)
|
common.HandleNonFatalError(c, err)
|
||||||
return
|
return
|
||||||
@@ -98,9 +98,9 @@ func HandleGETConfigVolumesFragment(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HandleGETConfigNetsFragment(c *gin.Context) {
|
func HandleGETConfigNetsFragment(c *gin.Context) {
|
||||||
auth, err := common.GetAuth(c)
|
auth, err := common.GetAuthFromRequest(c)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
vm_path, err := common.ExtractVMPath(c)
|
vm_path, err := common.GetInstancePathFromRequest(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.HandleNonFatalError(c, err)
|
common.HandleNonFatalError(c, err)
|
||||||
return
|
return
|
||||||
@@ -126,9 +126,9 @@ func HandleGETConfigNetsFragment(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HandleGETConfigDevicesFragment(c *gin.Context) {
|
func HandleGETConfigDevicesFragment(c *gin.Context) {
|
||||||
auth, err := common.GetAuth(c)
|
auth, err := common.GetAuthFromRequest(c)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
vm_path, err := common.ExtractVMPath(c)
|
vm_path, err := common.GetInstancePathFromRequest(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.HandleNonFatalError(c, err)
|
common.HandleNonFatalError(c, err)
|
||||||
return
|
return
|
||||||
@@ -154,9 +154,9 @@ func HandleGETConfigDevicesFragment(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HandleGETConfigBootFragment(c *gin.Context) {
|
func HandleGETConfigBootFragment(c *gin.Context) {
|
||||||
auth, err := common.GetAuth(c)
|
auth, err := common.GetAuthFromRequest(c)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
vm_path, err := common.ExtractVMPath(c)
|
vm_path, err := common.GetInstancePathFromRequest(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.HandleNonFatalError(c, err)
|
common.HandleNonFatalError(c, err)
|
||||||
return
|
return
|
||||||
@@ -181,12 +181,11 @@ func HandleGETConfigBootFragment(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetInstanceConfig(vm common.VMPath, auth common.Auth) (InstanceConfig, error) {
|
func GetInstanceConfig(vm paas.InstancePath, auth paas.Auth) (InstanceConfig, error) {
|
||||||
config := InstanceConfig{}
|
config := InstanceConfig{}
|
||||||
path := fmt.Sprintf("/cluster/%s/%s/%s", vm.Node, vm.Type, vm.VMID)
|
path := fmt.Sprintf("/cluster/%s/%s/%d/", vm.NodeName, string(vm.InstanceType), uint64(vm.InstanceID))
|
||||||
ctx := common.GetRequestContextFromCookies(auth)
|
|
||||||
body := map[string]any{}
|
body := map[string]any{}
|
||||||
res, code, err := common.RequestGetAPI(path, ctx, &body)
|
res, code, err := common.RequestGetAPI(path, &auth, &body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return config, err
|
return config, err
|
||||||
}
|
}
|
||||||
@@ -205,17 +204,16 @@ func GetInstanceConfig(vm common.VMPath, auth common.Auth) (InstanceConfig, erro
|
|||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCPUTypes(vm common.VMPath, pool string, auth common.Auth) (common.Select, error) {
|
func GetCPUTypes(vm paas.InstancePath, pool string, auth paas.Auth) (common.Select, error) {
|
||||||
cputypes := common.Select{
|
cputypes := common.Select{
|
||||||
ID: "proctype",
|
ID: "proctype",
|
||||||
Required: true,
|
Required: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// get global resource config
|
// get global resource config
|
||||||
ctx := common.GetRequestContextFromCookies(auth)
|
|
||||||
body := map[string]any{}
|
body := map[string]any{}
|
||||||
path := "/global/config/resources"
|
path := "/global/config/resources"
|
||||||
res, code, err := common.RequestGetAPI(path, ctx, &body)
|
res, code, err := common.RequestGetAPI(path, &auth, &body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cputypes, err
|
return cputypes, err
|
||||||
}
|
}
|
||||||
@@ -231,7 +229,7 @@ func GetCPUTypes(vm common.VMPath, pool string, auth common.Auth) (common.Select
|
|||||||
// get pool resource config
|
// get pool resource config
|
||||||
body = map[string]any{}
|
body = map[string]any{}
|
||||||
path = fmt.Sprintf("/access/pools/%s", pool)
|
path = fmt.Sprintf("/access/pools/%s", pool)
|
||||||
res, code, err = common.RequestGetAPI(path, ctx, &body)
|
res, code, err = common.RequestGetAPI(path, &auth, &body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cputypes, err
|
return cputypes, err
|
||||||
}
|
}
|
||||||
@@ -246,8 +244,8 @@ func GetCPUTypes(vm common.VMPath, pool string, auth common.Auth) (common.Select
|
|||||||
|
|
||||||
// use node specific rules if present, otherwise use global rules
|
// use node specific rules if present, otherwise use global rules
|
||||||
var userCPU []paas.MatchLimit
|
var userCPU []paas.MatchLimit
|
||||||
if _, ok := poolCPUConfig.CPU.Nodes[vm.Node]; ok {
|
if _, ok := poolCPUConfig.CPU.Nodes[vm.NodeName]; ok {
|
||||||
userCPU = poolCPUConfig.CPU.Nodes[vm.Node]
|
userCPU = poolCPUConfig.CPU.Nodes[vm.NodeName]
|
||||||
} else {
|
} else {
|
||||||
userCPU = poolCPUConfig.CPU.Global
|
userCPU = poolCPUConfig.CPU.Global
|
||||||
}
|
}
|
||||||
@@ -262,8 +260,8 @@ func GetCPUTypes(vm common.VMPath, pool string, auth common.Auth) (common.Select
|
|||||||
} else { // cpu is a blacklist
|
} else { // cpu is a blacklist
|
||||||
// get the supported cpu types from the node
|
// get the supported cpu types from the node
|
||||||
body = map[string]any{}
|
body = map[string]any{}
|
||||||
path = fmt.Sprintf("/proxmox/nodes/%s/capabilities/qemu/cpu", vm.Node)
|
path = fmt.Sprintf("/proxmox/nodes/%s/capabilities/qemu/cpu", vm.NodeName)
|
||||||
res, code, err = common.RequestGetAPI(path, ctx, &body)
|
res, code, err = common.RequestGetAPI(path, &auth, &body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cputypes, err
|
return cputypes, err
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -3,6 +3,7 @@ package routes
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
paas "proxmoxaas-common-lib"
|
||||||
"proxmoxaas-dashboard/app/common"
|
"proxmoxaas-dashboard/app/common"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ type InstanceStatus struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HandleGETIndex(c *gin.Context) {
|
func HandleGETIndex(c *gin.Context) {
|
||||||
auth, err := common.GetAuth(c)
|
auth, err := common.GetAuthFromRequest(c)
|
||||||
if err == nil { // user should be authed, try to return index with population
|
if err == nil { // user should be authed, try to return index with population
|
||||||
instances, _, err := GetClusterResources(auth)
|
instances, _, err := GetClusterResources(auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -64,7 +65,7 @@ func HandleGETIndex(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HandleGETInstancesFragment(c *gin.Context) {
|
func HandleGETInstancesFragment(c *gin.Context) {
|
||||||
auth, err := common.GetAuth(c)
|
auth, err := common.GetAuthFromRequest(c)
|
||||||
if err == nil { // user should be authed, try to return index with population
|
if err == nil { // user should be authed, try to return index with population
|
||||||
instances, _, err := GetClusterResources(auth)
|
instances, _, err := GetClusterResources(auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -86,10 +87,9 @@ func HandleGETInstancesFragment(c *gin.Context) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetClusterResources(auth common.Auth) (map[uint]InstanceCard, map[string]Node, error) {
|
func GetClusterResources(auth paas.Auth) (map[uint]InstanceCard, map[string]Node, error) {
|
||||||
ctx := common.GetRequestContextFromCookies(auth)
|
|
||||||
body := []any{}
|
body := []any{}
|
||||||
res, code, err := common.RequestGetAPI("/proxmox/cluster/resources", ctx, &body)
|
res, code, err := common.RequestGetAPI("/proxmox/cluster/resources", &auth, &body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@@ -140,7 +140,7 @@ func GetClusterResources(auth common.Auth) (map[uint]InstanceCard, map[string]No
|
|||||||
}
|
}
|
||||||
|
|
||||||
body = []any{}
|
body = []any{}
|
||||||
res, code, err = common.RequestGetAPI("/proxmox/cluster/tasks", ctx, &body)
|
res, code, err = common.RequestGetAPI("/proxmox/cluster/tasks", &auth, &body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@@ -198,7 +198,7 @@ func GetClusterResources(auth common.Auth) (map[uint]InstanceCard, map[string]No
|
|||||||
instance := instances[vmid]
|
instance := instances[vmid]
|
||||||
path := fmt.Sprintf("/proxmox/nodes/%s/%s/%d/status/current", instance.Node, instance.Type, instance.VMID)
|
path := fmt.Sprintf("/proxmox/nodes/%s/%s/%d/status/current", instance.Node, instance.Type, instance.VMID)
|
||||||
body := map[string]any{}
|
body := map[string]any{}
|
||||||
res, code, err := common.RequestGetAPI(path, ctx, &body)
|
res, code, err := common.RequestGetAPI(path, &auth, &body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-4
@@ -24,11 +24,8 @@ type Realm struct {
|
|||||||
func GetLoginRealms() ([]Realm, error) {
|
func GetLoginRealms() ([]Realm, error) {
|
||||||
realms := []Realm{}
|
realms := []Realm{}
|
||||||
|
|
||||||
ctx := common.RequestContext{
|
|
||||||
Cookies: nil,
|
|
||||||
}
|
|
||||||
body := []any{}
|
body := []any{}
|
||||||
res, code, err := common.RequestGetAPI("/proxmox/access/domains", ctx, &body)
|
res, code, err := common.RequestGetAPI("/proxmox/access/domains", nil, &body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return realms, err
|
return realms, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func HandleGETSettings(c *gin.Context) {
|
func HandleGETSettings(c *gin.Context) {
|
||||||
_, err := common.GetAuth(c)
|
_, err := common.GetAuthFromRequest(c)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
c.HTML(http.StatusOK, "html/settings.html", gin.H{
|
c.HTML(http.StatusOK, "html/settings.html", gin.H{
|
||||||
"global": common.Global,
|
"global": common.Global,
|
||||||
|
|||||||
+1
-1
Submodule proxmoxaas-common-lib updated: 52ac2c2b97...ad6b8211b3
Reference in New Issue
Block a user