mirror of
https://github.com/turbot/steampipe.git
synced 2025-12-19 18:12:43 -05:00
compiles but needs testing
This commit is contained in:
@@ -2,12 +2,12 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/turbot/pipe-fittings/constants"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/turbot/steampipe/pkg/cmdconfig"
|
||||
"github.com/turbot/steampipe/pkg/constants"
|
||||
)
|
||||
|
||||
func generateCompletionScriptsCmd() *cobra.Command {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
constants2 "github.com/turbot/pipe-fittings/constants"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
@@ -28,7 +29,7 @@ func loginCmd() *cobra.Command {
|
||||
|
||||
cmdconfig.OnCmd(cmd).
|
||||
AddCloudFlags().
|
||||
AddBoolFlag(constants.ArgHelp, false, "Help for dashboard", cmdconfig.FlagOptions.WithShortHand("h"))
|
||||
AddBoolFlag(constants2.ArgHelp, false, "Help for dashboard", cmdconfig.FlagOptions.WithShortHand("h"))
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -36,7 +37,7 @@ func loginCmd() *cobra.Command {
|
||||
func runLoginCmd(cmd *cobra.Command, _ []string) {
|
||||
ctx := cmd.Context()
|
||||
|
||||
log.Printf("[TRACE] login, pipes host %s", viper.Get(constants.ArgPipesHost))
|
||||
log.Printf("[TRACE] login, pipes host %s", viper.Get(constants2.ArgPipesHost))
|
||||
log.Printf("[TRACE] opening login web page")
|
||||
// start login flow - this will open a web page prompting user to login, and will give the user a code to enter
|
||||
var id, err = cloud.WebLogin(ctx)
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/turbot/steampipe/pkg/ociinstaller"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -14,10 +13,11 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/turbot/go-kit/helpers"
|
||||
pconstants "github.com/turbot/pipe-fittings/constants"
|
||||
perror_helpers "github.com/turbot/pipe-fittings/error_helpers"
|
||||
putils "github.com/turbot/pipe-fittings/ociinstaller"
|
||||
"github.com/turbot/pipe-fittings/ociinstaller/versionfile"
|
||||
"github.com/turbot/pipe-fittings/plugin"
|
||||
pplugin "github.com/turbot/pipe-fittings/plugin"
|
||||
"github.com/turbot/pipe-fittings/utils"
|
||||
"github.com/turbot/steampipe-plugin-sdk/v5/sperr"
|
||||
"github.com/turbot/steampipe/pkg/cmdconfig"
|
||||
@@ -27,6 +27,8 @@ import (
|
||||
"github.com/turbot/steampipe/pkg/display"
|
||||
"github.com/turbot/steampipe/pkg/error_helpers"
|
||||
"github.com/turbot/steampipe/pkg/installationstate"
|
||||
"github.com/turbot/steampipe/pkg/ociinstaller"
|
||||
"github.com/turbot/steampipe/pkg/plugin"
|
||||
"github.com/turbot/steampipe/pkg/statushooks"
|
||||
"github.com/turbot/steampipe/pkg/steampipeconfig"
|
||||
)
|
||||
@@ -76,14 +78,14 @@ Examples:
|
||||
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
||||
utils.LogTime("cmd.plugin.PersistentPostRun start")
|
||||
defer utils.LogTime("cmd.plugin.PersistentPostRun end")
|
||||
plugin.CleanupOldTmpDirs(cmd.Context())
|
||||
pplugin.CleanupOldTmpDirs(cmd.Context())
|
||||
},
|
||||
}
|
||||
cmd.AddCommand(pluginInstallCmd())
|
||||
cmd.AddCommand(pluginListCmd())
|
||||
cmd.AddCommand(pluginUninstallCmd())
|
||||
cmd.AddCommand(pluginUpdateCmd())
|
||||
cmd.Flags().BoolP(constants.ArgHelp, "h", false, "Help for plugin")
|
||||
cmd.Flags().BoolP(pconstants.ArgHelp, "h", false, "Help for plugin")
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -122,9 +124,9 @@ Examples:
|
||||
|
||||
cmdconfig.
|
||||
OnCmd(cmd).
|
||||
AddBoolFlag(constants.ArgProgress, true, "Display installation progress").
|
||||
AddBoolFlag(constants.ArgSkipConfig, false, "Skip creating the default config file for plugin").
|
||||
AddBoolFlag(constants.ArgHelp, false, "Help for plugin install", cmdconfig.FlagOptions.WithShortHand("h"))
|
||||
AddBoolFlag(pconstants.ArgProgress, true, "Display installation progress").
|
||||
AddBoolFlag(pconstants.ArgSkipConfig, false, "Skip creating the default config file for plugin").
|
||||
AddBoolFlag(pconstants.ArgHelp, false, "Help for plugin install", cmdconfig.FlagOptions.WithShortHand("h"))
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -156,9 +158,9 @@ Examples:
|
||||
|
||||
cmdconfig.
|
||||
OnCmd(cmd).
|
||||
AddBoolFlag(constants.ArgAll, false, "Update all plugins to its latest available version").
|
||||
AddBoolFlag(constants.ArgProgress, true, "Display installation progress").
|
||||
AddBoolFlag(constants.ArgHelp, false, "Help for plugin update", cmdconfig.FlagOptions.WithShortHand("h"))
|
||||
AddBoolFlag(pconstants.ArgAll, false, "Update all plugins to its latest available version").
|
||||
AddBoolFlag(pconstants.ArgProgress, true, "Display installation progress").
|
||||
AddBoolFlag(pconstants.ArgHelp, false, "Help for plugin update", cmdconfig.FlagOptions.WithShortHand("h"))
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -189,8 +191,8 @@ Examples:
|
||||
cmdconfig.
|
||||
OnCmd(cmd).
|
||||
AddBoolFlag("outdated", false, "Check each plugin in the list for updates").
|
||||
AddStringFlag(constants.ArgOutput, "table", "Output format: table or json").
|
||||
AddBoolFlag(constants.ArgHelp, false, "Help for plugin list", cmdconfig.FlagOptions.WithShortHand("h"))
|
||||
AddStringFlag(pconstants.ArgOutput, "table", "Output format: table or json").
|
||||
AddBoolFlag(pconstants.ArgHelp, false, "Help for plugin list", cmdconfig.FlagOptions.WithShortHand("h"))
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -216,7 +218,7 @@ Example:
|
||||
}
|
||||
|
||||
cmdconfig.OnCmd(cmd).
|
||||
AddBoolFlag(constants.ArgHelp, false, "Help for plugin uninstall", cmdconfig.FlagOptions.WithShortHand("h"))
|
||||
AddBoolFlag(pconstants.ArgHelp, false, "Help for plugin uninstall", cmdconfig.FlagOptions.WithShortHand("h"))
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -249,7 +251,7 @@ func runPluginInstallCmd(cmd *cobra.Command, args []string) {
|
||||
// - aws@^0.118
|
||||
// - ghcr.io/turbot/steampipe/plugins/turbot/aws:1.0.0
|
||||
plugins := append([]string{}, args...)
|
||||
showProgress := viper.GetBool(constants.ArgProgress)
|
||||
showProgress := viper.GetBool(pconstants.ArgProgress)
|
||||
installReports := make(display.PluginInstallReports, 0, len(plugins))
|
||||
|
||||
if len(plugins) == 0 {
|
||||
@@ -289,14 +291,14 @@ func runPluginInstallCmd(cmd *cobra.Command, args []string) {
|
||||
ref := putils.NewImageRef(pluginName)
|
||||
org, name, constraint := ref.GetOrgNameAndStream()
|
||||
orgAndName := fmt.Sprintf("%s/%s", org, name)
|
||||
var resolved plugin.ResolvedPluginVersion
|
||||
var resolved pplugin.ResolvedPluginVersion
|
||||
if ref.IsFromTurbotHub() {
|
||||
rpv, err := plugin.GetLatestPluginVersionByConstraint(ctx, state.InstallationID, org, name, constraint)
|
||||
rpv, err := pplugin.GetLatestPluginVersionByConstraint(ctx, state.InstallationID, org, name, constraint)
|
||||
if err != nil || rpv == nil {
|
||||
report := &display.PluginInstallReport{
|
||||
Plugin: pluginName,
|
||||
Skipped: true,
|
||||
SkipReason: constants.InstallMessagePluginNotFound,
|
||||
SkipReason: pconstants.InstallMessagePluginNotFound,
|
||||
IsUpdateReport: false,
|
||||
}
|
||||
reportChannel <- report
|
||||
@@ -305,7 +307,7 @@ func runPluginInstallCmd(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
resolved = *rpv
|
||||
} else {
|
||||
resolved = plugin.NewResolvedPluginVersion(orgAndName, constraint, constraint)
|
||||
resolved = pplugin.NewResolvedPluginVersion(orgAndName, constraint, constraint)
|
||||
}
|
||||
|
||||
go doPluginInstall(ctx, bar, pluginName, resolved, installWaitGroup, reportChannel)
|
||||
@@ -332,7 +334,7 @@ func runPluginInstallCmd(cmd *cobra.Command, args []string) {
|
||||
|
||||
// reload the config, since an installation should have created a new config file
|
||||
var cmd = viper.Get(constants.ConfigKeyActiveCommand).(*cobra.Command)
|
||||
config, errorsAndWarnings := steampipeconfig.LoadSteampipeConfig(ctx, viper.GetString(constants.ArgModLocation), cmd.Name())
|
||||
config, errorsAndWarnings := steampipeconfig.LoadSteampipeConfig(ctx, viper.GetString(pconstants.ArgModLocation), cmd.Name())
|
||||
if errorsAndWarnings.GetError() != nil {
|
||||
error_helpers.ShowWarning(fmt.Sprintf("Failed to reload config - install report may be incomplete (%s)", errorsAndWarnings.GetError()))
|
||||
} else {
|
||||
@@ -347,29 +349,29 @@ func runPluginInstallCmd(cmd *cobra.Command, args []string) {
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
func doPluginInstall(ctx context.Context, bar *uiprogress.Bar, pluginName string, resolvedPlugin plugin.ResolvedPluginVersion, wg *sync.WaitGroup, returnChannel chan *display.PluginInstallReport) {
|
||||
func doPluginInstall(ctx context.Context, bar *uiprogress.Bar, pluginName string, resolvedPlugin pplugin.ResolvedPluginVersion, wg *sync.WaitGroup, returnChannel chan *display.PluginInstallReport) {
|
||||
var report *display.PluginInstallReport
|
||||
|
||||
pluginAlreadyInstalled, _ := plugin.Exists(ctx, pluginName)
|
||||
pluginAlreadyInstalled, _ := pplugin.Exists(ctx, pluginName)
|
||||
if pluginAlreadyInstalled {
|
||||
// set the bar to MAX
|
||||
//nolint:golint,errcheck // the error happens if we set this over the max value
|
||||
bar.Set(len(pluginInstallSteps))
|
||||
// let the bar append itself with "Already Installed"
|
||||
bar.AppendFunc(func(b *uiprogress.Bar) string {
|
||||
return helpers.Resize(constants.InstallMessagePluginAlreadyInstalled, 20)
|
||||
return helpers.Resize(pconstants.InstallMessagePluginAlreadyInstalled, 20)
|
||||
})
|
||||
report = &display.PluginInstallReport{
|
||||
Plugin: pluginName,
|
||||
Skipped: true,
|
||||
SkipReason: constants.InstallMessagePluginAlreadyInstalled,
|
||||
SkipReason: pconstants.InstallMessagePluginAlreadyInstalled,
|
||||
IsUpdateReport: false,
|
||||
}
|
||||
} else {
|
||||
// let the bar append itself with the current installation step
|
||||
bar.AppendFunc(func(b *uiprogress.Bar) string {
|
||||
if report != nil && report.SkipReason == constants.InstallMessagePluginNotFound {
|
||||
return helpers.Resize(constants.InstallMessagePluginNotFound, 20)
|
||||
if report != nil && report.SkipReason == pconstants.InstallMessagePluginNotFound {
|
||||
return helpers.Resize(pconstants.InstallMessagePluginNotFound, 20)
|
||||
} else {
|
||||
if b.Current() == 0 {
|
||||
// no install step to display yet
|
||||
@@ -404,7 +406,7 @@ func runPluginUpdateCmd(cmd *cobra.Command, args []string) {
|
||||
// - aws@^0.118
|
||||
// - ghcr.io/turbot/steampipe/plugins/turbot/aws:1.0.0
|
||||
plugins, err := resolveUpdatePluginsFromArgs(args)
|
||||
showProgress := viper.GetBool(constants.ArgProgress)
|
||||
showProgress := viper.GetBool(pconstants.ArgProgress)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println()
|
||||
@@ -416,7 +418,7 @@ func runPluginUpdateCmd(cmd *cobra.Command, args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
if len(plugins) > 0 && !(cmdconfig.Viper().GetBool(constants.ArgAll)) && plugins[0] == constants.ArgAll {
|
||||
if len(plugins) > 0 && !(cmdconfig.Viper().GetBool(pconstants.ArgAll)) && plugins[0] == pconstants.ArgAll {
|
||||
// improve the response to wrong argument "steampipe plugin update all"
|
||||
fmt.Println()
|
||||
exitCode = constants.ExitCodeInsufficientOrWrongInputs
|
||||
@@ -441,7 +443,7 @@ func runPluginUpdateCmd(cmd *cobra.Command, args []string) {
|
||||
// a leading blank line - since we always output multiple lines
|
||||
fmt.Println()
|
||||
|
||||
if cmdconfig.Viper().GetBool(constants.ArgAll) {
|
||||
if cmdconfig.Viper().GetBool(pconstants.ArgAll) {
|
||||
for k, v := range pluginVersions {
|
||||
ref := putils.NewImageRef(k)
|
||||
org, name, constraint := ref.GetOrgNameAndStream()
|
||||
@@ -454,7 +456,7 @@ func runPluginUpdateCmd(cmd *cobra.Command, args []string) {
|
||||
// get the args and retrieve the installed versions
|
||||
for _, p := range plugins {
|
||||
ref := putils.NewImageRef(p)
|
||||
isExists, _ := plugin.Exists(ctx, p)
|
||||
isExists, _ := pplugin.Exists(ctx, p)
|
||||
if isExists {
|
||||
if strings.HasPrefix(ref.DisplayImageRef(), constants.SteampipeHubOCIBase) {
|
||||
runUpdatesFor = append(runUpdatesFor, pluginVersions[ref.DisplayImageRef()])
|
||||
@@ -468,7 +470,7 @@ func runPluginUpdateCmd(cmd *cobra.Command, args []string) {
|
||||
updateResults = append(updateResults, &display.PluginInstallReport{
|
||||
Skipped: true,
|
||||
Plugin: p,
|
||||
SkipReason: constants.InstallMessagePluginNotInstalled,
|
||||
SkipReason: pconstants.InstallMessagePluginNotInstalled,
|
||||
IsUpdateReport: true,
|
||||
})
|
||||
}
|
||||
@@ -488,7 +490,7 @@ func runPluginUpdateCmd(cmd *cobra.Command, args []string) {
|
||||
defer cancel()
|
||||
|
||||
statushooks.SetStatus(ctx, "Checking for available updates")
|
||||
reports := plugin.GetUpdateReport(timeoutCtx, state.InstallationID, runUpdatesFor)
|
||||
reports := pplugin.GetUpdateReport(timeoutCtx, state.InstallationID, runUpdatesFor)
|
||||
statushooks.Done(ctx)
|
||||
if len(reports) == 0 {
|
||||
// this happens if for some reason the update server could not be contacted,
|
||||
@@ -534,10 +536,10 @@ func runPluginUpdateCmd(cmd *cobra.Command, args []string) {
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
func doPluginUpdate(ctx context.Context, bar *uiprogress.Bar, pvr plugin.PluginVersionCheckReport, wg *sync.WaitGroup, returnChannel chan *display.PluginInstallReport) {
|
||||
func doPluginUpdate(ctx context.Context, bar *uiprogress.Bar, pvr pplugin.PluginVersionCheckReport, wg *sync.WaitGroup, returnChannel chan *display.PluginInstallReport) {
|
||||
var report *display.PluginInstallReport
|
||||
|
||||
if plugin.UpdateRequired(pvr) {
|
||||
if pplugin.UpdateRequired(pvr) {
|
||||
// update required, resolve version and install update
|
||||
bar.AppendFunc(func(b *uiprogress.Bar) string {
|
||||
// set the progress bar to append itself with the step underway
|
||||
@@ -547,20 +549,20 @@ func doPluginUpdate(ctx context.Context, bar *uiprogress.Bar, pvr plugin.PluginV
|
||||
}
|
||||
return helpers.Resize(pluginInstallSteps[b.Current()-1], 20)
|
||||
})
|
||||
rp := plugin.NewResolvedPluginVersion(pvr.ShortName(), pvr.CheckResponse.Version, pvr.CheckResponse.Constraint)
|
||||
rp := pplugin.NewResolvedPluginVersion(pvr.ShortName(), pvr.CheckResponse.Version, pvr.CheckResponse.Constraint)
|
||||
report = installPlugin(ctx, rp, true, bar)
|
||||
} else {
|
||||
// update NOT required, return already installed report
|
||||
bar.AppendFunc(func(b *uiprogress.Bar) string {
|
||||
// set the progress bar to append itself with "Already Installed"
|
||||
return helpers.Resize(constants.InstallMessagePluginLatestAlreadyInstalled, 30)
|
||||
return helpers.Resize(pconstants.InstallMessagePluginLatestAlreadyInstalled, 30)
|
||||
})
|
||||
// set the progress bar to the maximum
|
||||
bar.Set(len(pluginInstallSteps))
|
||||
report = &display.PluginInstallReport{
|
||||
Plugin: fmt.Sprintf("%s@%s", pvr.CheckResponse.Name, pvr.CheckResponse.Constraint),
|
||||
Skipped: true,
|
||||
SkipReason: constants.InstallMessagePluginLatestAlreadyInstalled,
|
||||
SkipReason: pconstants.InstallMessagePluginLatestAlreadyInstalled,
|
||||
IsUpdateReport: true,
|
||||
}
|
||||
}
|
||||
@@ -577,7 +579,7 @@ func createProgressBar(plugin string, parentProgressBars *uiprogress.Progress) *
|
||||
return bar
|
||||
}
|
||||
|
||||
func installPlugin(ctx context.Context, resolvedPlugin plugin.ResolvedPluginVersion, isUpdate bool, bar *uiprogress.Bar) *display.PluginInstallReport {
|
||||
func installPlugin(ctx context.Context, resolvedPlugin pplugin.ResolvedPluginVersion, isUpdate bool, bar *uiprogress.Bar) *display.PluginInstallReport {
|
||||
// start a channel for progress publications from plugin.Install
|
||||
progress := make(chan struct{}, 5)
|
||||
defer func() {
|
||||
@@ -593,14 +595,14 @@ func installPlugin(ctx context.Context, resolvedPlugin plugin.ResolvedPluginVers
|
||||
}
|
||||
}()
|
||||
|
||||
image, err := plugin.Install(ctx, resolvedPlugin, progress, constants.BaseImageRef, ociinstaller.SteampipeMediaTypeProvider{}, putils.WithSkipConfig(viper.GetBool(constants.ArgSkipConfig)))
|
||||
image, err := plugin.Install(ctx, resolvedPlugin, progress, constants.BaseImageRef, ociinstaller.SteampipeMediaTypeProvider{}, putils.WithSkipConfig(viper.GetBool(pconstants.ArgSkipConfig)))
|
||||
if err != nil {
|
||||
msg := ""
|
||||
// used to build data for the plugin install report to be used for display purposes
|
||||
_, name, constraint := putils.NewImageRef(resolvedPlugin.GetVersionTag()).GetOrgNameAndStream()
|
||||
if isPluginNotFoundErr(err) {
|
||||
exitCode = constants.ExitCodePluginNotFound
|
||||
msg = constants.InstallMessagePluginNotFound
|
||||
msg = pconstants.InstallMessagePluginNotFound
|
||||
} else {
|
||||
msg = err.Error()
|
||||
}
|
||||
@@ -643,7 +645,7 @@ func resolveUpdatePluginsFromArgs(args []string) ([]string, error) {
|
||||
return nil, fmt.Errorf("you need to provide at least one plugin to update or use the %s flag", constants.Bold("--all"))
|
||||
}
|
||||
|
||||
if len(plugins) > 0 && cmdconfig.Viper().GetBool(constants.ArgAll) {
|
||||
if len(plugins) > 0 && cmdconfig.Viper().GetBool(pconstants.ArgAll) {
|
||||
// we can't allow update and install at the same time
|
||||
return nil, fmt.Errorf("%s cannot be used when updating specific plugins", constants.Bold("`--all`"))
|
||||
}
|
||||
@@ -655,7 +657,7 @@ func runPluginListCmd(cmd *cobra.Command, _ []string) {
|
||||
// setup a cancel context and start cancel handler
|
||||
ctx, cancel := context.WithCancel(cmd.Context())
|
||||
contexthelpers.StartCancelHandler(cancel)
|
||||
outputFormat := viper.GetString(constants.ArgOutput)
|
||||
outputFormat := viper.GetString(pconstants.ArgOutput)
|
||||
|
||||
utils.LogTime("runPluginListCmd list")
|
||||
defer func() {
|
||||
@@ -716,7 +718,7 @@ func showPluginListAsTable(pluginList []plugin.PluginListItem, failedPluginMap,
|
||||
for _, conn := range item {
|
||||
conns = append(conns, conn.GetName())
|
||||
}
|
||||
missingRows = append(missingRows, []string{p, strings.Join(conns, ","), constants.ConnectionErrorPluginFailedToStart})
|
||||
missingRows = append(missingRows, []string{p, strings.Join(conns, ","), pconstants.ConnectionErrorPluginFailedToStart})
|
||||
conns = []string{}
|
||||
}
|
||||
|
||||
@@ -725,7 +727,7 @@ func showPluginListAsTable(pluginList []plugin.PluginListItem, failedPluginMap,
|
||||
for _, conn := range item {
|
||||
conns = append(conns, conn.GetName())
|
||||
}
|
||||
missingRows = append(missingRows, []string{p, strings.Join(conns, ","), constants.InstallMessagePluginNotInstalled})
|
||||
missingRows = append(missingRows, []string{p, strings.Join(conns, ","), pconstants.InstallMessagePluginNotInstalled})
|
||||
conns = []string{}
|
||||
}
|
||||
|
||||
@@ -761,7 +763,7 @@ func showPluginListAsJSON(pluginList []plugin.PluginListItem, failedPluginMap, m
|
||||
failed := failedPlugin{
|
||||
Name: p,
|
||||
Connections: connections,
|
||||
Reason: constants.ConnectionErrorPluginFailedToStart,
|
||||
Reason: pconstants.ConnectionErrorPluginFailedToStart,
|
||||
}
|
||||
output.Failed = append(output.Failed, failed)
|
||||
}
|
||||
@@ -774,7 +776,7 @@ func showPluginListAsJSON(pluginList []plugin.PluginListItem, failedPluginMap, m
|
||||
missing := failedPlugin{
|
||||
Name: p,
|
||||
Connections: connections,
|
||||
Reason: constants.InstallMessagePluginNotInstalled,
|
||||
Reason: pconstants.InstallMessagePluginNotInstalled,
|
||||
}
|
||||
output.Failed = append(output.Failed, missing)
|
||||
}
|
||||
@@ -898,9 +900,9 @@ func getPluginConnectionMap(ctx context.Context) (pluginConnectionMap, failedPlu
|
||||
continue
|
||||
}
|
||||
|
||||
if state.State == constants.ConnectionStateError && state.Error() == constants.ConnectionErrorPluginFailedToStart {
|
||||
if state.State == constants.ConnectionStateError && state.Error() == pconstants.ConnectionErrorPluginFailedToStart {
|
||||
failedPluginMap[state.Plugin] = append(failedPluginMap[state.Plugin], connection)
|
||||
} else if state.State == constants.ConnectionStateError && state.Error() == constants.ConnectionErrorPluginNotInstalled {
|
||||
} else if state.State == constants.ConnectionStateError && state.Error() == pconstants.ConnectionErrorPluginNotInstalled {
|
||||
missingPluginMap[state.Plugin] = append(missingPluginMap[state.Plugin], connection)
|
||||
}
|
||||
|
||||
|
||||
57
cmd/query.go
57
cmd/query.go
@@ -4,6 +4,7 @@ import (
|
||||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
constants2 "github.com/turbot/pipe-fittings/constants"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
@@ -59,34 +60,34 @@ Examples:
|
||||
AddCloudFlags().
|
||||
AddWorkspaceDatabaseFlag().
|
||||
AddModLocationFlag().
|
||||
AddBoolFlag(constants.ArgHelp, false, "Help for query", cmdconfig.FlagOptions.WithShortHand("h")).
|
||||
AddBoolFlag(constants.ArgHeader, true, "Include column headers csv and table output").
|
||||
AddStringFlag(constants.ArgSeparator, ",", "Separator string for csv output").
|
||||
AddVarFlag(enumflag.New(&queryOutputMode, constants.ArgOutput, constants.QueryOutputModeIds, enumflag.EnumCaseInsensitive),
|
||||
constants.ArgOutput,
|
||||
AddBoolFlag(constants2.ArgHelp, false, "Help for query", cmdconfig.FlagOptions.WithShortHand("h")).
|
||||
AddBoolFlag(constants2.ArgHeader, true, "Include column headers csv and table output").
|
||||
AddStringFlag(constants2.ArgSeparator, ",", "Separator string for csv output").
|
||||
AddVarFlag(enumflag.New(&queryOutputMode, constants2.ArgOutput, constants.QueryOutputModeIds, enumflag.EnumCaseInsensitive),
|
||||
constants2.ArgOutput,
|
||||
fmt.Sprintf("Output format; one of: %s", strings.Join(constants.FlagValues(constants.QueryOutputModeIds), ", "))).
|
||||
AddVarFlag(enumflag.New(&queryTimingMode, constants.ArgTiming, constants.QueryTimingModeIds, enumflag.EnumCaseInsensitive),
|
||||
constants.ArgTiming,
|
||||
AddVarFlag(enumflag.New(&queryTimingMode, constants2.ArgTiming, constants.QueryTimingModeIds, enumflag.EnumCaseInsensitive),
|
||||
constants2.ArgTiming,
|
||||
fmt.Sprintf("Display query timing; one of: %s", strings.Join(constants.FlagValues(constants.QueryTimingModeIds), ", ")),
|
||||
cmdconfig.FlagOptions.NoOptDefVal(constants.ArgOn)).
|
||||
cmdconfig.FlagOptions.NoOptDefVal(constants2.ArgOn)).
|
||||
// TODO #breakingchange
|
||||
//AddBoolFlag(constants.ArgWatch, true, "Watch SQL files in the current workspace (works only in interactive mode)").
|
||||
AddStringSliceFlag(constants.ArgSearchPath, nil, "Set a custom search_path for the steampipe user for a query session (comma-separated)").
|
||||
AddStringSliceFlag(constants.ArgSearchPathPrefix, nil, "Set a prefix to the current search path for a query session (comma-separated)").
|
||||
AddStringSliceFlag(constants.ArgVarFile, nil, "Specify a file containing variable values").
|
||||
AddStringSliceFlag(constants2.ArgSearchPath, nil, "Set a custom search_path for the steampipe user for a query session (comma-separated)").
|
||||
AddStringSliceFlag(constants2.ArgSearchPathPrefix, nil, "Set a prefix to the current search path for a query session (comma-separated)").
|
||||
AddStringSliceFlag(constants2.ArgVarFile, nil, "Specify a file containing variable values").
|
||||
// NOTE: use StringArrayFlag for ArgVariable, 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.ArgVariable, nil, "Specify the value of a variable").
|
||||
AddBoolFlag(constants.ArgInput, true, "Enable interactive prompts").
|
||||
AddBoolFlag(constants.ArgSnapshot, false, "Create snapshot in Turbot Pipes with the default (workspace) visibility").
|
||||
AddBoolFlag(constants.ArgShare, false, "Create snapshot in Turbot Pipes with 'anyone_with_link' visibility").
|
||||
AddStringArrayFlag(constants.ArgSnapshotTag, nil, "Specify tags to set on the snapshot").
|
||||
AddStringFlag(constants.ArgSnapshotTitle, "", "The title to give a snapshot").
|
||||
AddIntFlag(constants.ArgDatabaseQueryTimeout, 0, "The query timeout").
|
||||
AddStringSliceFlag(constants.ArgExport, nil, "Export output to file, supported format: sps (snapshot)").
|
||||
AddStringFlag(constants.ArgSnapshotLocation, "", "The location to write snapshots - either a local file path or a Turbot Pipes workspace").
|
||||
AddBoolFlag(constants.ArgProgress, true, "Display snapshot upload status")
|
||||
AddStringArrayFlag(constants2.ArgVariable, nil, "Specify the value of a variable").
|
||||
AddBoolFlag(constants2.ArgInput, true, "Enable interactive prompts").
|
||||
AddBoolFlag(constants2.ArgSnapshot, false, "Create snapshot in Turbot Pipes with the default (workspace) visibility").
|
||||
AddBoolFlag(constants2.ArgShare, false, "Create snapshot in Turbot Pipes with 'anyone_with_link' visibility").
|
||||
AddStringArrayFlag(constants2.ArgSnapshotTag, nil, "Specify tags to set on the snapshot").
|
||||
AddStringFlag(constants2.ArgSnapshotTitle, "", "The title to give a snapshot").
|
||||
AddIntFlag(constants2.ArgDatabaseQueryTimeout, 0, "The query timeout").
|
||||
AddStringSliceFlag(constants2.ArgExport, nil, "Export output to file, supported format: sps (snapshot)").
|
||||
AddStringFlag(constants2.ArgSnapshotLocation, "", "The location to write snapshots - either a local file path or a Turbot Pipes workspace").
|
||||
AddBoolFlag(constants2.ArgProgress, true, "Display snapshot upload status")
|
||||
|
||||
cmd.AddCommand(getListSubCmd(listSubCmdOptions{parentCmd: cmd}))
|
||||
|
||||
@@ -166,11 +167,11 @@ func runQueryCmd(cmd *cobra.Command, args []string) {
|
||||
|
||||
func validateQueryArgs(ctx context.Context, args []string) error {
|
||||
interactiveMode := len(args) == 0
|
||||
if interactiveMode && (viper.IsSet(constants.ArgSnapshot) || viper.IsSet(constants.ArgShare)) {
|
||||
if interactiveMode && (viper.IsSet(constants2.ArgSnapshot) || viper.IsSet(constants2.ArgShare)) {
|
||||
exitCode = constants.ExitCodeInsufficientOrWrongInputs
|
||||
return sperr.New("cannot share snapshots in interactive mode")
|
||||
}
|
||||
if interactiveMode && len(viper.GetStringSlice(constants.ArgExport)) > 0 {
|
||||
if interactiveMode && len(viper.GetStringSlice(constants2.ArgExport)) > 0 {
|
||||
exitCode = constants.ExitCodeInsufficientOrWrongInputs
|
||||
return sperr.New("cannot export query results in interactive mode")
|
||||
}
|
||||
@@ -182,7 +183,7 @@ func validateQueryArgs(ctx context.Context, args []string) error {
|
||||
}
|
||||
|
||||
validOutputFormats := []string{constants.OutputFormatLine, constants.OutputFormatCSV, constants.OutputFormatTable, constants.OutputFormatJSON, constants.OutputFormatSnapshot, constants.OutputFormatSnapshotShort, constants.OutputFormatNone}
|
||||
output := viper.GetString(constants.ArgOutput)
|
||||
output := viper.GetString(constants2.ArgOutput)
|
||||
if !helpers.StringSliceContains(validOutputFormats, output) {
|
||||
exitCode = constants.ExitCodeInsufficientOrWrongInputs
|
||||
return sperr.New("invalid output format: '%s', must be one of [%s]", output, strings.Join(validOutputFormats, ", "))
|
||||
@@ -342,15 +343,15 @@ func executeSnapshotQuery(initData *query.InitData, ctx context.Context) int {
|
||||
func snapshotRequired() bool {
|
||||
SnapshotFormatNames := []string{constants.OutputFormatSnapshot, constants.OutputFormatSnapshotShort}
|
||||
// if a snapshot exporter is specified return true
|
||||
for _, e := range viper.GetStringSlice(constants.ArgExport) {
|
||||
for _, e := range viper.GetStringSlice(constants2.ArgExport) {
|
||||
if helpers.StringSliceContains(SnapshotFormatNames, e) || path.Ext(e) == constants.SnapshotExtension {
|
||||
return true
|
||||
}
|
||||
}
|
||||
// if share/snapshot args are set or output is snapshot, return true
|
||||
return viper.IsSet(constants.ArgShare) ||
|
||||
viper.IsSet(constants.ArgSnapshot) ||
|
||||
helpers.StringSliceContains(SnapshotFormatNames, viper.GetString(constants.ArgOutput))
|
||||
return viper.IsSet(constants2.ArgShare) ||
|
||||
viper.IsSet(constants2.ArgSnapshot) ||
|
||||
helpers.StringSliceContains(SnapshotFormatNames, viper.GetString(constants2.ArgOutput))
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package cmd
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/turbot/pipe-fittings/constants"
|
||||
"os"
|
||||
|
||||
"github.com/mattn/go-isatty"
|
||||
@@ -11,7 +12,6 @@ import (
|
||||
filehelpers "github.com/turbot/go-kit/files"
|
||||
"github.com/turbot/pipe-fittings/app_specific"
|
||||
"github.com/turbot/pipe-fittings/utils"
|
||||
"github.com/turbot/steampipe/pkg/constants"
|
||||
"github.com/turbot/steampipe/pkg/error_helpers"
|
||||
"github.com/turbot/steampipe/pkg/statushooks"
|
||||
"github.com/turbot/steampipe/pkg/version"
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
constants2 "github.com/turbot/pipe-fittings/constants"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -42,7 +43,7 @@ connection from any Postgres compatible database client.`,
|
||||
cmd.AddCommand(serviceStatusCmd())
|
||||
cmd.AddCommand(serviceStopCmd())
|
||||
cmd.AddCommand(serviceRestartCmd())
|
||||
cmd.Flags().BoolP(constants.ArgHelp, "h", false, "Help for service")
|
||||
cmd.Flags().BoolP(constants2.ArgHelp, "h", false, "Help for service")
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -62,17 +63,17 @@ connection from any Postgres compatible database client.`,
|
||||
cmdconfig.
|
||||
OnCmd(cmd).
|
||||
AddModLocationFlag().
|
||||
AddBoolFlag(constants.ArgHelp, false, "Help for service start", cmdconfig.FlagOptions.WithShortHand("h")).
|
||||
AddIntFlag(constants.ArgDatabasePort, constants.DatabaseDefaultPort, "Database service port").
|
||||
AddStringFlag(constants.ArgDatabaseListenAddresses, string(db_local.ListenTypeNetwork), "Accept connections from: `local` (an alias for `localhost` only), `network` (an alias for `*`), or a comma separated list of hosts and/or IP addresses").
|
||||
AddStringFlag(constants.ArgServicePassword, "", "Set the database password for this session").
|
||||
AddBoolFlag(constants2.ArgHelp, false, "Help for service start", cmdconfig.FlagOptions.WithShortHand("h")).
|
||||
AddIntFlag(constants2.ArgDatabasePort, constants.DatabaseDefaultPort, "Database service port").
|
||||
AddStringFlag(constants2.ArgDatabaseListenAddresses, string(db_local.ListenTypeNetwork), "Accept connections from: `local` (an alias for `localhost` only), `network` (an alias for `*`), or a comma separated list of hosts and/or IP addresses").
|
||||
AddStringFlag(constants2.ArgServicePassword, "", "Set the database password for this session").
|
||||
// default is false and hides the database user password from service start prompt
|
||||
AddBoolFlag(constants.ArgServiceShowPassword, false, "View database password for connecting from another machine").
|
||||
AddBoolFlag(constants2.ArgServiceShowPassword, false, "View database password for connecting from another machine").
|
||||
// foreground enables the service to run in the foreground - till exit
|
||||
AddBoolFlag(constants.ArgForeground, false, "Run the service in the foreground").
|
||||
AddBoolFlag(constants2.ArgForeground, false, "Run the service in the foreground").
|
||||
|
||||
// hidden flags for internal use
|
||||
AddStringFlag(constants.ArgInvoker, string(constants.InvokerService), "Invoked by \"service\" or \"query\"", cmdconfig.FlagOptions.Hidden())
|
||||
AddStringFlag(constants2.ArgInvoker, string(constants.InvokerService), "Invoked by \"service\" or \"query\"", cmdconfig.FlagOptions.Hidden())
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -90,10 +91,10 @@ Report current status of the Steampipe database service.`,
|
||||
}
|
||||
|
||||
cmdconfig.OnCmd(cmd).
|
||||
AddBoolFlag(constants.ArgHelp, false, "Help for service status", cmdconfig.FlagOptions.WithShortHand("h")).
|
||||
AddBoolFlag(constants2.ArgHelp, false, "Help for service status", cmdconfig.FlagOptions.WithShortHand("h")).
|
||||
// default is false and hides the database user password from service start prompt
|
||||
AddBoolFlag(constants.ArgServiceShowPassword, false, "View database password for connecting from another machine").
|
||||
AddBoolFlag(constants.ArgAll, false, "Bypasses the INSTALL_DIR and reports status of all running steampipe services")
|
||||
AddBoolFlag(constants2.ArgServiceShowPassword, false, "View database password for connecting from another machine").
|
||||
AddBoolFlag(constants2.ArgAll, false, "Bypasses the INSTALL_DIR and reports status of all running steampipe services")
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -110,8 +111,8 @@ func serviceStopCmd() *cobra.Command {
|
||||
|
||||
cmdconfig.
|
||||
OnCmd(cmd).
|
||||
AddBoolFlag(constants.ArgHelp, false, "Help for service stop", cmdconfig.FlagOptions.WithShortHand("h")).
|
||||
AddBoolFlag(constants.ArgForce, false, "Forces all services to shutdown, releasing all open connections and ports")
|
||||
AddBoolFlag(constants2.ArgHelp, false, "Help for service stop", cmdconfig.FlagOptions.WithShortHand("h")).
|
||||
AddBoolFlag(constants2.ArgForce, false, "Forces all services to shutdown, releasing all open connections and ports")
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -128,8 +129,8 @@ func serviceRestartCmd() *cobra.Command {
|
||||
|
||||
cmdconfig.
|
||||
OnCmd(cmd).
|
||||
AddBoolFlag(constants.ArgHelp, false, "Help for service restart", cmdconfig.FlagOptions.WithShortHand("h")).
|
||||
AddBoolFlag(constants.ArgForce, false, "Forces the service to restart, releasing all open connections and ports")
|
||||
AddBoolFlag(constants2.ArgHelp, false, "Help for service restart", cmdconfig.FlagOptions.WithShortHand("h")).
|
||||
AddBoolFlag(constants2.ArgForce, false, "Forces the service to restart, releasing all open connections and ports")
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -153,15 +154,15 @@ func runServiceStartCmd(cmd *cobra.Command, _ []string) {
|
||||
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt, os.Kill)
|
||||
defer cancel()
|
||||
|
||||
listenAddresses := db_local.StartListenType(viper.GetString(constants.ArgDatabaseListenAddresses)).ToListenAddresses()
|
||||
listenAddresses := db_local.StartListenType(viper.GetString(constants2.ArgDatabaseListenAddresses)).ToListenAddresses()
|
||||
|
||||
port := viper.GetInt(constants.ArgDatabasePort)
|
||||
port := viper.GetInt(constants2.ArgDatabasePort)
|
||||
if port < 1 || port > 65535 {
|
||||
exitCode = constants.ExitCodeInsufficientOrWrongInputs
|
||||
panic("Invalid port - must be within range (1:65535)")
|
||||
}
|
||||
|
||||
invoker := constants.Invoker(cmdconfig.Viper().GetString(constants.ArgInvoker))
|
||||
invoker := constants.Invoker(cmdconfig.Viper().GetString(constants2.ArgInvoker))
|
||||
if invoker.IsValid() != nil {
|
||||
exitCode = constants.ExitCodeInsufficientOrWrongInputs
|
||||
error_helpers.FailOnError(invoker.IsValid())
|
||||
@@ -172,7 +173,7 @@ func runServiceStartCmd(cmd *cobra.Command, _ []string) {
|
||||
|
||||
printStatus(ctx, startResult.DbState, startResult.PluginManagerState, alreadyRunning)
|
||||
|
||||
if viper.GetBool(constants.ArgForeground) {
|
||||
if viper.GetBool(constants2.ArgForeground) {
|
||||
runServiceInForeground(ctx)
|
||||
}
|
||||
}
|
||||
@@ -338,7 +339,7 @@ func restartService(ctx context.Context) (_ *db_local.StartResult) {
|
||||
}
|
||||
|
||||
// stop db
|
||||
stopStatus, err := db_local.StopServices(ctx, viper.GetBool(constants.ArgForce), constants.InvokerService)
|
||||
stopStatus, err := db_local.StopServices(ctx, viper.GetBool(constants2.ArgForce), constants.InvokerService)
|
||||
if err != nil {
|
||||
exitCode = constants.ExitCodeServiceStopFailure
|
||||
error_helpers.FailOnErrorWithMessage(err, "could not stop current instance")
|
||||
@@ -365,7 +366,7 @@ to force a restart.
|
||||
}
|
||||
|
||||
// set the password in 'viper' so that it can be used by 'service start'
|
||||
viper.Set(constants.ArgServicePassword, currentDbState.Password)
|
||||
viper.Set(constants2.ArgServicePassword, currentDbState.Password)
|
||||
|
||||
// start db
|
||||
dbStartResult := startServiceAndRefreshConnections(ctx, currentDbState.ResolvedListenAddresses, currentDbState.Port, currentDbState.Invoker)
|
||||
@@ -393,7 +394,7 @@ func runServiceStatusCmd(cmd *cobra.Command, _ []string) {
|
||||
return
|
||||
}
|
||||
|
||||
if viper.GetBool(constants.ArgAll) {
|
||||
if viper.GetBool(constants2.ArgAll) {
|
||||
showAllStatus(ctx)
|
||||
} else {
|
||||
dbState, dbStateErr := db_local.GetState()
|
||||
@@ -443,7 +444,7 @@ func runServiceStopCmd(cmd *cobra.Command, _ []string) {
|
||||
}
|
||||
}()
|
||||
|
||||
force := cmdconfig.Viper().GetBool(constants.ArgForce)
|
||||
force := cmdconfig.Viper().GetBool(constants2.ArgForce)
|
||||
if force {
|
||||
status, dbStopError = db_local.StopServices(ctx, force, constants.InvokerService)
|
||||
dbStopError = error_helpers.CombineErrors(dbStopError)
|
||||
@@ -588,7 +589,7 @@ Managing the Steampipe service:
|
||||
|
||||
var connectionStr string
|
||||
var password string
|
||||
if viper.GetBool(constants.ArgServiceShowPassword) {
|
||||
if viper.GetBool(constants2.ArgServiceShowPassword) {
|
||||
connectionStr = fmt.Sprintf(
|
||||
"postgres://%v:%v@%v:%v/%v",
|
||||
dbState.User,
|
||||
|
||||
Reference in New Issue
Block a user