Add flag for disabling writing of default plugin config during plugin installation. Closes #3531. Closes #2206

This commit is contained in:
Meet Rajesh Gor
2023-07-28 14:45:37 +05:30
committed by GitHub
parent 16a59b6e46
commit ce2bc0cb5b
6 changed files with 86 additions and 8 deletions

View File

@@ -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()

View File

@@ -18,6 +18,7 @@ const (
ArgDashboard = "dashboard"
ArgDashboardListen = "dashboard-listen"
ArgDashboardPort = "dashboard-port"
ArgSkipConfig = "skip-config"
ArgForeground = "foreground"
ArgInvoker = "invoker"
ArgUpdateCheck = "update-check"

View 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
}
}

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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