Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecation for database workspace property and env var #512

Merged
merged 1 commit into from
Oct 21, 2024
Merged
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
2 changes: 1 addition & 1 deletion internal/cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func checkCmd[T controlinit.CheckTarget]() *cobra.Command {
builder.
AddCloudFlags().
AddModLocationFlag().
AddStringFlag(constants.ArgDatabase, "", "Turbot Pipes workspace database", cmdconfig.FlagOptions.Deprecated("use a variable or param")).
AddStringFlag(constants.ArgDatabase, "", "Turbot Pipes workspace database", cmdconfig.FlagOptions.Deprecated("use a variable if the mod supports it")).
AddBoolFlag(constants.ArgHeader, true, "Include column headers for csv and table output").
AddBoolFlag(constants.ArgHelp, false, "Help for run command", cmdconfig.FlagOptions.WithShortHand("h")).
AddBoolFlag(constants.ArgInput, true, "Enable interactive prompts").
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The current mod is the working directory, or the directory specified by the --mo
AddModLocationFlag().
AddStringArrayFlag(constants.ArgArg, nil, "Specify the value of a dashboard argument").
AddStringSliceFlag(constants.ArgExport, nil, "Export output to file, supported format: pps (snapshot)").
AddStringFlag(constants.ArgDatabase, "", "Turbot Pipes workspace database", cmdconfig.FlagOptions.Deprecated("use a variable or param")).
AddStringFlag(constants.ArgDatabase, "", "Turbot Pipes workspace database", cmdconfig.FlagOptions.Deprecated("use a variable if the mod supports it")).
AddIntFlag(constants.ArgDatabaseQueryTimeout, localconstants.DatabaseDefaultQueryTimeout, "The query timeout").
AddBoolFlag(constants.ArgHelp, false, "Help for dashboard", cmdconfig.FlagOptions.WithShortHand("h")).
AddBoolFlag(constants.ArgInput, true, "Enable interactive prompts").
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Examples:

cmdconfig.OnCmd(cmd).
AddBoolFlag(constants.ArgDryRun, false, "Show which mods would be installed/updated/uninstalled without modifying them").
AddStringFlag(constants.ArgDatabase, "", "Turbot Pipes workspace database", cmdconfig.FlagOptions.Deprecated("use a variable or param")).
AddStringFlag(constants.ArgDatabase, "", "Turbot Pipes workspace database", cmdconfig.FlagOptions.Deprecated("use a variable if the mod supports it")).
AddBoolFlag(constants.ArgForce, false, "Install mods even if plugin/cli version requirements are not met (cannot be used with --dry-run)").
AddBoolFlag(constants.ArgHelp, false, "Help for install", cmdconfig.FlagOptions.WithShortHand("h")).
AddBoolFlag(constants.ArgPrune, true, "Remove unused dependencies after installation is complete").
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The current mod is the working directory, or the directory specified by the --mo
// NOTE: use StringArrayFlag for ArgQueryInput, not StringSliceFlag
// Cobra will interpret values passed to a StringSliceFlag as CSV, where args passed to StringArrayFlag are not parsed and used raw
AddStringArrayFlag(constants.ArgArg, nil, "Specify the value of a query argument").
AddStringFlag(constants.ArgDatabase, "", "Turbot Pipes workspace database", cmdconfig.FlagOptions.Deprecated("use a variable or param")).
AddStringFlag(constants.ArgDatabase, "", "Turbot Pipes workspace database", cmdconfig.FlagOptions.Deprecated("use a variable if the mod supports it")).
AddIntFlag(constants.ArgDatabaseQueryTimeout, localconstants.DatabaseDefaultQueryTimeout, "The query timeout").
AddStringSliceFlag(constants.ArgExport, nil, "Export output to file, supported formats: csv, html, json, md, nunit3, pps (snapshot), asff").
AddBoolFlag(constants.ArgHeader, true, "Include column headers for csv and table output").
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func serverCmd() *cobra.Command {
Args: cobra.NoArgs,
Run: runServerCmd,
Short: "Start Powerpipe dashboard server",
Long: `Run the Powerpipe server, including the dashbaord server and the API.
Long: `Run the Powerpipe server, including the dashboard server and the API.
Powerpipe server runs in the foreground; Press Ctrl-C to exit.`,
}
Expand All @@ -43,7 +43,7 @@ Powerpipe server runs in the foreground; Press Ctrl-C to exit.`,
AddStringFlag(constants.ArgListen, string(dashboardserver.ListenTypeLocal), "Accept connections from local (localhost only) or network (all interfaces / IP addresses)").
AddStringArrayFlag(constants.ArgVariable, []string{}, "Specify the value of a variable. Multiple --var arguments may be passed.").
AddStringFlag(constants.ArgVarFile, "", "Specify a .ppvar file containing variable values.").
AddStringFlag(constants.ArgDatabase, "", "Turbot Pipes workspace database", cmdconfig.FlagOptions.Deprecated("use a variable or param")).
AddStringFlag(constants.ArgDatabase, "", "Turbot Pipes workspace database", cmdconfig.FlagOptions.Deprecated("use a variable if the mod supports it")).
AddIntFlag(constants.ArgDashboardTimeout, 0, "Set a the dashboard execution timeout")

return cmd
Expand Down
17 changes: 13 additions & 4 deletions internal/cmdconfig/cmd_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func initGlobalConfig() error_helpers.ErrorAndWarnings {
}

// now validate all config values have appropriate values
return validateConfig()
return validateConfig(loader.GetActiveWorkspaceProfile())
}

func setPipesTokenDefault(loader *parse.WorkspaceProfileLoader[*workspace_profile.PowerpipeWorkspaceProfile]) error {
Expand Down Expand Up @@ -209,9 +209,8 @@ func setPipesTokenDefault(loader *parse.WorkspaceProfileLoader[*workspace_profil
return nil
}

// now validate config values have appropriate values
// (currently validates telemetry)
func validateConfig() error_helpers.ErrorAndWarnings {
// now validate config values have appropriate values
func validateConfig(activeWorkspace *workspace_profile.PowerpipeWorkspaceProfile) error_helpers.ErrorAndWarnings {
var res = error_helpers.ErrorAndWarnings{}
telemetry := viper.GetString(constants.ArgTelemetry)
if !helpers.StringSliceContains(constants.TelemetryLevels, telemetry) {
Expand All @@ -221,6 +220,16 @@ func validateConfig() error_helpers.ErrorAndWarnings {
if _, legacyDiagnosticsSet := os.LookupEnv(plugin.EnvLegacyDiagnosticsLevel); legacyDiagnosticsSet {
res.AddWarning(fmt.Sprintf("Environment variable %s is deprecated - use %s", plugin.EnvLegacyDiagnosticsLevel, plugin.EnvDiagnosticsLevel))
}

// database deprecation warnings
if _, dbEnvSet := os.LookupEnv(app_specific.EnvDatabase); dbEnvSet {
res.AddWarning(fmt.Sprintf("Environment variable %s is deprecated- use a variable if the mod supports it", app_specific.EnvDatabase))
}
// check active workspace profile
if activeWorkspace != nil && activeWorkspace.Database != nil {
res.AddWarning(fmt.Sprintf("workspace property 'database' is deprecated - use a variable if the mod supports it (%s:%d-%d)", activeWorkspace.DeclRange.Filename, activeWorkspace.DeclRange.Start.Line, activeWorkspace.DeclRange.End.Line))
}

res.Error = plugin.ValidateDiagnosticsEnvVar()

return res
Expand Down
2 changes: 1 addition & 1 deletion internal/powerpipeconfig/powerpipe_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type PowerpipeConfig struct {

loadLock *sync.Mutex
DefaultConnection connection.ConnectionStringProvider
// cache the conneciton strings for cloud workspaces (is this ok???
// cache the connection strings for cloud workspaces (is this ok???
cloudConnectionStrings map[string]string
// lock
cloudConnectionStringLock *sync.RWMutex
Expand Down
Loading