Commit 607ffff3 authored by Juergen Enge's avatar Juergen Enge
Browse files

fallback signature parameter added

parent 4c4eb47d
Pipeline #14874 passed with stages
in 3 minutes and 37 seconds
......@@ -15,6 +15,7 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"regexp"
"strings"
)
......@@ -39,6 +40,8 @@ func proxy(url url.URL, w http.ResponseWriter, req *http.Request) {
rp.ServeHTTP(w, req)
}
var regexpFallback = regexp.MustCompile("^fallback(.+)$")
func (ms *memoServer) mainHandler(w http.ResponseWriter, req *http.Request) {
// remove prefix and use whole rest of url as signature
vars := mux.Vars(req)
......@@ -48,14 +51,30 @@ func (ms *memoServer) mainHandler(w http.ResponseWriter, req *http.Request) {
return
}
action, _ := vars["action"]
params, _ := vars["params"]
//signature := strings.TrimPrefix(req.URL.Path, ms.urlPrefix)
paramstr, _ := vars["paramstr"]
params := strings.Split(paramstr, "/")
// resolve signature
me, err := ms.resolver.resolve(signature)
if err != nil {
ms.DoPanicf(w, http.StatusNotFound, "signature %v not found: %v", signature, err)
return
// check for fallback parameter only if needed
fallback := ""
for _, p := range params {
if matches := regexpFallback.FindStringSubmatch(p); matches != nil {
fallback = matches[1]
break
}
}
if fallback != "" {
me, err = ms.resolver.resolve(fallback)
if err != nil {
ms.DoPanicf(w, http.StatusNotFound, "signature %v and fallback %v not found: %v", signature, fallback, err)
return
}
} else {
ms.DoPanicf(w, http.StatusNotFound, "signature %v not found: %v", signature, err)
return
}
}
if me.Access != Media_Public {
if err := CheckRequestJWT(req, ms.jwtSecret, ms.jwtAlg, signature); err != nil {
......@@ -69,7 +88,7 @@ func (ms *memoServer) mainHandler(w http.ResponseWriter, req *http.Request) {
}
if actions, ok := ms.actions[me.Type]; ok {
for _, a := range actions {
ok, err := a.Do(w, req, me, action, strings.Split(params, "/")...)
ok, err := a.Do(w, req, me, action, params...)
if err != nil {
ms.DoPanicf(w, http.StatusInternalServerError, "Cannot execute action %s on signature %s: %v", action, me.Signature, err)
return
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment