Skip to content

Commit

Permalink
chore: handle kibana datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
marianozunino committed Jul 18, 2024
1 parent a92f41f commit 1fa56ed
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions internal/program/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func parseDataSources(output string) []storage.DataSource {
Type: fields[statusIndex+2],
Tags: strings.Join(fields[statusIndex+3:], " "),
}
if dataSource.Type == "amazones" {
dataSource.Address = fmt.Sprintf("http://%s/_plugin/kibana/app/kibana", dataSource.Address)
}
dataSources = append(dataSources, dataSource)
}
}
Expand Down
15 changes: 12 additions & 3 deletions internal/program/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,26 @@ func (p *Program) validateAccount() error {

func printDataSources(dataSources []storage.DataSource, w io.Writer) {
const format = "%v\t%v\t%v\n"
tw := new(tabwriter.Writer).Init(w, 0, 8, 2, ' ', 0)
tw := new(tabwriter.Writer).Init(w, 0, 8, 1, '\t', 0)

for _, ds := range dataSources {
status := "🔒"
if ds.Status == "connected" {
status = "✅"
}

fmt.Fprintf(tw, format, ds.Name, ds.Address, status)
fmt.Fprintf(tw, format, ds.Name, elipsise(ds.Address, 20), status)
}
tw.Flush()
}

func elipsise(s string, maxLen int) string {
if len(s) <= maxLen {
return s
}
return s[:maxLen] + "..."
}

func (p *Program) retryCommand(command func() error) error {
if err := command(); err != nil {
sdmErr, ok := err.(sdm.SDMError)
Expand All @@ -145,8 +152,10 @@ func (p *Program) retryCommand(command func() error) error {
case sdm.Unauthorized:
notify.Notify("SDM CLI", "Authenticating... 🔐", "", "")
return p.retryCommand(func() error {
return p.sdmWrapper.Login(p.account, p.password)
p.sdmWrapper.Login(p.account, p.password)
return command()
})

case sdm.InvalidCredentials:
notify.Notify("SDM CLI", "Authentication error 🔐", "Invalid credentials", "")
p.keyring.DeleteSecret(p.account)
Expand Down
3 changes: 1 addition & 2 deletions internal/program/rofi.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func (p *Program) executeRofi(args []string) error {
cmd := exec.Command("rofi", "-dmenu", "-i", "-p", "Select Data Source")
cmd.Stdin = bytesOut
rofiOut, err := cmd.Output()

if err != nil {
fmt.Println("[rofi] Failed to execute rofi")
return nil
Expand All @@ -49,7 +48,7 @@ func (p *Program) executeRofi(args []string) error {
message := fmt.Sprintf(dataSource)
message += fmt.Sprintf("\n📋 <b>%s</b>", dataSourcePort)

if strings.HasPrefix(dataSourcePort, "https:") {
if strings.HasPrefix(dataSourcePort, "http") {
open.Start(dataSourcePort)
} else {
if clip, err := clipper.GetClipboard(clipper.Clipboards...); err != nil {
Expand Down

0 comments on commit 1fa56ed

Please sign in to comment.