Skip to content

Commit

Permalink
Remove portal v1 (#3465)
Browse files Browse the repository at this point in the history
Portal V1, you have served us well.
  • Loading branch information
hawkowl authored Apr 5, 2024
1 parent 162164e commit 27bc205
Show file tree
Hide file tree
Showing 25 changed files with 24 additions and 9,666 deletions.
14 changes: 0 additions & 14 deletions .gdn/.gdnsuppress
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,6 @@
"expirationDate": null,
"type": null
},
"20cd31403587ea29d121d28ac3ef7d9b6a7b922baaf817f79ba4ccf0d5730b43": {
"signature": "20cd31403587ea29d121d28ac3ef7d9b6a7b922baaf817f79ba4ccf0d5730b43",
"alternativeSignatures": [],
"target": "portal/v1/build/main.js.LICENSE.txt",
"memberOf": [
"default"
],
"tool": "policheck",
"ruleId": "166862",
"justification": null,
"createdDate": "2022-07-14 16:28:44Z",
"expirationDate": null,
"type": null
},
"9c277a79f4467e0f7fc8eaeac774f9680776f80a1acfee7a0e3331dde2f7ef6d": {
"signature": "9c277a79f4467e0f7fc8eaeac774f9680776f80a1acfee7a0e3331dde2f7ef6d",
"alternativeSignatures": [],
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ run-portal:
go run -ldflags "-X github.com/Azure/ARO-RP/pkg/util/version.GitCommit=$(VERSION)" ./cmd/aro portal

build-portal:
cd portal/v1 && npm install && npm run build && cd ../v2 && npm install && npm run build
cd portal/v2 && npm install && npm run build

pyenv:
python3 -m venv pyenv
Expand Down
2 changes: 1 addition & 1 deletion docs/admin-portal.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The front end is developed using react and typescript. The back end api is writt

The portal front end lives in the top level directory of the ARO-RP repo within the `portal` directory. The portal back end exists within `pkg/portal`

The front end code is compiled into go code using the bindata golang module. This front end code is then served through the RP.
The front end code is built into the `aro` binary (via go embed) and the static files are served by `aro portal`.

The admin portal also serves a static Prometheus web frontend. The contents are taken from a Prometheus release's web-ui artifact (e.g. [2.48](https://github.com/prometheus/prometheus/releases/download/v2.48.0/prometheus-web-ui-2.48.0.tar.gz)), and the static/react subdirectory is mirrored to this repository's pkg/portal/assets/prometheus-ui directory.

Expand Down
1 change: 0 additions & 1 deletion pkg/portal/assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"embed"
)

//go:embed v1/*
//go:embed v2/*
//go:embed prometheus-ui/*
var EmbeddedFiles embed.FS
92 changes: 0 additions & 92 deletions pkg/portal/assets/v1/build/index.html

This file was deleted.

2 changes: 0 additions & 2 deletions pkg/portal/assets/v1/build/main.js

This file was deleted.

84 changes: 0 additions & 84 deletions pkg/portal/assets/v1/build/main.js.LICENSE.txt

This file was deleted.

6 changes: 0 additions & 6 deletions pkg/portal/assets/v1/build/styles.css

This file was deleted.

6 changes: 3 additions & 3 deletions pkg/portal/assets/v2/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"files": {
"main.js": "/static/js/main.09fbc574.js",
"main.js": "/static/js/main.662aea13.js",
"index.html": "/index.html",
"main.09fbc574.js.map": "/static/js/main.09fbc574.js.map"
"main.662aea13.js.map": "/static/js/main.662aea13.js.map"
},
"entrypoints": [
"static/js/main.09fbc574.js"
"static/js/main.662aea13.js"
]
}
2 changes: 1 addition & 1 deletion pkg/portal/assets/v2/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>ARO Portal</title><script defer="defer" src="/static/js/main.09fbc574.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>ARO Portal</title><script defer="defer" src="/static/js/main.662aea13.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1 change: 0 additions & 1 deletion pkg/portal/assets/v2/build/static/js/main.09fbc574.js.map

This file was deleted.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/portal/assets/v2/build/static/js/main.662aea13.js.map

Large diffs are not rendered by default.

34 changes: 2 additions & 32 deletions pkg/portal/portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ type portal struct {

dialer proxy.Dialer

templateV1 *template.Template
templateV2 *template.Template
templatePrometheus *template.Template

Expand Down Expand Up @@ -134,11 +133,6 @@ func (p *portal) setupRouter(kconfig *kubeconfig.Kubeconfig, prom *prometheus.Pr
r := mux.NewRouter()
r.Use(middleware.Panic(p.log))

assetv1, err := assets.EmbeddedFiles.ReadFile("v1/build/index.html")
if err != nil {
return nil, err
}

assetv2, err := assets.EmbeddedFiles.ReadFile("v2/build/index.html")
if err != nil {
return nil, err
Expand All @@ -149,11 +143,6 @@ func (p *portal) setupRouter(kconfig *kubeconfig.Kubeconfig, prom *prometheus.Pr
return nil, err
}

p.templateV1, err = template.New("index.html").Parse(string(assetv1))
if err != nil {
return nil, err
}

p.templateV2, err = template.New("index.html").Parse(string(assetv2))
if err != nil {
return nil, err
Expand Down Expand Up @@ -325,39 +314,20 @@ func (p *portal) aadAuthenticatedRoutes(r *mux.Router, prom *prometheus.Promethe
r.Methods(http.MethodPost).Path("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.redhatopenshift/openshiftclusters/{resourceName}/ssh/new").HandlerFunc(sshStruct.New)

for _, name := range names {
regexp, _ := regexp.Compile(`v[1,2]/build/.*\..*`)
regexp, _ := regexp.Compile(`v2/build/.*\..*`)
name := regexp.FindString(name)
switch name {
case "v2/build/index.html":
r.Methods(http.MethodGet).Path("/").HandlerFunc(p.indexV2)
r.Methods(http.MethodGet).PathPrefix("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.redhatopenshift/openshiftclusters/{resourceName}").HandlerFunc(p.indexV2)
case "v1/build/index.html":
r.Methods(http.MethodGet).Path("/v1").HandlerFunc(p.index)
case "":
default:
fmtName := strings.TrimPrefix(name, "v1/build/")
fmtName = strings.TrimPrefix(fmtName, "v2/build/")

fmtName := strings.TrimPrefix(name, "v2/build/")
r.Methods(http.MethodGet).Path("/" + fmtName).HandlerFunc(p.serve(name))
}
}
}

func (p *portal) index(w http.ResponseWriter, r *http.Request) {
buf := &bytes.Buffer{}

err := p.templateV1.ExecuteTemplate(buf, "index.html", map[string]interface{}{
"location": p.env.Location(),
csrf.TemplateTag: csrf.TemplateField(r),
})
if err != nil {
p.internalServerError(w, err)
return
}

http.ServeContent(w, r, "index.html", time.Time{}, bytes.NewReader(buf.Bytes()))
}

func (p *portal) indexV2(w http.ResponseWriter, r *http.Request) {
buf := &bytes.Buffer{}

Expand Down
10 changes: 5 additions & 5 deletions pkg/portal/security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ func TestSecurity(t *testing.T) {
},
},
{
name: "/main.js",
name: "/asset-manifest.json",
request: func() (*http.Request, error) {
return http.NewRequest(http.MethodGet, "https://server/main.js", nil)
return http.NewRequest(http.MethodGet, "https://server/asset-manifest.json", nil)
},
wantAuditOperation: "GET /main.js",
wantAuditOperation: "GET /asset-manifest.json",
wantAuditTargetResources: []audit.TargetResource{
{
TargetResourceType: "",
TargetResourceName: "/main.js",
TargetResourceName: "/asset-manifest.json",
},
},
},
Expand Down Expand Up @@ -359,7 +359,7 @@ func TestSecurity(t *testing.T) {
// the Payload will change during this access, resulting in the e2e panicking.
// `go test -race -timeout 30s -run ^TestSecurity$ ./pkg/portal` should show the race and
// where the concurrent read/write is occurring.
if tt.name == "/" || tt.name == "/main.js" {
if tt.name == "/" || tt.name == "/asset-manifest.json" {
err = testpoller.Poll(1*time.Second, 5*time.Millisecond, func() (bool, error) {
if len(auditHook.AllEntries()) == 1 {
if _, ok := auditHook.AllEntries()[0].Data[audit.MetadataPayload]; ok {
Expand Down
Loading

0 comments on commit 27bc205

Please sign in to comment.