-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for Grafana API key Auth (#93)
- Loading branch information
1 parent
3a24b5b
commit 353ed9b
Showing
4 changed files
with
92 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package kiosk | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
|
||
"github.com/chromedp/cdproto/network" | ||
"github.com/chromedp/chromedp" | ||
) | ||
|
||
// GrafanaKioskApikey creates a chrome-based kiosk using a grafana api key. | ||
func GrafanaKioskApikey(cfg *Config) { | ||
dir, err := os.MkdirTemp(os.TempDir(), "chromedp-kiosk") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
log.Println("Using temp dir:", dir) | ||
defer os.RemoveAll(dir) | ||
|
||
opts := generateExecutorOptions(dir, cfg.General.WindowPosition, cfg.Target.IgnoreCertificateErrors) | ||
|
||
allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...) | ||
defer cancel() | ||
|
||
// also set up a custom logger | ||
taskCtx, cancel := chromedp.NewContext(allocCtx, chromedp.WithLogf(log.Printf)) | ||
defer cancel() | ||
|
||
listenChromeEvents(taskCtx, consoleAPICall|targetCrashed) | ||
|
||
// ensure that the browser process is started | ||
if err := chromedp.Run(taskCtx); err != nil { | ||
panic(err) | ||
} | ||
|
||
// Give browser time to load next page (this can be prone to failure, explore different options vs sleeping) | ||
time.Sleep(2000 * time.Millisecond) | ||
|
||
var generatedURL = GenerateURL(cfg.Target.URL, cfg.General.Mode, cfg.General.AutoFit, cfg.Target.IsPlayList) | ||
|
||
log.Println("Navigating to ", generatedURL) | ||
/* | ||
Launch chrome and look for main-view element | ||
*/ | ||
headers := map[string]interface{}{ | ||
"Authorization": "Bearer " + cfg.APIKEY.Apikey, | ||
} | ||
if err := chromedp.Run(taskCtx, | ||
network.Enable(), | ||
network.SetExtraHTTPHeaders(network.Headers(headers)), | ||
chromedp.Navigate(generatedURL), | ||
chromedp.WaitVisible(`//div[@class="main-view"]`, chromedp.BySearch), | ||
// wait forever (for now) | ||
chromedp.WaitVisible("notinputPassword", chromedp.ByID), | ||
); err != nil { | ||
panic(err) | ||
} | ||
|
||
log.Println("Sleep before exit...") | ||
// wait here for the process to exit | ||
time.Sleep(2000 * time.Millisecond) | ||
log.Println("Exit...") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters