mirror of
https://github.com/yusing/godoxy.git
synced 2025-07-01 04:54:26 +02:00
api: also validate for middleware compose files
This commit is contained in:
parent
5e2ce9e1e6
commit
6f35a6f5e9
1 changed files with 8 additions and 3 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/yusing/go-proxy/internal/common"
|
||||
"github.com/yusing/go-proxy/internal/config"
|
||||
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"
|
||||
)
|
||||
|
||||
|
@ -40,12 +41,16 @@ func SetFileContent(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
var valErr E.Error
|
||||
if filename == common.ConfigFileName {
|
||||
switch {
|
||||
case filename == common.ConfigFileName:
|
||||
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)
|
||||
}
|
||||
// no validation for include files
|
||||
|
||||
if valErr != nil {
|
||||
U.RespondError(w, valErr, http.StatusBadRequest)
|
||||
|
|
Loading…
Add table
Reference in a new issue