mirror of
https://github.com/turbot/steampipe.git
synced 2026-02-27 11:01:05 -05:00
Add flag for disabling writing of default plugin config during plugin installation. Closes #3531. Closes #2206
This commit is contained in:
@@ -109,12 +109,16 @@ Examples:
|
||||
steampipe plugin install turbot/azure@0.1.0
|
||||
|
||||
# Hide progress bars during installation
|
||||
steampipe plugin install --progress=false aws`,
|
||||
steampipe plugin install --progress=false aws
|
||||
|
||||
# Skip creation of default plugin config file
|
||||
steampipe plugin install --skip-config aws`,
|
||||
}
|
||||
|
||||
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"))
|
||||
return cmd
|
||||
}
|
||||
@@ -542,7 +546,7 @@ func installPlugin(ctx context.Context, pluginName string, isUpdate bool, bar *u
|
||||
}
|
||||
}()
|
||||
|
||||
image, err := plugin.Install(ctx, pluginName, progress)
|
||||
image, err := plugin.Install(ctx, pluginName, progress, ociinstaller.WithSkipConfig(viper.GetBool(constants.ArgSkipConfig)))
|
||||
if err != nil {
|
||||
msg := ""
|
||||
_, name, stream := ociinstaller.NewSteampipeImageRef(pluginName).GetOrgNameAndStream()
|
||||
|
||||
@@ -18,6 +18,7 @@ const (
|
||||
ArgDashboard = "dashboard"
|
||||
ArgDashboardListen = "dashboard-listen"
|
||||
ArgDashboardPort = "dashboard-port"
|
||||
ArgSkipConfig = "skip-config"
|
||||
ArgForeground = "foreground"
|
||||
ArgInvoker = "invoker"
|
||||
ArgUpdateCheck = "update-check"
|
||||
|
||||
13
pkg/ociinstaller/config.go
Normal file
13
pkg/ociinstaller/config.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package ociinstaller
|
||||
|
||||
type pluginInstallConfig struct {
|
||||
skipConfigFile bool
|
||||
}
|
||||
|
||||
type PluginInstallOption = func(config *pluginInstallConfig)
|
||||
|
||||
func WithSkipConfig(skipConfigFile bool) PluginInstallOption {
|
||||
return func(o *pluginInstallConfig) {
|
||||
o.skipConfigFile = skipConfigFile
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,11 @@ import (
|
||||
var versionFileUpdateLock = &sync.Mutex{}
|
||||
|
||||
// InstallPlugin installs a plugin from an OCI Image
|
||||
func InstallPlugin(ctx context.Context, imageRef string, sub chan struct{}) (*SteampipeImage, error) {
|
||||
func InstallPlugin(ctx context.Context, imageRef string, sub chan struct{}, opts ...PluginInstallOption) (*SteampipeImage, error) {
|
||||
config := &pluginInstallConfig{}
|
||||
for _, opt := range opts {
|
||||
opt(config)
|
||||
}
|
||||
tempDir := NewTempDir(filepaths.EnsurePluginDir())
|
||||
defer func() {
|
||||
// send a last beacon to signal completion
|
||||
@@ -49,9 +53,10 @@ func InstallPlugin(ctx context.Context, imageRef string, sub chan struct{}) (*St
|
||||
if err = installPluginDocs(image, tempDir.Path); err != nil {
|
||||
return nil, fmt.Errorf("plugin installation failed: %s", err)
|
||||
}
|
||||
sub <- struct{}{}
|
||||
if err = installPluginConfigFiles(image, tempDir.Path); err != nil {
|
||||
return nil, fmt.Errorf("plugin installation failed: %s", err)
|
||||
if !config.skipConfigFile {
|
||||
if err = installPluginConfigFiles(image, tempDir.Path); err != nil {
|
||||
return nil, fmt.Errorf("plugin installation failed: %s", err)
|
||||
}
|
||||
}
|
||||
sub <- struct{}{}
|
||||
if err := updatePluginVersionFiles(image); err != nil {
|
||||
|
||||
@@ -71,8 +71,8 @@ func Exists(plugin string) (bool, error) {
|
||||
}
|
||||
|
||||
// Install installs a plugin in the local file system
|
||||
func Install(ctx context.Context, plugin string, sub chan struct{}) (*ociinstaller.SteampipeImage, error) {
|
||||
image, err := ociinstaller.InstallPlugin(ctx, plugin, sub)
|
||||
func Install(ctx context.Context, plugin string, sub chan struct{}, opts ...ociinstaller.PluginInstallOption) (*ociinstaller.SteampipeImage, error) {
|
||||
image, err := ociinstaller.InstallPlugin(ctx, plugin, sub, opts...)
|
||||
return image, err
|
||||
}
|
||||
|
||||
|
||||
@@ -721,6 +721,61 @@ load "$LIB_BATS_SUPPORT/load.bash"
|
||||
rm -rf $tmpdir
|
||||
}
|
||||
|
||||
@test "verify that plugin installed with --skip-config as true, should not have create a default config .spc file in config folder" {
|
||||
tmpdir=$(mktemp -d)
|
||||
run steampipe plugin install aws --skip-config --install-dir $tmpdir
|
||||
assert_success
|
||||
|
||||
run test -f $tmpdir/config/aws.spc
|
||||
assert_failure
|
||||
|
||||
rm -rf $tmpdir
|
||||
}
|
||||
|
||||
@test "verify that plugin installed with --skip-config as false(default), should have default config .spc file in config folder" {
|
||||
tmpdir=$(mktemp -d)
|
||||
run steampipe plugin install aws --install-dir $tmpdir
|
||||
assert_success
|
||||
|
||||
run test -f $tmpdir/config/aws.spc
|
||||
assert_success
|
||||
|
||||
rm -rf $tmpdir
|
||||
}
|
||||
|
||||
@test "verify reinstalling a plugin does not overwrite existing plugin config" {
|
||||
# check if the default/tweaked config file for a plugin is not deleted after
|
||||
# re-installation of a plugin
|
||||
|
||||
tmpdir=$(mktemp -d)
|
||||
|
||||
run steampipe plugin install aws --install-dir $tmpdir
|
||||
|
||||
run test -f $tmpdir/config/aws.spc
|
||||
assert_success
|
||||
|
||||
echo '
|
||||
connection "aws" {
|
||||
plugin = "aws"
|
||||
endpoint_url = "http://localhost:4566"
|
||||
}
|
||||
' >> $tmpdir/config/aws.spc
|
||||
cp $tmpdir/config/aws.spc config.spc
|
||||
|
||||
run steampipe plugin uninstall aws --install-dir $tmpdir
|
||||
|
||||
run steampipe plugin install aws --skip-config --install-dir $tmpdir
|
||||
|
||||
run test -f $tmpdir/config/aws.spc
|
||||
assert_success
|
||||
|
||||
run diff $tmpdir/config/aws.spc config.spc
|
||||
assert_success
|
||||
|
||||
rm config.spc
|
||||
rm -rf $tmpdir
|
||||
}
|
||||
|
||||
@test "cleanup" {
|
||||
rm -f $STEAMPIPE_INSTALL_DIR/config/chaos_agg.spc
|
||||
run steampipe plugin uninstall steampipe
|
||||
|
||||
Reference in New Issue
Block a user