mirror of
https://github.com/turbot/steampipe.git
synced 2025-12-19 18:12:43 -05:00
Update all ErrorAndWarnings function returns to pass by value, removing possibility of nil ErrorAndWarnings. Closes #3974 (#4212)
This commit is contained in:
@@ -634,7 +634,7 @@ func runPluginListCmd(cmd *cobra.Command, _ []string) {
|
||||
|
||||
}
|
||||
|
||||
func showPluginListOutput(pluginList []plugin.PluginListItem, failedPluginMap, missingPluginMap map[string][]*modconfig.Connection, res *error_helpers.ErrorAndWarnings, outputFormat string) error {
|
||||
func showPluginListOutput(pluginList []plugin.PluginListItem, failedPluginMap, missingPluginMap map[string][]*modconfig.Connection, res error_helpers.ErrorAndWarnings, outputFormat string) error {
|
||||
switch outputFormat {
|
||||
case "table":
|
||||
return showPluginListAsTable(pluginList, failedPluginMap, missingPluginMap, res)
|
||||
@@ -645,7 +645,7 @@ func showPluginListOutput(pluginList []plugin.PluginListItem, failedPluginMap, m
|
||||
}
|
||||
}
|
||||
|
||||
func showPluginListAsTable(pluginList []plugin.PluginListItem, failedPluginMap, missingPluginMap map[string][]*modconfig.Connection, res *error_helpers.ErrorAndWarnings) error {
|
||||
func showPluginListAsTable(pluginList []plugin.PluginListItem, failedPluginMap, missingPluginMap map[string][]*modconfig.Connection, res error_helpers.ErrorAndWarnings) error {
|
||||
headers := []string{"Installed", "Version", "Connections"}
|
||||
var rows [][]string
|
||||
// List installed plugins in a table
|
||||
@@ -695,7 +695,7 @@ func showPluginListAsTable(pluginList []plugin.PluginListItem, failedPluginMap,
|
||||
return nil
|
||||
}
|
||||
|
||||
func showPluginListAsJSON(pluginList []plugin.PluginListItem, failedPluginMap, missingPluginMap map[string][]*modconfig.Connection, res *error_helpers.ErrorAndWarnings) error {
|
||||
func showPluginListAsJSON(pluginList []plugin.PluginListItem, failedPluginMap, missingPluginMap map[string][]*modconfig.Connection, res error_helpers.ErrorAndWarnings) error {
|
||||
output := pluginJsonOutput{}
|
||||
|
||||
for _, item := range pluginList {
|
||||
@@ -796,7 +796,7 @@ func runPluginUninstallCmd(cmd *cobra.Command, args []string) {
|
||||
reports.Print()
|
||||
}
|
||||
|
||||
func getPluginList(ctx context.Context) (pluginList []plugin.PluginListItem, failedPluginMap, missingPluginMap map[string][]*modconfig.Connection, res *error_helpers.ErrorAndWarnings) {
|
||||
func getPluginList(ctx context.Context) (pluginList []plugin.PluginListItem, failedPluginMap, missingPluginMap map[string][]*modconfig.Connection, res error_helpers.ErrorAndWarnings) {
|
||||
statushooks.Show(ctx)
|
||||
defer statushooks.Done(ctx)
|
||||
|
||||
@@ -827,13 +827,13 @@ func getPluginList(ctx context.Context) (pluginList []plugin.PluginListItem, fai
|
||||
return pluginList, failedPluginMap, missingPluginMap, res
|
||||
}
|
||||
|
||||
func getPluginConnectionMap(ctx context.Context) (pluginConnectionMap, failedPluginMap, missingPluginMap map[string][]*modconfig.Connection, res *error_helpers.ErrorAndWarnings) {
|
||||
func getPluginConnectionMap(ctx context.Context) (pluginConnectionMap, failedPluginMap, missingPluginMap map[string][]*modconfig.Connection, res error_helpers.ErrorAndWarnings) {
|
||||
utils.LogTime("cmd.getPluginConnectionMap start")
|
||||
defer utils.LogTime("cmd.getPluginConnectionMap end")
|
||||
|
||||
statushooks.SetStatus(ctx, "Fetching connection map")
|
||||
|
||||
res = &error_helpers.ErrorAndWarnings{}
|
||||
res = error_helpers.ErrorAndWarnings{}
|
||||
|
||||
connectionStateMap, stateRes := getConnectionState(ctx)
|
||||
res.Merge(stateRes)
|
||||
@@ -865,7 +865,7 @@ func getPluginConnectionMap(ctx context.Context) (pluginConnectionMap, failedPlu
|
||||
}
|
||||
|
||||
// load the connection state, waiting until all connections are loaded
|
||||
func getConnectionState(ctx context.Context) (steampipeconfig.ConnectionStateMap, *error_helpers.ErrorAndWarnings) {
|
||||
func getConnectionState(ctx context.Context) (steampipeconfig.ConnectionStateMap, error_helpers.ErrorAndWarnings) {
|
||||
utils.LogTime("cmd.getConnectionState start")
|
||||
defer utils.LogTime("cmd.getConnectionState end")
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ func setMemoryLimit() {
|
||||
// task run is complete
|
||||
//
|
||||
// runScheduledTasks skips running tasks if this instance is the plugin manager
|
||||
func runScheduledTasks(ctx context.Context, cmd *cobra.Command, args []string, ew *error_helpers.ErrorAndWarnings) chan struct{} {
|
||||
func runScheduledTasks(ctx context.Context, cmd *cobra.Command, args []string, ew error_helpers.ErrorAndWarnings) chan struct{} {
|
||||
// skip running the task runner if this is the plugin manager
|
||||
// since it's supposed to be a daemon
|
||||
if task.IsPluginManagerCmd(cmd) {
|
||||
@@ -189,7 +189,7 @@ func envLogLevelSet() bool {
|
||||
}
|
||||
|
||||
// initConfig reads in config file and ENV variables if set.
|
||||
func initGlobalConfig() *error_helpers.ErrorAndWarnings {
|
||||
func initGlobalConfig() error_helpers.ErrorAndWarnings {
|
||||
utils.LogTime("cmdconfig.initGlobalConfig start")
|
||||
defer utils.LogTime("cmdconfig.initGlobalConfig end")
|
||||
|
||||
@@ -263,8 +263,8 @@ func initGlobalConfig() *error_helpers.ErrorAndWarnings {
|
||||
return loadConfigErrorsAndWarnings
|
||||
}
|
||||
|
||||
func handleDeprecations() *error_helpers.ErrorAndWarnings {
|
||||
var ew = &error_helpers.ErrorAndWarnings{}
|
||||
func handleDeprecations() error_helpers.ErrorAndWarnings {
|
||||
var ew = error_helpers.ErrorAndWarnings{}
|
||||
// if deprecated cloud-token or cloud-host is set, show a warning and copy the value to the new arg
|
||||
if viper.IsSet(constants.ArgCloudToken) {
|
||||
if viper.IsSet(constants.ArgPipesToken) {
|
||||
@@ -370,8 +370,8 @@ func getWorkspaceProfileLoader(ctx context.Context) (*steampipeconfig.WorkspaceP
|
||||
|
||||
// now validate config values have appropriate values
|
||||
// (currently validates telemetry)
|
||||
func validateConfig() *error_helpers.ErrorAndWarnings {
|
||||
var res = &error_helpers.ErrorAndWarnings{}
|
||||
func validateConfig() error_helpers.ErrorAndWarnings {
|
||||
var res = error_helpers.ErrorAndWarnings{}
|
||||
telemetry := viper.GetString(constants.ArgTelemetry)
|
||||
if !helpers.StringSliceContains(constants.TelemetryLevels, telemetry) {
|
||||
res.Error = sperr.New(`invalid value of 'telemetry' (%s), must be one of: %s`, telemetry, strings.Join(constants.TelemetryLevels, ", "))
|
||||
@@ -459,7 +459,7 @@ func ensureInstallDir() {
|
||||
}
|
||||
|
||||
// displayDeprecationWarnings shows the deprecated warnings in a formatted way
|
||||
func displayDeprecationWarnings(errorsAndWarnings *error_helpers.ErrorAndWarnings) {
|
||||
func displayDeprecationWarnings(errorsAndWarnings error_helpers.ErrorAndWarnings) {
|
||||
if len(errorsAndWarnings.Warnings) > 0 {
|
||||
fmt.Println(color.YellowString(fmt.Sprintf("\nDeprecation %s:", utils.Pluralize("warning", len(errorsAndWarnings.Warnings)))))
|
||||
for _, warning := range errorsAndWarnings.Warnings {
|
||||
|
||||
@@ -18,6 +18,6 @@ type pluginManager interface {
|
||||
ShouldFetchRateLimiterDefs() bool
|
||||
LoadPluginRateLimiters(map[string]string) (PluginLimiterMap, error)
|
||||
SendPostgresSchemaNotification(context.Context) error
|
||||
SendPostgresErrorsAndWarningsNotification(context.Context, *error_helpers.ErrorAndWarnings)
|
||||
SendPostgresErrorsAndWarningsNotification(context.Context, error_helpers.ErrorAndWarnings)
|
||||
UpdatePluginColumnsTable(context.Context, map[string]*proto.Schema, []string) error
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ func (s *refreshConnectionState) refreshConnections(ctx context.Context) {
|
||||
}
|
||||
if !s.res.ErrorAndWarnings.Empty() {
|
||||
log.Printf("[INFO] refreshConnections completed with errors, sending notification")
|
||||
s.pluginManager.SendPostgresErrorsAndWarningsNotification(ctx, &s.res.ErrorAndWarnings)
|
||||
s.pluginManager.SendPostgresErrorsAndWarningsNotification(ctx, s.res.ErrorAndWarnings)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,14 +8,14 @@ import (
|
||||
"github.com/turbot/steampipe/pkg/error_helpers"
|
||||
)
|
||||
|
||||
func ValidateClientCacheSettings(c Client) *error_helpers.ErrorAndWarnings {
|
||||
func ValidateClientCacheSettings(c Client) error_helpers.ErrorAndWarnings {
|
||||
cacheEnabledResult := ValidateClientCacheEnabled(c)
|
||||
cacheTtlResult := ValidateClientCacheTtl(c)
|
||||
|
||||
return error_helpers.EmptyErrorsAndWarning().Merge(cacheEnabledResult).Merge(cacheTtlResult)
|
||||
return cacheEnabledResult.Merge(cacheTtlResult)
|
||||
}
|
||||
|
||||
func ValidateClientCacheEnabled(c Client) *error_helpers.ErrorAndWarnings {
|
||||
func ValidateClientCacheEnabled(c Client) error_helpers.ErrorAndWarnings {
|
||||
errorsAndWarnings := error_helpers.EmptyErrorsAndWarning()
|
||||
if c.ServerSettings() == nil || !viper.IsSet(constants.ArgClientCacheEnabled) {
|
||||
// if there's no serverSettings, then this is a pre-21 server
|
||||
@@ -29,7 +29,7 @@ func ValidateClientCacheEnabled(c Client) *error_helpers.ErrorAndWarnings {
|
||||
return errorsAndWarnings
|
||||
}
|
||||
|
||||
func ValidateClientCacheTtl(c Client) *error_helpers.ErrorAndWarnings {
|
||||
func ValidateClientCacheTtl(c Client) error_helpers.ErrorAndWarnings {
|
||||
errorsAndWarnings := error_helpers.EmptyErrorsAndWarning()
|
||||
|
||||
if c.ServerSettings() == nil || !viper.IsSet(constants.ArgCacheTtl) {
|
||||
|
||||
@@ -23,7 +23,7 @@ type LocalDbClient struct {
|
||||
}
|
||||
|
||||
// GetLocalClient starts service if needed and creates a new LocalDbClient
|
||||
func GetLocalClient(ctx context.Context, invoker constants.Invoker, onConnectionCallback db_client.DbConnectionCallback, opts ...db_client.ClientOption) (*LocalDbClient, *error_helpers.ErrorAndWarnings) {
|
||||
func GetLocalClient(ctx context.Context, invoker constants.Invoker, onConnectionCallback db_client.DbConnectionCallback, opts ...db_client.ClientOption) (*LocalDbClient, error_helpers.ErrorAndWarnings) {
|
||||
utils.LogTime("db.GetLocalClient start")
|
||||
defer utils.LogTime("db.GetLocalClient end")
|
||||
|
||||
@@ -41,7 +41,7 @@ func GetLocalClient(ctx context.Context, invoker constants.Invoker, onConnection
|
||||
log.Printf("[INFO] StartServices")
|
||||
startResult := StartServices(ctx, listenAddresses, port, invoker)
|
||||
if startResult.Error != nil {
|
||||
return nil, &startResult.ErrorAndWarnings
|
||||
return nil, startResult.ErrorAndWarnings
|
||||
}
|
||||
|
||||
log.Printf("[INFO] newLocalClient")
|
||||
@@ -62,7 +62,7 @@ func GetLocalClient(ctx context.Context, invoker constants.Invoker, onConnection
|
||||
_, _ = startResult.PluginManager.RefreshConnections(&pb.RefreshConnectionsRequest{})
|
||||
}
|
||||
|
||||
return client, &startResult.ErrorAndWarnings
|
||||
return client, startResult.ErrorAndWarnings
|
||||
}
|
||||
|
||||
// newLocalClient verifies that the local database instance is running and returns a LocalDbClient to interact with it
|
||||
|
||||
@@ -11,28 +11,28 @@ type ErrorAndWarnings struct {
|
||||
Warnings []string
|
||||
}
|
||||
|
||||
func DiagsToErrorsAndWarnings(errPrefix string, diags hcl.Diagnostics) *ErrorAndWarnings {
|
||||
func DiagsToErrorsAndWarnings(errPrefix string, diags hcl.Diagnostics) ErrorAndWarnings {
|
||||
return NewErrorsAndWarning(
|
||||
plugin.DiagsToError(errPrefix, diags),
|
||||
plugin.DiagsToWarnings(diags)...,
|
||||
)
|
||||
}
|
||||
|
||||
func EmptyErrorsAndWarning() *ErrorAndWarnings {
|
||||
func EmptyErrorsAndWarning() ErrorAndWarnings {
|
||||
return NewErrorsAndWarning(nil)
|
||||
}
|
||||
|
||||
func NewErrorsAndWarning(err error, warnings ...string) *ErrorAndWarnings {
|
||||
return &ErrorAndWarnings{
|
||||
func NewErrorsAndWarning(err error, warnings ...string) ErrorAndWarnings {
|
||||
return ErrorAndWarnings{
|
||||
Error: err, Warnings: warnings,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ErrorAndWarnings) WrapErrorWithMessage(msg string) *ErrorAndWarnings {
|
||||
func (r *ErrorAndWarnings) WrapErrorWithMessage(msg string) ErrorAndWarnings {
|
||||
if r.Error != nil {
|
||||
r.Error = sperr.WrapWithMessage(r.Error, msg)
|
||||
}
|
||||
return r
|
||||
return *r
|
||||
}
|
||||
|
||||
func (r *ErrorAndWarnings) AddWarning(warnings ...string) {
|
||||
@@ -46,7 +46,6 @@ func (r *ErrorAndWarnings) AddWarning(warnings ...string) {
|
||||
}
|
||||
|
||||
func (r *ErrorAndWarnings) ShowWarnings() {
|
||||
|
||||
for _, w := range r.Warnings {
|
||||
ShowWarning(w)
|
||||
}
|
||||
@@ -59,11 +58,7 @@ func (r *ErrorAndWarnings) GetError() error {
|
||||
return r.Error
|
||||
}
|
||||
|
||||
func (r *ErrorAndWarnings) Merge(other *ErrorAndWarnings) *ErrorAndWarnings {
|
||||
if other == nil {
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *ErrorAndWarnings) Merge(other ErrorAndWarnings) ErrorAndWarnings {
|
||||
// TODO: Restructure ErrorsAndWarning
|
||||
// [issue](https://github.com/turbot/steampipe/issues/3845)
|
||||
if r.Error == nil {
|
||||
@@ -72,7 +67,7 @@ func (r *ErrorAndWarnings) Merge(other *ErrorAndWarnings) *ErrorAndWarnings {
|
||||
if len(other.Warnings) > 0 {
|
||||
r.AddWarning(other.Warnings...)
|
||||
}
|
||||
return r
|
||||
return *r
|
||||
}
|
||||
|
||||
func (r *ErrorAndWarnings) Empty() bool {
|
||||
|
||||
@@ -155,12 +155,11 @@ func (i *InitData) Init(ctx context.Context, invoker constants.Invoker, opts ...
|
||||
i.Result.AddWarnings(errorsAndWarnings.Warnings...)
|
||||
|
||||
log.Printf("[INFO] ValidateClientCacheSettings")
|
||||
if errorsAndWarnings := db_common.ValidateClientCacheSettings(client); errorsAndWarnings != nil {
|
||||
if errorsAndWarnings.GetError() != nil {
|
||||
i.Result.Error = errorsAndWarnings.GetError()
|
||||
}
|
||||
i.Result.AddWarnings(errorsAndWarnings.Warnings...)
|
||||
errorsAndWarnings = db_common.ValidateClientCacheSettings(client)
|
||||
if errorsAndWarnings.GetError() != nil {
|
||||
i.Result.Error = errorsAndWarnings.GetError()
|
||||
}
|
||||
i.Result.AddWarnings(errorsAndWarnings.Warnings...)
|
||||
|
||||
i.Client = client
|
||||
}
|
||||
@@ -190,7 +189,7 @@ func validateModRequirementsRecursively(mod *modconfig.Mod, pluginVersionMap map
|
||||
}
|
||||
|
||||
// GetDbClient either creates a DB client using the configured connection string (if present) or creates a LocalDbClient
|
||||
func GetDbClient(ctx context.Context, invoker constants.Invoker, onConnectionCallback db_client.DbConnectionCallback, opts ...db_client.ClientOption) (db_common.Client, *error_helpers.ErrorAndWarnings) {
|
||||
func GetDbClient(ctx context.Context, invoker constants.Invoker, onConnectionCallback db_client.DbConnectionCallback, opts ...db_client.ClientOption) (db_common.Client, error_helpers.ErrorAndWarnings) {
|
||||
if connectionString := viper.GetString(constants.ArgConnectionString); connectionString != "" {
|
||||
statushooks.SetStatus(ctx, "Connecting to remote Steampipe database")
|
||||
client, err := db_client.NewDbClient(ctx, connectionString, onConnectionCallback, opts...)
|
||||
|
||||
@@ -118,9 +118,7 @@ func showCacheTtl(ctx context.Context, input *HandlerInput) error {
|
||||
fmt.Println("Cache TTL is", serverTtl, "seconds.")
|
||||
}
|
||||
errorsAndWarnings := db_common.ValidateClientCacheTtl(input.Client)
|
||||
if errorsAndWarnings != nil {
|
||||
errorsAndWarnings.ShowWarnings()
|
||||
}
|
||||
errorsAndWarnings.ShowWarnings()
|
||||
// we don't know what the setting is
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ func (p *PluginVersionFile) ensureVersionFilesInPluginDirectories() error {
|
||||
}
|
||||
|
||||
// any plugins installed under the `local` folder are added to the plugin version file
|
||||
func (p *PluginVersionFile) AddLocalPlugins(ctx context.Context) *error_helpers.ErrorAndWarnings {
|
||||
func (p *PluginVersionFile) AddLocalPlugins(ctx context.Context) error_helpers.ErrorAndWarnings {
|
||||
localPlugins, err := loadLocalPlugins(ctx)
|
||||
if err != nil {
|
||||
return error_helpers.NewErrorsAndWarning(err)
|
||||
@@ -127,7 +127,7 @@ func (p *PluginVersionFile) AddLocalPlugins(ctx context.Context) *error_helpers.
|
||||
}
|
||||
p.Plugins[fmt.Sprintf("local/%s", name)] = install
|
||||
}
|
||||
return nil
|
||||
return error_helpers.EmptyErrorsAndWarning()
|
||||
}
|
||||
|
||||
// to lock plugin version file loads
|
||||
|
||||
@@ -16,7 +16,7 @@ func (m *PluginManager) SendPostgresSchemaNotification(ctx context.Context) erro
|
||||
|
||||
}
|
||||
|
||||
func (m *PluginManager) SendPostgresErrorsAndWarningsNotification(ctx context.Context, errorAndWarnings *error_helpers.ErrorAndWarnings) {
|
||||
func (m *PluginManager) SendPostgresErrorsAndWarningsNotification(ctx context.Context, errorAndWarnings error_helpers.ErrorAndWarnings) {
|
||||
if err := m.sendPostgresNotification(ctx, steampipeconfig.NewErrorsAndWarningsNotification(errorAndWarnings)); err != nil {
|
||||
|
||||
log.Printf("[WARN] failed to send error notification, error")
|
||||
|
||||
@@ -20,11 +20,11 @@ type ConnectionStateSummary map[string]int
|
||||
type ConnectionStateMap map[string]*ConnectionState
|
||||
|
||||
// GetRequiredConnectionStateMap populates a map of connection data for all connections in connectionMap
|
||||
func GetRequiredConnectionStateMap(connectionMap map[string]*modconfig.Connection, currentConnectionState ConnectionStateMap) (ConnectionStateMap, map[string][]modconfig.Connection, *error_helpers.ErrorAndWarnings) {
|
||||
func GetRequiredConnectionStateMap(connectionMap map[string]*modconfig.Connection, currentConnectionState ConnectionStateMap) (ConnectionStateMap, map[string][]modconfig.Connection, error_helpers.ErrorAndWarnings) {
|
||||
utils.LogTime("steampipeconfig.GetRequiredConnectionStateMap start")
|
||||
defer utils.LogTime("steampipeconfig.GetRequiredConnectionStateMap end")
|
||||
|
||||
var res = &error_helpers.ErrorAndWarnings{}
|
||||
var res = error_helpers.ErrorAndWarnings{}
|
||||
requiredState := ConnectionStateMap{}
|
||||
|
||||
// cache plugin file creation times in a dictionary to avoid reloading the same plugin file multiple times
|
||||
|
||||
@@ -32,7 +32,7 @@ var defaultConfigFileName = "default.spc"
|
||||
var defaultConfigSampleFileName = "default.spc.sample"
|
||||
|
||||
// LoadSteampipeConfig loads the HCL connection config and workspace options
|
||||
func LoadSteampipeConfig(ctx context.Context, modLocation string, commandName string) (*SteampipeConfig, *error_helpers.ErrorAndWarnings) {
|
||||
func LoadSteampipeConfig(ctx context.Context, modLocation string, commandName string) (*SteampipeConfig, error_helpers.ErrorAndWarnings) {
|
||||
utils.LogTime("steampipeconfig.LoadSteampipeConfig start")
|
||||
defer utils.LogTime("steampipeconfig.LoadSteampipeConfig end")
|
||||
|
||||
@@ -51,7 +51,7 @@ func LoadSteampipeConfig(ctx context.Context, modLocation string, commandName st
|
||||
|
||||
// LoadConnectionConfig loads the connection config but not the workspace options
|
||||
// this is called by the fdw
|
||||
func LoadConnectionConfig(ctx context.Context) (*SteampipeConfig, *error_helpers.ErrorAndWarnings) {
|
||||
func LoadConnectionConfig(ctx context.Context) (*SteampipeConfig, error_helpers.ErrorAndWarnings) {
|
||||
return LoadSteampipeConfig(ctx, "", "")
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ func ensureDefaultConfigFile(configFolder string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadSteampipeConfig(ctx context.Context, modLocation string, commandName string) (steampipeConfig *SteampipeConfig, errorsAndWarnings *error_helpers.ErrorAndWarnings) {
|
||||
func loadSteampipeConfig(ctx context.Context, modLocation string, commandName string) (steampipeConfig *SteampipeConfig, errorsAndWarnings error_helpers.ErrorAndWarnings) {
|
||||
utils.LogTime("steampipeconfig.loadSteampipeConfig start")
|
||||
defer utils.LogTime("steampipeconfig.loadSteampipeConfig end")
|
||||
|
||||
@@ -140,7 +140,7 @@ func loadSteampipeConfig(ctx context.Context, modLocation string, commandName st
|
||||
|
||||
// add any "local" plugins (i.e. plugins installed under the 'local' folder) into the version file
|
||||
ew := v.AddLocalPlugins(ctx)
|
||||
if ew != nil && ew.GetError() != nil {
|
||||
if ew.GetError() != nil {
|
||||
return nil, ew
|
||||
}
|
||||
steampipeConfig.PluginVersions = v.Plugins
|
||||
@@ -148,13 +148,12 @@ func loadSteampipeConfig(ctx context.Context, modLocation string, commandName st
|
||||
// load config from the installation folder - load all spc files from config directory
|
||||
include := filehelpers.InclusionsFromExtensions(constants.ConnectionConfigExtensions)
|
||||
loadOptions := &loadConfigOptions{include: include}
|
||||
if ew := loadConfig(ctx, filepaths.EnsureConfigDir(), steampipeConfig, loadOptions); ew != nil {
|
||||
if ew.GetError() != nil {
|
||||
return nil, ew
|
||||
}
|
||||
// merge the warning from this call
|
||||
errorsAndWarnings.AddWarning(ew.Warnings...)
|
||||
ew = loadConfig(ctx, filepaths.EnsureConfigDir(), steampipeConfig, loadOptions)
|
||||
if ew.GetError() != nil {
|
||||
return nil, ew
|
||||
}
|
||||
// merge the warning from this call
|
||||
errorsAndWarnings.AddWarning(ew.Warnings...)
|
||||
|
||||
// now load config from the workspace folder, if provided
|
||||
// this has precedence and so will overwrite any config which has already been set
|
||||
@@ -168,14 +167,13 @@ func loadSteampipeConfig(ctx context.Context, modLocation string, commandName st
|
||||
include = filehelpers.InclusionsFromFiles([]string{filepaths.WorkspaceConfigFileName})
|
||||
// update load options to ONLY allow terminal options
|
||||
loadOptions = &loadConfigOptions{include: include, allowedOptions: []string{options.TerminalBlock}}
|
||||
if ew := loadConfig(ctx, modLocation, steampipeConfig, loadOptions); ew != nil {
|
||||
if ew.GetError() != nil {
|
||||
return nil, ew.WrapErrorWithMessage("failed to load workspace config")
|
||||
}
|
||||
|
||||
// merge the warning from this call
|
||||
errorsAndWarnings.AddWarning(ew.Warnings...)
|
||||
ew := loadConfig(ctx, modLocation, steampipeConfig, loadOptions)
|
||||
if ew.GetError() != nil {
|
||||
return nil, ew.WrapErrorWithMessage("failed to load workspace config")
|
||||
}
|
||||
|
||||
// merge the warning from this call
|
||||
errorsAndWarnings.AddWarning(ew.Warnings...)
|
||||
}
|
||||
|
||||
// now set default options on all connections without options set
|
||||
@@ -223,7 +221,7 @@ type loadConfigOptions struct {
|
||||
allowedOptions []string
|
||||
}
|
||||
|
||||
func loadConfig(ctx context.Context, configFolder string, steampipeConfig *SteampipeConfig, opts *loadConfigOptions) *error_helpers.ErrorAndWarnings {
|
||||
func loadConfig(ctx context.Context, configFolder string, steampipeConfig *SteampipeConfig, opts *loadConfigOptions) error_helpers.ErrorAndWarnings {
|
||||
log.Printf("[INFO] loadConfig is loading connection config")
|
||||
// get all the config files in the directory
|
||||
configPaths, err := filehelpers.ListFilesWithContext(ctx, configFolder, &filehelpers.ListOptions{
|
||||
@@ -236,7 +234,7 @@ func loadConfig(ctx context.Context, configFolder string, steampipeConfig *Steam
|
||||
return error_helpers.NewErrorsAndWarning(err)
|
||||
}
|
||||
if len(configPaths) == 0 {
|
||||
return nil
|
||||
return error_helpers.ErrorAndWarnings{}
|
||||
}
|
||||
|
||||
fileData, diags := parse.LoadFileData(configPaths...)
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
// if CreatePseudoResources flag is set, construct hcl resources for files with specific extensions
|
||||
// NOTE: it is an error if there is more than 1 mod defined, however zero mods is acceptable
|
||||
// - a default mod will be created assuming there are any resource files
|
||||
func LoadMod(ctx context.Context, modPath string, parseCtx *parse.ModParseContext) (mod *modconfig.Mod, errorsAndWarnings *error_helpers.ErrorAndWarnings) {
|
||||
func LoadMod(ctx context.Context, modPath string, parseCtx *parse.ModParseContext) (mod *modconfig.Mod, errorsAndWarnings error_helpers.ErrorAndWarnings) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
errorsAndWarnings = error_helpers.NewErrorsAndWarning(helpers.ToError(r))
|
||||
@@ -59,8 +59,8 @@ func LoadMod(ctx context.Context, modPath string, parseCtx *parse.ModParseContex
|
||||
return mod, errorsAndWarnings
|
||||
}
|
||||
|
||||
func loadModDefinition(ctx context.Context, modPath string, parseCtx *parse.ModParseContext) (mod *modconfig.Mod, errorsAndWarnings *error_helpers.ErrorAndWarnings) {
|
||||
errorsAndWarnings = &error_helpers.ErrorAndWarnings{}
|
||||
func loadModDefinition(ctx context.Context, modPath string, parseCtx *parse.ModParseContext) (mod *modconfig.Mod, errorsAndWarnings error_helpers.ErrorAndWarnings) {
|
||||
errorsAndWarnings = error_helpers.ErrorAndWarnings{}
|
||||
// verify the mod folder exists
|
||||
_, err := os.Stat(modPath)
|
||||
if os.IsNotExist(err) {
|
||||
@@ -153,7 +153,7 @@ func loadModDependency(ctx context.Context, modDependency *versionmap.ResolvedVe
|
||||
|
||||
}
|
||||
|
||||
func loadModResources(ctx context.Context, mod *modconfig.Mod, parseCtx *parse.ModParseContext) (*modconfig.Mod, *error_helpers.ErrorAndWarnings) {
|
||||
func loadModResources(ctx context.Context, mod *modconfig.Mod, parseCtx *parse.ModParseContext) (*modconfig.Mod, error_helpers.ErrorAndWarnings) {
|
||||
// if flag is set, create pseudo resources by mapping files
|
||||
var pseudoResources []modconfig.MappableResource
|
||||
var err error
|
||||
|
||||
@@ -32,7 +32,7 @@ func LoadVariableDefinitions(ctx context.Context, variablePath string, parseCtx
|
||||
return variableMap, nil
|
||||
}
|
||||
|
||||
func GetVariableValues(parseCtx *parse.ModParseContext, variableMap *modconfig.ModVariableMap, validate bool) (*modconfig.ModVariableMap, *error_helpers.ErrorAndWarnings) {
|
||||
func GetVariableValues(parseCtx *parse.ModParseContext, variableMap *modconfig.ModVariableMap, validate bool) (*modconfig.ModVariableMap, error_helpers.ErrorAndWarnings) {
|
||||
log.Printf("[INFO] GetVariableValues")
|
||||
// now resolve all input variables
|
||||
inputValues, errorsAndWarnings := getInputVariables(parseCtx, variableMap, validate)
|
||||
@@ -44,7 +44,7 @@ func GetVariableValues(parseCtx *parse.ModParseContext, variableMap *modconfig.M
|
||||
return variableMap, errorsAndWarnings
|
||||
}
|
||||
|
||||
func getInputVariables(parseCtx *parse.ModParseContext, variableMap *modconfig.ModVariableMap, validate bool) (inputvars.InputValues, *error_helpers.ErrorAndWarnings) {
|
||||
func getInputVariables(parseCtx *parse.ModParseContext, variableMap *modconfig.ModVariableMap, validate bool) (inputvars.InputValues, error_helpers.ErrorAndWarnings) {
|
||||
variableFileArgs := viper.GetStringSlice(constants.ArgVarFile)
|
||||
variableArgs := viper.GetStringSlice(constants.ArgVariable)
|
||||
|
||||
@@ -87,7 +87,7 @@ func getInputVariables(parseCtx *parse.ModParseContext, variableMap *modconfig.M
|
||||
return parsedValues, newVariableValidationResult(diags)
|
||||
}
|
||||
|
||||
func newVariableValidationResult(diags tfdiags.Diagnostics) *error_helpers.ErrorAndWarnings {
|
||||
func newVariableValidationResult(diags tfdiags.Diagnostics) error_helpers.ErrorAndWarnings {
|
||||
warnings := plugin.DiagsToWarnings(diags.ToHCL())
|
||||
var err error
|
||||
if diags.HasErrors() {
|
||||
|
||||
@@ -97,7 +97,7 @@ func ParseModDefinition(modFilePath string, evalCtx *hcl.EvalContext) (*modconfi
|
||||
|
||||
// ParseMod parses all source hcl files for the mod path and associated resources, and returns the mod object
|
||||
// NOTE: the mod definition has already been parsed (or a default created) and is in opts.RunCtx.RootMod
|
||||
func ParseMod(ctx context.Context, fileData map[string][]byte, pseudoResources []modconfig.MappableResource, parseCtx *ModParseContext) (*modconfig.Mod, *error_helpers.ErrorAndWarnings) {
|
||||
func ParseMod(ctx context.Context, fileData map[string][]byte, pseudoResources []modconfig.MappableResource, parseCtx *ModParseContext) (*modconfig.Mod, error_helpers.ErrorAndWarnings) {
|
||||
body, diags := ParseHclFiles(fileData)
|
||||
if diags.HasErrors() {
|
||||
return nil, error_helpers.NewErrorsAndWarning(plugin.DiagsToError("Failed to load all mod source files", diags))
|
||||
@@ -129,7 +129,7 @@ func ParseMod(ctx context.Context, fileData map[string][]byte, pseudoResources [
|
||||
}
|
||||
|
||||
// collect warnings as we parse
|
||||
var res = &error_helpers.ErrorAndWarnings{}
|
||||
var res = error_helpers.ErrorAndWarnings{}
|
||||
|
||||
// add pseudo resources to the mod
|
||||
errorsAndWarnings := addPseudoResourcesToMod(pseudoResources, hclResources, mod)
|
||||
|
||||
@@ -129,7 +129,7 @@ func parseYamlFile(filename string) (*hcl.File, hcl.Diagnostics) {
|
||||
return json.Parse(jsonData, filename)
|
||||
}
|
||||
|
||||
func addPseudoResourcesToMod(pseudoResources []modconfig.MappableResource, hclResources map[string]bool, mod *modconfig.Mod) *error_helpers.ErrorAndWarnings {
|
||||
func addPseudoResourcesToMod(pseudoResources []modconfig.MappableResource, hclResources map[string]bool, mod *modconfig.Mod) error_helpers.ErrorAndWarnings {
|
||||
res := error_helpers.EmptyErrorsAndWarning()
|
||||
for _, r := range pseudoResources {
|
||||
// is there a hcl resource with the same name as this pseudo resource - it takes precedence
|
||||
|
||||
@@ -31,7 +31,7 @@ func NewSchemaUpdateNotification() *PostgresNotification {
|
||||
}
|
||||
}
|
||||
|
||||
func NewErrorsAndWarningsNotification(errorAndWarnings *error_helpers.ErrorAndWarnings) *ErrorsAndWarningsNotification {
|
||||
func NewErrorsAndWarningsNotification(errorAndWarnings error_helpers.ErrorAndWarnings) *ErrorsAndWarningsNotification {
|
||||
res := &ErrorsAndWarningsNotification{
|
||||
PostgresNotification: PostgresNotification{
|
||||
StructVersion: PostgresNotificationStructVersion,
|
||||
|
||||
@@ -16,7 +16,7 @@ type RefreshConnectionResult struct {
|
||||
}
|
||||
|
||||
func NewErrorRefreshConnectionResult(err error) *RefreshConnectionResult {
|
||||
return &RefreshConnectionResult{ErrorAndWarnings: *error_helpers.NewErrorsAndWarning(err)}
|
||||
return &RefreshConnectionResult{ErrorAndWarnings: error_helpers.NewErrorsAndWarning(err)}
|
||||
}
|
||||
|
||||
func (r *RefreshConnectionResult) Merge(other *RefreshConnectionResult) {
|
||||
|
||||
@@ -95,7 +95,7 @@ func (c *SteampipeConfig) ConfigMap() map[string]interface{} {
|
||||
return res
|
||||
}
|
||||
|
||||
func (c *SteampipeConfig) SetOptions(opts options.Options) (errorsAndWarnings *error_helpers.ErrorAndWarnings) {
|
||||
func (c *SteampipeConfig) SetOptions(opts options.Options) (errorsAndWarnings error_helpers.ErrorAndWarnings) {
|
||||
errorsAndWarnings = error_helpers.NewErrorsAndWarning(nil)
|
||||
|
||||
switch o := opts.(type) {
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/turbot/terraform-components/terraform"
|
||||
)
|
||||
|
||||
func LoadWorkspacePromptingForVariables(ctx context.Context) (*Workspace, *error_helpers.ErrorAndWarnings) {
|
||||
func LoadWorkspacePromptingForVariables(ctx context.Context) (*Workspace, error_helpers.ErrorAndWarnings) {
|
||||
t := time.Now()
|
||||
defer func() {
|
||||
log.Printf("[TRACE] Workspace load took %dms\n", time.Since(t).Milliseconds())
|
||||
|
||||
@@ -68,7 +68,7 @@ type Workspace struct {
|
||||
}
|
||||
|
||||
// LoadWorkspaceVars creates a Workspace and loads the variables
|
||||
func LoadWorkspaceVars(ctx context.Context) (*Workspace, *modconfig.ModVariableMap, *error_helpers.ErrorAndWarnings) {
|
||||
func LoadWorkspaceVars(ctx context.Context) (*Workspace, *modconfig.ModVariableMap, error_helpers.ErrorAndWarnings) {
|
||||
log.Printf("[INFO] LoadWorkspaceVars: creating workspace, loading variable and resolving variable values")
|
||||
workspacePath := viper.GetString(constants.ArgModLocation)
|
||||
|
||||
@@ -99,7 +99,7 @@ func LoadWorkspaceVars(ctx context.Context) (*Workspace, *modconfig.ModVariableM
|
||||
|
||||
// LoadVariables creates a Workspace and uses it to load all variables, ignoring any value resolution errors
|
||||
// this is use for the variable list command
|
||||
func LoadVariables(ctx context.Context, workspacePath string) ([]*modconfig.Variable, *error_helpers.ErrorAndWarnings) {
|
||||
func LoadVariables(ctx context.Context, workspacePath string) ([]*modconfig.Variable, error_helpers.ErrorAndWarnings) {
|
||||
utils.LogTime("workspace.LoadVariables start")
|
||||
defer utils.LogTime("workspace.LoadVariables end")
|
||||
|
||||
@@ -310,8 +310,8 @@ func HomeDirectoryModfileCheck(ctx context.Context, workspacePath string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *Workspace) LoadWorkspaceMod(ctx context.Context, inputVariables *modconfig.ModVariableMap) *error_helpers.ErrorAndWarnings {
|
||||
var errorsAndWarnings = &error_helpers.ErrorAndWarnings{}
|
||||
func (w *Workspace) LoadWorkspaceMod(ctx context.Context, inputVariables *modconfig.ModVariableMap) error_helpers.ErrorAndWarnings {
|
||||
var errorsAndWarnings = error_helpers.ErrorAndWarnings{}
|
||||
|
||||
// build run context which we use to load the workspace
|
||||
parseCtx, err := w.getParseContext(ctx, inputVariables)
|
||||
@@ -345,7 +345,7 @@ func (w *Workspace) LoadWorkspaceMod(ctx context.Context, inputVariables *modcon
|
||||
return errorsAndWarnings
|
||||
}
|
||||
|
||||
func (w *Workspace) PopulateVariables(ctx context.Context) (*modconfig.ModVariableMap, *error_helpers.ErrorAndWarnings) {
|
||||
func (w *Workspace) PopulateVariables(ctx context.Context) (*modconfig.ModVariableMap, error_helpers.ErrorAndWarnings) {
|
||||
log.Printf("[TRACE] Workspace.PopulateVariables")
|
||||
// resolve values of all input variables
|
||||
// we WILL validate missing variables when loading
|
||||
@@ -388,7 +388,7 @@ func (w *Workspace) PopulateVariables(ctx context.Context) (*modconfig.ModVariab
|
||||
return inputVariables, errorsAndWarnings
|
||||
}
|
||||
|
||||
func (w *Workspace) getInputVariables(ctx context.Context, validateMissing bool) (*modconfig.ModVariableMap, *error_helpers.ErrorAndWarnings) {
|
||||
func (w *Workspace) getInputVariables(ctx context.Context, validateMissing bool) (*modconfig.ModVariableMap, error_helpers.ErrorAndWarnings) {
|
||||
log.Printf("[TRACE] Workspace.getInputVariables")
|
||||
// build a run context just to use to load variable definitions
|
||||
variablesParseCtx, err := w.getParseContext(ctx, nil)
|
||||
|
||||
@@ -115,7 +115,7 @@ func (w *Workspace) onNewIntrospectionData(ctx context.Context, client db_common
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Workspace) reloadResourceMaps(ctx context.Context) (_ *modconfig.ResourceMaps, _ *modconfig.ResourceMaps, errAndWarnings *error_helpers.ErrorAndWarnings) {
|
||||
func (w *Workspace) reloadResourceMaps(ctx context.Context) (_ *modconfig.ResourceMaps, _ *modconfig.ResourceMaps, errAndWarnings error_helpers.ErrorAndWarnings) {
|
||||
w.loadLock.Lock()
|
||||
defer w.loadLock.Unlock()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user