From 576abdeec468d378ec4e48d27173d3587dcd089a Mon Sep 17 00:00:00 2001 From: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> Date: Thu, 24 Feb 2022 13:24:29 -0800 Subject: [PATCH] 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> --- operatorapi/configure_operator.go | 2 +- operatorapi/operator_login.go | 4 +++ operatorapi/proxy.go | 13 ++++--- portal-ui/src/icons/BackCaretIcon.tsx | 27 ++++++++------- portal-ui/src/icons/FolderIcon.tsx | 6 ++-- .../Objects/ListObjects/CreateFolderModal.tsx | 2 +- .../Objects/ListObjects/ListObjects.tsx | 12 +++---- .../FormComponents/common/styleLibrary.ts | 6 ++-- portal-ui/src/screens/Console/ConsoleKBar.tsx | 1 + .../Tenants/TenantDetails/PodsSummary.tsx | 34 +++++++++---------- .../Tenants/TenantDetails/VolumesSummary.tsx | 13 +++---- .../Console/Tenants/TenantDetails/hop/Hop.tsx | 2 +- portal-ui/tests/operator/list-tenants.ts | 34 ++++++++++--------- portal-ui/tests/policies/inspect-allowed.json | 14 +++----- .../tests/policies/inspect-not-allowed.json | 14 +++----- 15 files changed, 94 insertions(+), 90 deletions(-) diff --git a/operatorapi/configure_operator.go b/operatorapi/configure_operator.go index 1298c462c..528425cde 100644 --- a/operatorapi/configure_operator.go +++ b/operatorapi/configure_operator.go @@ -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) diff --git a/operatorapi/operator_login.go b/operatorapi/operator_login.go index 25fc5bc0d..329896936 100644 --- a/operatorapi/operator_login.go +++ b/operatorapi/operator_login.go @@ -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) diff --git a/operatorapi/proxy.go b/operatorapi/proxy.go index 80dbd50cf..792041ebc 100644 --- a/operatorapi/proxy.go +++ b/operatorapi/proxy.go @@ -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{ diff --git a/portal-ui/src/icons/BackCaretIcon.tsx b/portal-ui/src/icons/BackCaretIcon.tsx index 96b8f3f2a..54061f9a7 100644 --- a/portal-ui/src/icons/BackCaretIcon.tsx +++ b/portal-ui/src/icons/BackCaretIcon.tsx @@ -18,20 +18,23 @@ import * as React from "react"; import { SVGProps } from "react"; const BackCaretIcon = (props: SVGProps) => ( - - - + + - - + c0.11,3.93-1.51,7.71-4.43,10.34L-167.29,2.99C-170.07,5.97-173.93,7.71-178.01,7.8z" + /> + + ); export default BackCaretIcon; diff --git a/portal-ui/src/icons/FolderIcon.tsx b/portal-ui/src/icons/FolderIcon.tsx index 39ae74b98..1bb085f16 100644 --- a/portal-ui/src/icons/FolderIcon.tsx +++ b/portal-ui/src/icons/FolderIcon.tsx @@ -26,10 +26,12 @@ const FolderIcon = (props: SVGProps) => ( {...props} > - + h172c0.2,4.6,2.9,8.8,6.9,11H32.5z" + /> ); diff --git a/portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/CreateFolderModal.tsx b/portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/CreateFolderModal.tsx index e4a054edd..215013bc7 100644 --- a/portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/CreateFolderModal.tsx +++ b/portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/CreateFolderModal.tsx @@ -107,7 +107,7 @@ const CreateFolderModal = ({ }; const keyPressed = (e: any) => { - if(e.code === "Enter" && pathUrl !== "") { + if (e.code === "Enter" && pathUrl !== "") { createProcess(); } }; diff --git a/portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/ListObjects.tsx b/portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/ListObjects.tsx index 8f43fa43c..e85754bc2 100644 --- a/portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/ListObjects.tsx +++ b/portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/ListObjects.tsx @@ -178,7 +178,7 @@ const styles = (theme: Theme) => "& .min-icon": { width: 20, height: 20, - } + }, }, ...objectBrowserCommon, ...containerForHeader(theme.spacing(4)), @@ -666,8 +666,6 @@ const ListObjects = ({ } }; - - const handleUploadButton = (e: any) => { if ( e === null || @@ -1270,7 +1268,7 @@ const ListObjects = ({ variant="dot" invisible={!rewindEnabled} className={classes.badgeOverlap} - sx={{height: 12}} + sx={{ height: 12 }} > @@ -1336,9 +1334,9 @@ const ListObjects = ({
{ + // if we are hiding the menu also disable the k-bar so just return console if (features?.includes("hide-menu")) { return ; } diff --git a/portal-ui/src/screens/Console/Tenants/TenantDetails/PodsSummary.tsx b/portal-ui/src/screens/Console/Tenants/TenantDetails/PodsSummary.tsx index 0d8791796..9c244647d 100644 --- a/portal-ui/src/screens/Console/Tenants/TenantDetails/PodsSummary.tsx +++ b/portal-ui/src/screens/Console/Tenants/TenantDetails/PodsSummary.tsx @@ -33,7 +33,7 @@ import { AppState } from "../../../../store"; import { setTenantDetailsLoad } from "../actions"; import { ErrorResponseHandler } from "../../../../common/types"; import DeletePod from "./DeletePod"; -import {Grid, InputAdornment, TextField} from "@mui/material"; +import { Grid, InputAdornment, TextField } from "@mui/material"; import SearchIcon from "../../../../icons/SearchIcon"; interface IPodsSummary { @@ -137,22 +137,22 @@ const PodsSummary = ({

Pods

- - - ), - }} - onChange={(e) => { - setFilter(e.target.value); - }} - variant="standard" + placeholder="Search Pods" + className={classes.searchField} + id="search-resource" + label="" + InputProps={{ + disableUnderline: true, + startAdornment: ( + + + + ), + }} + onChange={(e) => { + setFilter(e.target.value); + }} + variant="standard" /> diff --git a/portal-ui/src/screens/Console/Tenants/TenantDetails/VolumesSummary.tsx b/portal-ui/src/screens/Console/Tenants/TenantDetails/VolumesSummary.tsx index e65a79ee2..e9b1a8ec4 100644 --- a/portal-ui/src/screens/Console/Tenants/TenantDetails/VolumesSummary.tsx +++ b/portal-ui/src/screens/Console/Tenants/TenantDetails/VolumesSummary.tsx @@ -23,7 +23,8 @@ import withStyles from "@mui/styles/withStyles"; import { Grid, InputAdornment, TextField } from "@mui/material"; import { containerForHeader, - tableStyles, tenantDetailsStyles, + tableStyles, + tenantDetailsStyles, } from "../../Common/FormComponents/common/styleLibrary"; import { IStoragePVCs } from "../../Storage/types"; import { setErrorSnackMessage } from "../../../../actions"; @@ -48,11 +49,11 @@ interface ITenantVolumesProps { } const styles = (theme: Theme) => - createStyles({ - ...tenantDetailsStyles, - ...tableStyles, - ...containerForHeader(theme.spacing(4)), - }); + createStyles({ + ...tenantDetailsStyles, + ...tableStyles, + ...containerForHeader(theme.spacing(4)), + }); const TenantVolumes = ({ classes, diff --git a/portal-ui/src/screens/Console/Tenants/TenantDetails/hop/Hop.tsx b/portal-ui/src/screens/Console/Tenants/TenantDetails/hop/Hop.tsx index d1f110ca5..3db6123f6 100644 --- a/portal-ui/src/screens/Console/Tenants/TenantDetails/hop/Hop.tsx +++ b/portal-ui/src/screens/Console/Tenants/TenantDetails/hop/Hop.tsx @@ -151,7 +151,7 @@ const Hop = ({ classes, match }: IHopSimple) => { ref={consoleFrame} className={classes.iframeStyle} title={"metrics"} - src={`/api/proxy/${tenantNamespace}/${tenantName}/?cp=y`} + src={`/api/hop/${tenantNamespace}/${tenantName}/?cp=y`} onLoad={(val) => { setLoading(false); }} diff --git a/portal-ui/tests/operator/list-tenants.ts b/portal-ui/tests/operator/list-tenants.ts index 4a499525d..ea6464c4c 100644 --- a/portal-ui/tests/operator/list-tenants.ts +++ b/portal-ui/tests/operator/list-tenants.ts @@ -15,25 +15,27 @@ // along with this program. If not, see . import { diagnosticsElement, supportElement } from "../utils/elements-menu"; -import { Selector } from 'testcafe'; - +import { Selector } from "testcafe"; fixture("For user with default permissions").page("http://localhost:9090"); test("Create Tenant and List Tenants", async (t) => { + const osCount = Selector( + `#root > div > main > div[class] > div > div > div > div:nth-child(1) > div > div > div` + ).count; - const osCount = Selector(`#root > div > main > div[class] > div > div > div > div:nth-child(1) > div > div > div`).count; - - await t - .navigateTo("http://localhost:9090/login") - .typeText("#jwt","anyrandompasswordwillwork") - .click("button.MuiButton-root") - .click(Selector('button[tabindex="0"][type="button"]').withText('Create Tenant')) - .typeText("#tenant-name","thufeb1754epm") - .typeText("#namespace","default") - .wait(2000) - .click("button[tabindex=\"0\"]:nth-of-type(2)") - .click(Selector('button[tabindex="0"][type="button"]').withText('Done')) - .expect(osCount).eql(2); - + await t + .navigateTo("http://localhost:9090/login") + .typeText("#jwt", "anyrandompasswordwillwork") + .click("button.MuiButton-root") + .click( + Selector('button[tabindex="0"][type="button"]').withText("Create Tenant") + ) + .typeText("#tenant-name", "thufeb1754epm") + .typeText("#namespace", "default") + .wait(2000) + .click('button[tabindex="0"]:nth-of-type(2)') + .click(Selector('button[tabindex="0"][type="button"]').withText("Done")) + .expect(osCount) + .eql(2); }); diff --git a/portal-ui/tests/policies/inspect-allowed.json b/portal-ui/tests/policies/inspect-allowed.json index f605b82b8..6e9615809 100644 --- a/portal-ui/tests/policies/inspect-allowed.json +++ b/portal-ui/tests/policies/inspect-allowed.json @@ -2,21 +2,15 @@ "Version": "2012-10-17", "Statement": [ { - "Action": [ - "admin:*" - ], + "Action": ["admin:*"], "Effect": "Allow", "Sid": "Allow_Admin_Actions" }, { - "Action": [ - "s3:*" - ], + "Action": ["s3:*"], "Effect": "Allow", - "Resource": [ - "arn:aws:s3:::*" - ], + "Resource": ["arn:aws:s3:::*"], "Sid": "Allow_S3_Actions" } ] -} \ No newline at end of file +} diff --git a/portal-ui/tests/policies/inspect-not-allowed.json b/portal-ui/tests/policies/inspect-not-allowed.json index 86c32cd87..9d73e36ef 100644 --- a/portal-ui/tests/policies/inspect-not-allowed.json +++ b/portal-ui/tests/policies/inspect-not-allowed.json @@ -2,21 +2,15 @@ "Version": "2012-10-17", "Statement": [ { - "Action": [ - "admin:*" - ], + "Action": ["admin:*"], "Effect": "Deny", "Sid": "Deny_Admin_Actions" }, { - "Action": [ - "s3:*" - ], + "Action": ["s3:*"], "Effect": "Allow", - "Resource": [ - "arn:aws:s3:::*" - ], + "Resource": ["arn:aws:s3:::*"], "Sid": "Allow_S3_Actions" } ] -} \ No newline at end of file +}