mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-25 01:38:30 +02:00
api: also validate for middleware compose files
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/yusing/go-proxy/internal/common"
|
"github.com/yusing/go-proxy/internal/common"
|
||||||
"github.com/yusing/go-proxy/internal/config"
|
"github.com/yusing/go-proxy/internal/config"
|
||||||
E "github.com/yusing/go-proxy/internal/error"
|
E "github.com/yusing/go-proxy/internal/error"
|
||||||
|
"github.com/yusing/go-proxy/internal/net/http/middleware"
|
||||||
"github.com/yusing/go-proxy/internal/route/provider"
|
"github.com/yusing/go-proxy/internal/route/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -40,12 +41,16 @@ func SetFileContent(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var valErr E.Error
|
var valErr E.Error
|
||||||
if filename == common.ConfigFileName {
|
switch {
|
||||||
|
case filename == common.ConfigFileName:
|
||||||
valErr = config.Validate(content)
|
valErr = config.Validate(content)
|
||||||
} else if !strings.HasPrefix(filename, path.Base(common.MiddlewareComposeBasePath)) {
|
case strings.HasPrefix(filename, path.Base(common.MiddlewareComposeBasePath)):
|
||||||
|
errs := E.NewBuilder("middleware errors")
|
||||||
|
middleware.BuildMiddlewaresFromYAML(filename, content, errs)
|
||||||
|
valErr = errs.Error()
|
||||||
|
default:
|
||||||
valErr = provider.Validate(content)
|
valErr = provider.Validate(content)
|
||||||
}
|
}
|
||||||
// no validation for include files
|
|
||||||
|
|
||||||
if valErr != nil {
|
if valErr != nil {
|
||||||
U.RespondError(w, valErr, http.StatusBadRequest)
|
U.RespondError(w, valErr, http.StatusBadRequest)
|
||||||
|
|||||||
Reference in New Issue
Block a user