-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a221505
commit 7d7212a
Showing
12 changed files
with
329 additions
and
342 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
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) | ||
) |
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,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 | ||
|
||
} |
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 |
---|---|---|
@@ -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(), | ||
// } | ||
//} |
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
Oops, something went wrong.