Skip to content

Commit

Permalink
(feature): remote dashboard config capability (#27)
Browse files Browse the repository at this point in the history
* (feature): remote dashboard config use

Signed-off-by: Bryce Palmer <[email protected]>

* add to readme

Signed-off-by: Bryce Palmer <[email protected]>

---------

Signed-off-by: Bryce Palmer <[email protected]>
  • Loading branch information
everettraven authored Nov 15, 2023
1 parent 89a37a5 commit 2a0ba60
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ The `test.json` file contains samples for each of the different panel types that

`buoy` uses https://github.com/tidwall/gjson for the path evaluation and extracting of values from resources. Please consult their documentation for valid path syntax.

You can also specify a remote reference to a dashboard configuration file. It must be a valid URL and the response must be the raw YAML or JSON contents of the file.

## Controls
- `ctrl+c`, `q`, `esc` will quit the program and exit the tui
- `tab` will switch the active tab to the one to the right of the currently active tab
Expand Down
30 changes: 24 additions & 6 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package cli
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/url"
"os"
"path/filepath"

Expand All @@ -17,7 +20,7 @@ import (
)

var rootCommand = &cobra.Command{
Use: "buoy [file.json]",
Use: "buoy [config]",
Short: "declarative kubernetes dashboard in the terminal",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -29,14 +32,29 @@ func init() {
rootCommand.AddCommand(versionCommand)
}

func run(file string) error {
ext := filepath.Ext(file)
raw, err := os.ReadFile(file)
func run(path string) error {
var raw []byte
var ext string
u, err := url.ParseRequestURI(path)
if err != nil {
log.Fatalf("reading file: %s", err)
ext = filepath.Ext(path)
raw, err = os.ReadFile(path)
if err != nil {
log.Fatalf("reading local config: %s", err)
}
} else {
ext = filepath.Ext(u.Path)
resp, err := http.Get(u.String())
if err != nil {
log.Fatalf("fetching remote config: %s", err)
}
defer resp.Body.Close()
raw, err = io.ReadAll(resp.Body)
if err != nil {
log.Fatalf("reading remote config: %s", err)
}
}

fmt.Println(ext)
dash := &types.Dashboard{}
if ext == ".yaml" {
err = yaml.Unmarshal(raw, dash)
Expand Down

0 comments on commit 2a0ba60

Please sign in to comment.