Skip to content

Commit

Permalink
remove steampipe refs
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidaguerre committed Oct 18, 2023
1 parent a221505 commit 7d7212a
Show file tree
Hide file tree
Showing 12 changed files with 329 additions and 342 deletions.
19 changes: 19 additions & 0 deletions constants/dashboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package constants

import (
"fmt"

"github.com/turbot/steampipe/pkg/version"
)

// DashboardListenAddresses is an arrays is listen addresses which Steampipe accepts
var DashboardListenAddresses = []string{"localhost", "127.0.0.1"}

const (
DashboardServerDefaultPort = 9194
DashboardAssetsImageRefFormat = "us-docker.pkg.dev/steampipe/steampipe/assets:%s"
)

var (
DashboardAssetsImageRef = fmt.Sprintf(DashboardAssetsImageRefFormat, version.VersionString)
)
2 changes: 1 addition & 1 deletion controlexecute/result_row.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/turbot/pipe-fittings/constants"
"github.com/turbot/pipe-fittings/dashboardtypes"
"github.com/turbot/pipe-fittings/modconfig"
"github.com/turbot/pipe-fittings/query/queryresult"
"github.com/turbot/pipe-fittings/queryresult"
"github.com/turbot/pipe-fittings/utils"
)

Expand Down
62 changes: 62 additions & 0 deletions dashboardassets/ensure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package dashboardassets

import (
"context"
"encoding/json"
"log"
"os"

filehelpers "github.com/turbot/go-kit/files"
"github.com/turbot/pipe-fittings/filepaths"
"github.com/turbot/pipe-fittings/ociinstaller"
"github.com/turbot/pipe-fittings/statushooks"
"github.com/turbot/pipe-fittings/version"
"github.com/turbot/steampipe-plugin-sdk/v5/logging"
)

func Ensure(ctx context.Context) error {
logging.LogTime("dashboardassets.Ensure start")
defer logging.LogTime("dashboardassets.Ensure end")

// load report assets versions.json
versionFile, err := loadReportAssetVersionFile()
if err != nil {
return err
}

if versionFile.Version == version.VersionString {
return nil
}

statushooks.SetStatus(ctx, "Installing dashboard server…")

reportAssetsPath := filepaths.EnsureDashboardAssetsDir()

// remove the legacy report folder, if it exists
if _, err := os.Stat(filepaths.LegacyDashboardAssetsDir()); !os.IsNotExist(err) {
os.RemoveAll(filepaths.LegacyDashboardAssetsDir())
}

return ociinstaller.InstallAssets(ctx, reportAssetsPath)
}

type ReportAssetsVersionFile struct {
Version string `json:"version"`
}

func loadReportAssetVersionFile() (*ReportAssetsVersionFile, error) {
versionFilePath := filepaths.ReportAssetsVersionFilePath()
if !filehelpers.FileExists(versionFilePath) {
return &ReportAssetsVersionFile{}, nil
}

file, _ := os.ReadFile(versionFilePath)
var versionFile ReportAssetsVersionFile
if err := json.Unmarshal(file, &versionFile); err != nil {
log.Println("[ERROR]", "Error while reading dashboard assets version file", err)
return nil, err
}

return &versionFile, nil

}
2 changes: 1 addition & 1 deletion dashboardexecute/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/turbot/pipe-fittings/dashboardtypes"
"github.com/turbot/pipe-fittings/db/db_common"
"github.com/turbot/pipe-fittings/utils"
"github.com/turbot/powerpipe/internal/workspace"
"github.com/turbot/pipe-fittings/workspace"
)

type DashboardExecutor struct {
Expand Down
2 changes: 1 addition & 1 deletion dashboardexecute/referenced_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/turbot/pipe-fittings/dashboardtypes"
"github.com/turbot/pipe-fittings/modconfig"
"github.com/turbot/powerpipe/internal/workspace"
"github.com/turbot/pipe-fittings/workspace"
)

// GetReferencedVariables builds map of variables values containing only those mod variables which are referenced
Expand Down
137 changes: 64 additions & 73 deletions dashboardexecute/snapshot.go
Original file line number Diff line number Diff line change
@@ -1,75 +1,66 @@
package dashboardexecute

import (
"context"
"fmt"
"log"

"github.com/turbot/pipe-fittings/dashboardevents"
"github.com/turbot/pipe-fittings/dashboardtypes"
"github.com/turbot/pipe-fittings/modconfig"
"github.com/turbot/powerpipe/internal/initialisation"
)

func GenerateSnapshot(ctx context.Context, target string, initData *initialisation.InitData, inputs map[string]any) (snapshot *dashboardtypes.SteampipeSnapshot, err error) {
w := initData.Workspace

parsedName, err := modconfig.ParseResourceName(target)
if err != nil {
return nil, err
}
// no session for manual execution
sessionId := ""
errorChannel := make(chan error)
resultChannel := make(chan *dashboardtypes.SteampipeSnapshot)
dashboardEventHandler := func(ctx context.Context, event dashboardevents.DashboardEvent) {
handleDashboardEvent(ctx, event, resultChannel, errorChannel)
}
w.RegisterDashboardEventHandler(ctx, dashboardEventHandler)
// clear event handlers again in case another snapshot will be generated in this run
defer w.UnregisterDashboardEventHandlers()

// all runtime dependencies must be resolved before execution (i.e. inputs must be passed in)
Executor.interactive = false
Executor.ExecuteDashboard(ctx, sessionId, target, inputs, w, initData.Client)

select {
case err = <-errorChannel:
return nil, err
case snapshot = <-resultChannel:
// set the filename root of the snapshot
fileRootName, err := parsedName.ToFullNameWithMod(w.Mod.ShortName)
if err != nil {
return nil, err
}
snapshot.FileNameRoot = fileRootName
// return the context error (if any) to ensure we respect cancellation
return snapshot, ctx.Err()
}
}

func handleDashboardEvent(_ context.Context, event dashboardevents.DashboardEvent, resultChannel chan *dashboardtypes.SteampipeSnapshot, errorChannel chan error) {
switch e := event.(type) {
case *dashboardevents.ExecutionError:
errorChannel <- e.Error
case *dashboardevents.ExecutionComplete:
log.Println("[TRACE] execution complete event", *e)
snap := ExecutionCompleteToSnapshot(e)
resultChannel <- snap
}
}

// ExecutionCompleteToSnapshot transforms the ExecutionComplete event into a SteampipeSnapshot
func ExecutionCompleteToSnapshot(event *dashboardevents.ExecutionComplete) *dashboardtypes.SteampipeSnapshot {
return &dashboardtypes.SteampipeSnapshot{
SchemaVersion: fmt.Sprintf("%d", dashboardtypes.SteampipeSnapshotSchemaVersion),
Panels: event.Panels,
Layout: event.Root.AsTreeNode(),
Inputs: event.Inputs,
Variables: event.Variables,
SearchPath: event.SearchPath,
StartTime: event.StartTime,
EndTime: event.EndTime,
Title: event.Root.GetTitle(),
}
}
// TODO KAI MAKE ME WORK
//
//func GenerateSnapshot(ctx context.Context, target string, initData *initialisation.InitData, inputs map[string]any) (snapshot *dashboardtypes.SteampipeSnapshot, err error) {
// w := initData.Workspace
//
// parsedName, err := modconfig.ParseResourceName(target)
// if err != nil {
// return nil, err
// }
// // no session for manual execution
// sessionId := ""
// errorChannel := make(chan error)
// resultChannel := make(chan *dashboardtypes.SteampipeSnapshot)
// dashboardEventHandler := func(ctx context.Context, event dashboardevents.DashboardEvent) {
// handleDashboardEvent(ctx, event, resultChannel, errorChannel)
// }
// w.RegisterDashboardEventHandler(ctx, dashboardEventHandler)
// // clear event handlers again in case another snapshot will be generated in this run
// defer w.UnregisterDashboardEventHandlers()
//
// // all runtime dependencies must be resolved before execution (i.e. inputs must be passed in)
// Executor.interactive = false
// Executor.ExecuteDashboard(ctx, sessionId, target, inputs, w, initData.Client)
//
// select {
// case err = <-errorChannel:
// return nil, err
// case snapshot = <-resultChannel:
// // set the filename root of the snapshot
// fileRootName, err := parsedName.ToFullNameWithMod(w.Mod.ShortName)
// if err != nil {
// return nil, err
// }
// snapshot.FileNameRoot = fileRootName
// // return the context error (if any) to ensure we respect cancellation
// return snapshot, ctx.Err()
// }
//}
//
//func handleDashboardEvent(_ context.Context, event dashboardevents.DashboardEvent, resultChannel chan *dashboardtypes.SteampipeSnapshot, errorChannel chan error) {
// switch e := event.(type) {
// case *dashboardevents.ExecutionError:
// errorChannel <- e.Error
// case *dashboardevents.ExecutionComplete:
// log.Println("[TRACE] execution complete event", *e)
// snap := ExecutionCompleteToSnapshot(e)
// resultChannel <- snap
// }
//}
//
//// ExecutionCompleteToSnapshot transforms the ExecutionComplete event into a SteampipeSnapshot
//func ExecutionCompleteToSnapshot(event *dashboardevents.ExecutionComplete) *dashboardtypes.SteampipeSnapshot {
// return &dashboardtypes.SteampipeSnapshot{
// SchemaVersion: fmt.Sprintf("%d", dashboardtypes.SteampipeSnapshotSchemaVersion),
// Panels: event.Panels,
// Layout: event.Root.AsTreeNode(),
// Inputs: event.Inputs,
// Variables: event.Variables,
// SearchPath: event.SearchPath,
// StartTime: event.StartTime,
// EndTime: event.EndTime,
// Title: event.Root.GetTitle(),
// }
//}
3 changes: 1 addition & 2 deletions dashboardserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import (
"github.com/turbot/pipe-fittings/db/db_common"
"github.com/turbot/pipe-fittings/error_helpers"
"github.com/turbot/pipe-fittings/modconfig"
"github.com/turbot/powerpipe/internal/workspace"
"gopkg.in/olahol/melody.v1"
"github.com/turbot/pipe-fittings/workspace"
)

type Server struct {
Expand Down
2 changes: 1 addition & 1 deletion dashboardserver/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/shirou/gopsutil/process"
"github.com/spf13/viper"
"github.com/turbot/pipe-fittings/constants"
"github.com/turbot/pipe-fittings/dashboard/dashboardassets"
"github.com/turbot/pipe-fittings/dashboardassets"
"github.com/turbot/pipe-fittings/error_helpers"
"github.com/turbot/pipe-fittings/filepaths"
"github.com/turbot/pipe-fittings/utils"
Expand Down
Loading

0 comments on commit 7d7212a

Please sign in to comment.