Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions internal/dashboardserver/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ func (s *Server) buildServerMetadataPayload(rm modconfig.ModResources, pipesMeta
cliVersion = versionFile.Version
}

// populate the backend support flags (supportsSearchPath, supportsTimeRange) from the default database
bs := newBackendSupport(s.defaultDatabase)

payload := ServerMetadataPayload{
Action: "server_metadata",
Expand All @@ -62,8 +60,7 @@ func (s *Server) buildServerMetadataPayload(rm modconfig.ModResources, pipesMeta
},
InstalledMods: installedMods,
Telemetry: viper.GetString(constants.ArgTelemetry),
SupportsSearchPath: bs.supportsSearchPath,
SupportsTimeRange: bs.supportsTimeRange,

},
}

Expand All @@ -72,10 +69,16 @@ func (s *Server) buildServerMetadataPayload(rm modconfig.ModResources, pipesMeta
return nil, err
}
searchPath, err := getSearchPathMetadata(context.Background(), connectionString, s.defaultSearchPathConfig)
if err != nil {
return nil, err
if err == nil {
// NOTE: getSearchPathMetadata may fail if the default database is not running - rhis is ok as we may actually not require the default db
payload.Metadata.SearchPath = searchPath

// only populate backend support if we were able to get the search path metadata
// populate the backend support flags (supportsSearchPath, supportsTimeRange) from the default database
bs := newBackendSupport(s.defaultDatabase)
payload.Metadata.SupportsSearchPath = bs.supportsSearchPath
payload.Metadata.SupportsTimeRange = bs.supportsTimeRange
}
payload.Metadata.SearchPath = searchPath

if mod := workspaceResources.Mod; mod != nil {
payload.Metadata.Mod = &ModMetadata{
Expand All @@ -93,7 +96,7 @@ func (s *Server) buildServerMetadataPayload(rm modconfig.ModResources, pipesMeta
}

func (s *Server) buildDashboardMetadataPayload(dashboard modconfig.ModTreeItem) ([]byte, error) {
slog.Debug("calling buildDashboardMetadataPayload")
slog.Info("calling buildDashboardMetadataPayload")

// walk the tree of resources and determine whether any of them are using a tailpipe/steampipe/postrgres
// and set the SupportsSearchPath and SupportsTimeRange flags accordingly
Expand Down
45 changes: 31 additions & 14 deletions internal/initialisation/init_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,30 +192,47 @@ func (i *InitData) GetDefaultClient(ctx context.Context) (*db_client.DbClient, e
}

func (i *InitData) validateModRequirements(ctx context.Context, mod *modconfig.Mod) ([]string, error) {
connectionString, err := i.DefaultDatabase.GetConnectionString()
// try to get the plugin version map from the backend
// if the backend is not steampipe, or is not running, do not fail, just return an empty plugin version map
// - the validation code will handle this and just NOT validate the required plugins
pluginVersionMap, err := i.getPluginVersionMap(ctx)
if err != nil {
return nil, err
}

b, err := backend.FromConnectionString(ctx, connectionString)
warnings := validateModRequirementsRecursively(mod, pluginVersionMap)
return warnings, nil
}

// try to connect to the default database to determine if it is a steampipe backend
// if it is, retrieve the available plugins from the backend
// NOTE: the default database will be steampipe but the steampipe server may not be running
// (this may be valid, for example in the case of a tailpipe mod being installed - we do not need steampipe server)
// So - if we fail to connect to the default database THIS IS NOT AN ERROR.
// It just means we cannot populate the available plugins from the backend
func (i *InitData) getPluginVersionMap(ctx context.Context) (*plugin.PluginVersionMap, error) {
connectionString, err := i.DefaultDatabase.GetConnectionString()
if err != nil {
return nil, err
}
warnings := validateModRequirementsRecursively(mod, connectionString, b)
return warnings, nil
b, err := backend.FromConnectionString(ctx, connectionString)
if err == nil {
// if we successfully created the backend, determine whether it is a steampipe backend
if steampipeBackend, ok := b.(*backend.SteampipeBackend); ok {
return &plugin.PluginVersionMap{
Database: connectionString,
Backend: steampipeBackend.Name(),
AvailablePlugins: steampipeBackend.PluginVersions,
}, nil
}
}
// if we failed to create the backend, or it is not a steampipe backend, return an empty plugin version map
return nil, nil
}

func validateModRequirementsRecursively(mod *modconfig.Mod, connectionString string, be backend.Backend) []string {
func validateModRequirementsRecursively(mod *modconfig.Mod, pluginVersionMap *plugin.PluginVersionMap) []string {
var validationErrors []string

var pluginVersionMap = &plugin.PluginVersionMap{
Database: connectionString,
Backend: be.Name(),
}
// if the backend is steampipe, populate the available plugins
if steampipeBackend, ok := be.(*backend.SteampipeBackend); ok {
pluginVersionMap.AvailablePlugins = steampipeBackend.PluginVersions
}
// validate this mod
for _, err := range mod.ValidateRequirements(pluginVersionMap) {
validationErrors = append(validationErrors, err.Error())
Expand All @@ -227,7 +244,7 @@ func validateModRequirementsRecursively(mod *modconfig.Mod, connectionString str
// this is a reference to self - skip (otherwise we will end up with a recursion loop)
continue
}
childValidationErrors := validateModRequirementsRecursively(childMod, connectionString, be)
childValidationErrors := validateModRequirementsRecursively(childMod, pluginVersionMap)
validationErrors = append(validationErrors, childValidationErrors...)
}

Expand Down