Add config allow_paths for api module
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -30,6 +31,8 @@ func Init() {
|
|||||||
TLSCert string `yaml:"tls_cert"`
|
TLSCert string `yaml:"tls_cert"`
|
||||||
TLSKey string `yaml:"tls_key"`
|
TLSKey string `yaml:"tls_key"`
|
||||||
UnixListen string `yaml:"unix_listen"`
|
UnixListen string `yaml:"unix_listen"`
|
||||||
|
|
||||||
|
AllowPaths []string `yaml:"allow_paths"`
|
||||||
} `yaml:"api"`
|
} `yaml:"api"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +46,7 @@ func Init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allowPaths = cfg.Mod.AllowPaths
|
||||||
basePath = cfg.Mod.BasePath
|
basePath = cfg.Mod.BasePath
|
||||||
log = app.GetLogger("api")
|
log = app.GetLogger("api")
|
||||||
|
|
||||||
@@ -152,6 +156,9 @@ func HandleFunc(pattern string, handler http.HandlerFunc) {
|
|||||||
if len(pattern) == 0 || pattern[0] != '/' {
|
if len(pattern) == 0 || pattern[0] != '/' {
|
||||||
pattern = basePath + "/" + pattern
|
pattern = basePath + "/" + pattern
|
||||||
}
|
}
|
||||||
|
if allowPaths != nil && !slices.Contains(allowPaths, pattern) {
|
||||||
|
return
|
||||||
|
}
|
||||||
log.Trace().Str("path", pattern).Msg("[api] register path")
|
log.Trace().Str("path", pattern).Msg("[api] register path")
|
||||||
http.HandleFunc(pattern, handler)
|
http.HandleFunc(pattern, handler)
|
||||||
}
|
}
|
||||||
@@ -185,6 +192,7 @@ func Response(w http.ResponseWriter, body any, contentType string) {
|
|||||||
|
|
||||||
const StreamNotFound = "stream not found"
|
const StreamNotFound = "stream not found"
|
||||||
|
|
||||||
|
var allowPaths []string
|
||||||
var basePath string
|
var basePath string
|
||||||
var log zerolog.Logger
|
var log zerolog.Logger
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user