mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 01:57:19 +08:00
feat: 实现应用expr依赖判断
This commit is contained in:
1
go.mod
1
go.mod
@@ -6,6 +6,7 @@ require (
|
||||
github.com/beevik/ntp v1.4.3
|
||||
github.com/docker/docker v27.3.1+incompatible
|
||||
github.com/docker/go-connections v0.5.0
|
||||
github.com/expr-lang/expr v1.16.9
|
||||
github.com/glebarez/sqlite v1.11.0
|
||||
github.com/go-chi/chi/v5 v5.1.0
|
||||
github.com/go-gormigrate/gormigrate/v2 v2.1.3
|
||||
|
||||
2
go.sum
2
go.sum
@@ -65,6 +65,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/expr-lang/expr v1.16.9 h1:WUAzmR0JNI9JCiF0/ewwHB1gmcGw5wW7nWt8gc6PpCI=
|
||||
github.com/expr-lang/expr v1.16.9/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
|
||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
|
||||
@@ -4,8 +4,11 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/spf13/cast"
|
||||
"slices"
|
||||
|
||||
"github.com/expr-lang/expr"
|
||||
|
||||
"github.com/TheTNB/panel/internal/biz"
|
||||
"github.com/TheTNB/panel/internal/panel"
|
||||
"github.com/TheTNB/panel/pkg/api"
|
||||
@@ -260,28 +263,33 @@ func (r *appRepo) UpdateCache() error {
|
||||
}
|
||||
|
||||
func (r *appRepo) preCheck(app *api.App) error {
|
||||
var apps []string
|
||||
var installed []string
|
||||
|
||||
allPlugins := r.All()
|
||||
for _, p := range allPlugins {
|
||||
apps = append(apps, p.Slug)
|
||||
}
|
||||
installedPlugins, err := r.Installed()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
appsMap := make(map[string]bool)
|
||||
for _, p := range installedPlugins {
|
||||
appsMap[p.Slug] = true
|
||||
installed = append(installed, p.Slug)
|
||||
}
|
||||
|
||||
for _, require := range app.Requires {
|
||||
_, requireFound := appsMap[require]
|
||||
if !requireFound {
|
||||
return fmt.Errorf("应用 %s 需要依赖 %s 应用", app.Name, require)
|
||||
}
|
||||
env := map[string]any{
|
||||
"apps": apps,
|
||||
"installed": installed,
|
||||
}
|
||||
output, err := expr.Eval(app.Depends, env)
|
||||
if err != nil {
|
||||
|
||||
}
|
||||
|
||||
for _, exclude := range app.Excludes {
|
||||
_, excludeFound := appsMap[exclude]
|
||||
if excludeFound {
|
||||
return fmt.Errorf("应用 %s 不兼容 %s 应用", app.Name, exclude)
|
||||
}
|
||||
result := cast.ToString(output)
|
||||
if result != "ok" {
|
||||
return fmt.Errorf("应用 %s %s", app.Name, result)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
25
pkg/api/acme.go
Normal file
25
pkg/api/acme.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package api
|
||||
|
||||
import "fmt"
|
||||
|
||||
type EAB struct {
|
||||
KeyID string `json:"key_id"`
|
||||
MacKey string `json:"mac_key"`
|
||||
}
|
||||
|
||||
func (r *API) GoogleEAB() (*EAB, error) {
|
||||
resp, err := r.client.R().SetResult(&Response{}).Get("/acme/googleEAB")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !resp.IsSuccess() {
|
||||
return nil, fmt.Errorf("failed to get google eab: %s", resp.String())
|
||||
}
|
||||
|
||||
eab, err := getResponseData[EAB](resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return eab, nil
|
||||
}
|
||||
@@ -13,8 +13,7 @@ type App struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Categories []string `json:"categories"`
|
||||
Requires []string `json:"requires"`
|
||||
Excludes []string `json:"excludes"`
|
||||
Depends string `json:"depends"`
|
||||
Versions []struct {
|
||||
Version string `json:"version"`
|
||||
Install string `json:"install"`
|
||||
|
||||
Reference in New Issue
Block a user