From 9af983985039e5b7dabfe12be19d46b5555839cd Mon Sep 17 00:00:00 2001 From: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> Date: Sat, 25 May 2024 15:24:55 +0200 Subject: [PATCH 1/3] feat: add shareable link to the website --- README.md | 12 ++++++++++- docs/release_notes/v0.6.1.md | 3 +++ go.mod | 4 ++-- go.sum | 8 +++---- wasm/app-worker.js | 6 +++--- wasm/app.go | 39 +++++++++++++++++++++++++++++++++++ wasm/app.js | 2 +- wasm/index.html | 20 +++++++++--------- wasm/main.go | 1 + wasm/web/app.wasm | Bin 27713643 -> 27727898 bytes 10 files changed, 74 insertions(+), 21 deletions(-) create mode 100644 docs/release_notes/v0.6.1.md diff --git a/README.md b/README.md index efa8be8..7dc56a6 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ cty generate -c delivery.krok.app_krokcommands --comments --minimal --format htm ### Folder source -To parse mutliple CRDs in a single folder, just pass in the whole folder like this: +To parse multiple CRDs in a single folder, just pass in the whole folder like this: ``` cty generate -r folder @@ -98,6 +98,16 @@ make run This will start a front-end that can be used to paste in and parse CRDs. +## Shareable Link + +It's possible to provide a link that can be shared using a url parameter like this: + +``` +https://crdtoyaml.com/share?url=https://raw.githubusercontent.com/Skarlso/crd-to-sample-yaml/main/sample-crd/infrastructure.cluster.x-k8s.io_awsclusters.yaml +``` + +Will load the content, or display an appropriate error message. + ## Comments Comments can be added to each line of the generated YAML content where descriptions are available. This looks something diff --git a/docs/release_notes/v0.6.1.md b/docs/release_notes/v0.6.1.md new file mode 100644 index 0000000..72ab490 --- /dev/null +++ b/docs/release_notes/v0.6.1.md @@ -0,0 +1,3 @@ +# v0.6.1 Release + +- feat: add shareable link to the website (#79) diff --git a/go.mod b/go.mod index 2b217de..c88a224 100644 --- a/go.mod +++ b/go.mod @@ -23,8 +23,8 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/net v0.24.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/text v0.15.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 5e93355..2043529 100644 --- a/go.sum +++ b/go.sum @@ -59,8 +59,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= -golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -69,8 +69,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= diff --git a/wasm/app-worker.js b/wasm/app-worker.js index 68b869c..22cec4c 100644 --- a/wasm/app-worker.js +++ b/wasm/app-worker.js @@ -1,8 +1,8 @@ -const cacheName = "app-" + "0bbe4f618b019a028888bfd14fb564d3bd34e87d"; +const cacheName = "app-" + "3b331e016b66866228750cf2fe2424dd99820a15"; const resourcesToCache = ["/","/app.css","/app.js","/manifest.webmanifest","/wasm_exec.js","/web/app.wasm","/web/css/alert.css","/web/img/logo.png","https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js","https://cdn.jsdelivr.net/npm/halfmoon@2.0.1/css/halfmoon.min.css","https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.11/clipboard.min.js","https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css","https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-twilight.min.css"]; self.addEventListener("install", (event) => { - console.log("installing app worker 0bbe4f618b019a028888bfd14fb564d3bd34e87d"); + console.log("installing app worker 3b331e016b66866228750cf2fe2424dd99820a15"); event.waitUntil( caches @@ -28,7 +28,7 @@ self.addEventListener("activate", (event) => { ); }) ); - console.log("app worker 0bbe4f618b019a028888bfd14fb564d3bd34e87d is activated"); + console.log("app worker 3b331e016b66866228750cf2fe2424dd99820a15 is activated"); }); self.addEventListener("fetch", (event) => { diff --git a/wasm/app.go b/wasm/app.go index bb0e3d1..40c48c0 100644 --- a/wasm/app.go +++ b/wasm/app.go @@ -2,10 +2,15 @@ package main import ( "bytes" + "errors" "fmt" + "net/http" + "net/url" "sort" "strconv" + "strings" + "github.com/Skarlso/crd-to-sample-yaml/pkg/fetcher" "github.com/maxence-charriere/go-app/v9/pkg/app" "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" "k8s.io/apimachinery/pkg/util/yaml" @@ -16,6 +21,7 @@ import ( // crdView is the main component to display a rendered CRD. type crdView struct { app.Compo + preRenderErr error content []byte comment bool @@ -53,9 +59,42 @@ func (h *crdView) buildError(err error) app.UI { app.Text(err.Error())) } +func (h *crdView) OnNav(ctx app.Context) { + if strings.Contains(ctx.Page().URL().String(), "share") { + u := ctx.Page().URL().Query().Get("url") + if u == "" { + h.preRenderErr = errors.New( + "url parameter has to be define in the following format: " + + "/share?url=https://example.com/crd.yaml") + + return + } + + if _, err := url.Parse(u); err != nil { + h.preRenderErr = fmt.Errorf("invald url provided in query: %w", err) + + return + } + + f := fetcher.NewFetcher(http.DefaultClient) + content, err := f.Fetch(u) + if err != nil { + h.preRenderErr = err + + return + } + + h.content = content + } +} + // The Render method is where the component appearance is defined. Here, a // "Hello World!" is displayed as a heading. func (h *crdView) Render() app.UI { + if h.preRenderErr != nil { + return h.buildError(h.preRenderErr) + } + crd := &v1beta1.CustomResourceDefinition{} if err := yaml.Unmarshal(h.content, crd); err != nil { return h.buildError(err) diff --git a/wasm/app.js b/wasm/app.js index 92c9f7b..d58e4b6 100644 --- a/wasm/app.js +++ b/wasm/app.js @@ -5,7 +5,7 @@ var goappNav = function () {}; var goappOnUpdate = function () {}; var goappOnAppInstallChange = function () {}; -const goappEnv = {"GOAPP_INTERNAL_URLS":"null","GOAPP_ROOT_PREFIX":"","GOAPP_STATIC_RESOURCES_URL":"","GOAPP_VERSION":"0bbe4f618b019a028888bfd14fb564d3bd34e87d"}; +const goappEnv = {"GOAPP_INTERNAL_URLS":"null","GOAPP_ROOT_PREFIX":"","GOAPP_STATIC_RESOURCES_URL":"","GOAPP_VERSION":"3b331e016b66866228750cf2fe2424dd99820a15"}; const goappLoadingLabel = "{progress}%"; const goappWasmContentLengthHeader = ""; diff --git a/wasm/index.html b/wasm/index.html index deaeae1..7bc5863 100644 --- a/wasm/index.html +++ b/wasm/index.html @@ -6,25 +6,25 @@ - - - + + + - +