fix(source): add /services/{name}/source endpoint; fix 404 for service code view in funcs-console
This commit is contained in:
@@ -347,14 +347,19 @@ func servePlainText(w http.ResponseWriter, ns, externalURL string, fns []fnRespo
|
||||
fmt.Fprint(w, sb.String())
|
||||
}
|
||||
|
||||
// proxySourceGet проксирует GET /funcs/{ns}/source/{fn} → оператор GET /v1/.../source.
|
||||
// proxySourceGet проксирует GET /funcs/{ns}/source/{fn}?kind={function|service} → оператор.
|
||||
// Авторизация — сервисный токен (хранится на сервере, не открывается клиенту).
|
||||
// kind=service → /v1/.../services/{fn}/source; иначе → /v1/.../functions/{fn}/source
|
||||
func proxySourceGet(w http.ResponseWriter, r *http.Request, operatorURL, serviceToken, ns, funcName string) {
|
||||
if !isValidK8sName(funcName) {
|
||||
http.Error(w, "invalid function name\n", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
target := operatorURL + "/v1/namespaces/" + ns + "/functions/" + funcName + "/source"
|
||||
resourceType := "functions"
|
||||
if r.URL.Query().Get("kind") == "service" {
|
||||
resourceType = "services"
|
||||
}
|
||||
target := operatorURL + "/v1/namespaces/" + ns + "/" + resourceType + "/" + funcName + "/source"
|
||||
req, err := http.NewRequestWithContext(r.Context(), http.MethodGet, target, nil)
|
||||
if err != nil {
|
||||
http.Error(w, "internal error\n", http.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user