Fix Hop hiding menu (#1621)
* Fix Hop hiding menu Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> * Fix Menu Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
This commit is contained in:
@@ -140,7 +140,7 @@ func AuthenticationMiddleware(next http.Handler) http.Handler {
|
||||
// proxyMiddleware adds the proxy capability
|
||||
func proxyMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.HasPrefix(r.URL.Path, "/api/proxy") {
|
||||
if strings.HasPrefix(r.URL.Path, "/api/proxy") || strings.HasPrefix(r.URL.Path, "/api/hop") {
|
||||
serveProxy(w, r)
|
||||
} else {
|
||||
next.ServeHTTP(w, r)
|
||||
|
||||
@@ -18,6 +18,8 @@ package operatorapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -174,6 +176,8 @@ func getLoginOperatorResponse(lmr *models.LoginOperatorRequest) (*models.LoginRe
|
||||
return nil, prepareError(err)
|
||||
}
|
||||
consoleCreds := restapi.ConsoleCredentials{ConsoleCredentials: creds}
|
||||
// Set a random as access key as session identifier
|
||||
consoleCreds.AccountAccessKey = fmt.Sprintf("%d", rand.Intn(100000-10000)+10000)
|
||||
token, err := login(consoleCreds)
|
||||
if err != nil {
|
||||
return nil, prepareError(errInvalidCredentials, nil, err)
|
||||
|
||||
@@ -41,6 +41,8 @@ import (
|
||||
|
||||
func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
|
||||
urlParts := strings.Split(req.URL.Path, "/")
|
||||
// Either proxy or hop, will decide the type of session
|
||||
proxyMethod := urlParts[2]
|
||||
|
||||
if len(urlParts) < 5 {
|
||||
log.Println(len(urlParts))
|
||||
@@ -99,7 +101,7 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
|
||||
|
||||
h := sha1.New()
|
||||
h.Write([]byte(nsTenant))
|
||||
tenantCookieName := fmt.Sprintf("token-%x", string(h.Sum(nil)))
|
||||
tenantCookieName := fmt.Sprintf("token-%s-%s-%x", proxyMethod, claims.AccountAccessKey, string(h.Sum(nil)))
|
||||
tenantCookie, err := req.Cookie(tenantCookieName)
|
||||
if err != nil {
|
||||
// login to tenantName
|
||||
@@ -126,9 +128,12 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
|
||||
data := map[string]interface{}{
|
||||
"accessKey": tenantConfiguration["accesskey"],
|
||||
"secretKey": tenantConfiguration["secretkey"],
|
||||
"features": map[string]bool{
|
||||
}
|
||||
// if this a proxy request hide the menu
|
||||
if proxyMethod == "proxy" {
|
||||
data["features"] = map[string]bool{
|
||||
"hide_menu": true,
|
||||
},
|
||||
}
|
||||
}
|
||||
payload, _ := json.Marshal(data)
|
||||
|
||||
@@ -188,7 +193,7 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
|
||||
responseWriter.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
tenantBase := fmt.Sprintf("/api/proxy/%s/%s", tenant.Namespace, tenant.Name)
|
||||
tenantBase := fmt.Sprintf("/api/%s/%s/%s", proxyMethod, tenant.Namespace, tenant.Name)
|
||||
targetURL.Path = strings.Replace(req.URL.Path, tenantBase, "", -1)
|
||||
|
||||
proxiedCookie := &http.Cookie{
|
||||
|
||||
Reference in New Issue
Block a user