Skip to content

Commit

Permalink
Remove the dust
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Phoen committed Mar 22, 2023
1 parent 61cae91 commit 3b0991f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 26 deletions.
2 changes: 2 additions & 0 deletions cmd/wasm/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build js && wasm

package main

import (
Expand Down
4 changes: 3 additions & 1 deletion dark-web-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" ./dark-web-extension
npm install --global web-ext
cd ./dark-web-extension/
web-ext build
```
```

The extension can then be installing from the file generated by `web-ext`: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Your_first_WebExtension#installing
29 changes: 13 additions & 16 deletions dark-web-extension/content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,43 @@ if (isGrafana()) {
console.debug("content_script bootstrap");

// hackish way of giving enough time for grafana to load the dashboard
waitForElm('.page-toolbar').then((elm) => {
waitForElm('.page-toolbar').then(() => {
console.debug('page-toolbar found, inserting DARK export button');
setupExportButton();
});
}

function setupExportButton() {
var elements = document.getElementsByClassName("page-toolbar");
const buttonsContainer = document.querySelector('.page-toolbar > div:last-child');

if (elements.length === 0) {
console.debug("page-toolbar not found");
if (buttonsContainer.length === 0) {
console.debug("buttons container not found");
return;
}

console.debug("appending export button");
const pageToolbarElmt = elements[0];

const lastButton = pageToolbarElmt.childNodes[pageToolbarElmt.childNodes.length - 1];
const lastButton = buttonsContainer.childNodes[buttonsContainer.childNodes.length - 1];
const darkExportButton = lastButton.cloneNode(true);
darkExportButton.onclick = triggerExport;
darkExportButton.title = 'Export as DARK dashboard';

darkExportButton.childNodes[0].childNodes[0].childNodes[0].innerHTML = `<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 493.525 493.525" style="enable-background:new 0 0 493.525 493.525;" xml:space="preserve">
<g id="XMLID_30_">
<path id="XMLID_32_" d="M430.557,79.556H218.44c21.622,12.688,40.255,29.729,54.859,49.906h157.258
const darkExportButtonSVG = darkExportButton.querySelector('svg');
darkExportButtonSVG.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 493.525 493.525" xml:space="preserve">
<g>
<path d="M430.557,79.556H218.44c21.622,12.688,40.255,29.729,54.859,49.906h157.258
c7.196,0,13.063,5.863,13.063,13.06v238.662c0,7.199-5.866,13.064-13.063,13.064H191.894c-7.198,0-13.062-5.865-13.062-13.064
V222.173c-6.027-3.1-12.33-5.715-18.845-7.732c-3.818,11.764-12.105,21.787-23.508,27.781c-2.39,1.252-4.987,2.014-7.554,2.844
v136.119c0,34.717,28.25,62.971,62.968,62.971h238.663c34.718,0,62.969-28.254,62.969-62.971V142.522
C493.525,107.806,465.275,79.556,430.557,79.556z"/>
<path id="XMLID_31_" d="M129.037,175.989c51.419,1.234,96.388,28.283,122.25,68.865c2.371,3.705,6.434,5.848,10.657,5.848
C493.525,107.806,465.275,79.556,430.557,79.556z" />
<path d="M129.037,175.989c51.419,1.234,96.388,28.283,122.25,68.865c2.371,3.705,6.434,5.848,10.657,5.848
c1.152,0,2.322-0.162,3.46-0.486c5.377-1.545,9.114-6.418,9.179-12.006c0-0.504,0-1.01,0-1.51
c0-81.148-64.853-147.023-145.527-148.957V64.155c0-5.492-3.038-10.512-7.879-13.078c-2.16-1.139-4.533-1.707-6.889-1.707
c-2.94,0-5.848,0.88-8.35,2.584L5.751,120.526C2.162,122.98,0.018,127.041,0,131.394c-0.017,4.338,2.113,8.418,5.687,10.902
l100.17,69.451c2.518,1.753,5.459,2.631,8.414,2.631c2.355,0,4.696-0.553,6.857-1.676c4.855-2.549,7.909-7.6,7.909-13.092V175.989z
"/>
l100.17,69.451c2.518,1.753,5.459,2.631,8.414,2.631c2.355,0,4.696-0.553,6.857-1.676c4.855-2.549,7.909-7.6,7.909-13.092V175.989z" />
</g>
</svg>`;

pageToolbarElmt.appendChild(darkExportButton);
buttonsContainer.appendChild(darkExportButton);
}

function triggerExport() {
Expand Down
2 changes: 1 addition & 1 deletion dark-web-extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
]
}
]
}
}
4 changes: 2 additions & 2 deletions dark-web-extension/wasm_exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
outputBuf += decoder.decode(buf);
const nl = outputBuf.lastIndexOf("\n");
if (nl != -1) {
console.log(outputBuf.substr(0, nl));
outputBuf = outputBuf.substr(nl + 1);
console.log(outputBuf.substring(0, nl));
outputBuf = outputBuf.substring(nl + 1);
}
return buf.length;
},
Expand Down
7 changes: 3 additions & 4 deletions internal/pkg/controllers/grafanadashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ package controllers
import (
"context"

"sigs.k8s.io/controller-runtime/pkg/controller"

k8skevingomezfrv1 "github.com/K-Phoen/dark/api/v1"
"github.com/K-Phoen/dark/internal/pkg/grafana"
"github.com/K-Phoen/dark/internal/pkg/model"
"github.com/K-Phoen/grabana"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/log"
)

const grafanaDashboardFinalizerName = "grafanadashboards.k8s.kevingomez.fr/finalizer"
const DashboardFolderAnnotation = "dark/folder"

type dashboardManager interface {
FromRawSpec(ctx context.Context, folderName string, uid string, rawJSON []byte) error
Expand Down Expand Up @@ -103,7 +102,7 @@ func (r *GrafanaDashboardReconciler) Reconcile(ctx context.Context, req ctrl.Req
return ctrl.Result{}, nil
}

folder := dashboard.Annotations[DashboardFolderAnnotation]
folder := dashboard.Annotations[model.DashboardFolderAnnotation]
if dashboard.Folder != "" {
folder = dashboard.Folder
}
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/converter/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io"

v1 "github.com/K-Phoen/dark/api/v1"
"github.com/K-Phoen/dark/internal/pkg/controllers"
"github.com/K-Phoen/dark/internal/pkg/model"
grabana "github.com/K-Phoen/grabana/decoder"
"github.com/K-Phoen/sdk"
"go.uber.org/zap"
Expand Down Expand Up @@ -90,7 +90,7 @@ func (converter *JSON) ToK8SManifest(input io.Reader, output io.Writer, options

if options.Folder != "" {
manifest.Metadata["annotations"] = map[string]string{
controllers.DashboardFolderAnnotation: options.Folder,
model.DashboardFolderAnnotation: options.Folder,
}
}

Expand Down
3 changes: 3 additions & 0 deletions internal/pkg/model/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package model

const DashboardFolderAnnotation = "dark/folder"

0 comments on commit 3b0991f

Please sign in to comment.