From 6956cd80b0b5cb53ffece21571452006d4665575 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Tue, 31 Oct 2023 11:34:01 +0900 Subject: [PATCH] fix: fix a bug that AQUA_DISABLE_POLIDY doesn't work - https://github.com/orgs/aquaproj/discussions/2414 --- pkg/controller/cp/controller.go | 2 +- pkg/controller/cp/install.go | 4 +++- pkg/controller/exec/exec.go | 5 +++-- pkg/controller/install/install.go | 7 ++++--- pkg/installpackage/installer.go | 2 ++ 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pkg/controller/cp/controller.go b/pkg/controller/cp/controller.go index 01299d406..6a5f1c4b2 100644 --- a/pkg/controller/cp/controller.go +++ b/pkg/controller/cp/controller.go @@ -117,7 +117,7 @@ func (c *Controller) installAndCopy(ctx context.Context, logE *logrus.Entry, par return err //nolint:wrapcheck } - if err := c.install(ctx, logE, findResult, policyConfigs); err != nil { + if err := c.install(ctx, logE, findResult, policyConfigs, param); err != nil { return err } } diff --git a/pkg/controller/cp/install.go b/pkg/controller/cp/install.go index 4f7606987..a9e848619 100644 --- a/pkg/controller/cp/install.go +++ b/pkg/controller/cp/install.go @@ -6,6 +6,7 @@ import ( "path/filepath" "github.com/aquaproj/aqua/v2/pkg/checksum" + "github.com/aquaproj/aqua/v2/pkg/config" "github.com/aquaproj/aqua/v2/pkg/controller/which" "github.com/aquaproj/aqua/v2/pkg/installpackage" "github.com/aquaproj/aqua/v2/pkg/policy" @@ -13,7 +14,7 @@ import ( "github.com/suzuki-shunsuke/logrus-error/logerr" ) -func (c *Controller) install(ctx context.Context, logE *logrus.Entry, findResult *which.FindResult, policyConfigs []*policy.Config) error { +func (c *Controller) install(ctx context.Context, logE *logrus.Entry, findResult *which.FindResult, policyConfigs []*policy.Config, param *config.Param) error { var checksums *checksum.Checksums if findResult.Config.ChecksumEnabled() { checksums = checksum.New() @@ -37,6 +38,7 @@ func (c *Controller) install(ctx context.Context, logE *logrus.Entry, findResult RequireChecksum: findResult.Config.RequireChecksum(c.requireChecksum), ConfigFileDir: filepath.Dir(findResult.ConfigFilePath), PolicyConfigs: policyConfigs, + DisablePolicy: param.DisablePolicy, }); err != nil { return fmt.Errorf("install a package: %w", logerr.WithFields(err, logE.Data)) } diff --git a/pkg/controller/exec/exec.go b/pkg/controller/exec/exec.go index 9c90a8807..07261a1a2 100644 --- a/pkg/controller/exec/exec.go +++ b/pkg/controller/exec/exec.go @@ -58,13 +58,13 @@ func (c *Controller) Exec(ctx context.Context, logE *logrus.Entry, param *config return logerr.WithFields(errExecNotFoundDisableLazyInstall, logE.WithField("doc", "https://aquaproj.github.io/docs/reference/codes/006").Data) //nolint:wrapcheck } } - if err := c.install(ctx, logE, findResult, policyCfgs); err != nil { + if err := c.install(ctx, logE, findResult, policyCfgs, param); err != nil { return err } return c.execCommandWithRetry(ctx, logE, findResult.ExePath, args...) } -func (c *Controller) install(ctx context.Context, logE *logrus.Entry, findResult *which.FindResult, policies []*policy.Config) error { +func (c *Controller) install(ctx context.Context, logE *logrus.Entry, findResult *which.FindResult, policies []*policy.Config, param *config.Param) error { var checksums *checksum.Checksums if findResult.Config.ChecksumEnabled() { checksums = checksum.New() @@ -87,6 +87,7 @@ func (c *Controller) install(ctx context.Context, logE *logrus.Entry, findResult Checksums: checksums, RequireChecksum: findResult.Config.RequireChecksum(c.requireChecksum), PolicyConfigs: policies, + DisablePolicy: param.DisablePolicy, }); err != nil { return fmt.Errorf("install the package: %w", err) } diff --git a/pkg/controller/install/install.go b/pkg/controller/install/install.go index a9b7c9b2b..ba9b9f91c 100644 --- a/pkg/controller/install/install.go +++ b/pkg/controller/install/install.go @@ -45,7 +45,7 @@ func (c *Controller) Install(ctx context.Context, logE *logrus.Entry, param *con if err != nil { return err //nolint:wrapcheck } - if err := c.install(ctx, logE, cfgFilePath, policyCfgs); err != nil { + if err := c.install(ctx, logE, cfgFilePath, policyCfgs, param); err != nil { return err } } @@ -78,14 +78,14 @@ func (c *Controller) installAll(ctx context.Context, logE *logrus.Entry, param * if err != nil { return err //nolint:wrapcheck } - if err := c.install(ctx, logE, cfgFilePath, policyConfigs); err != nil { + if err := c.install(ctx, logE, cfgFilePath, policyConfigs, param); err != nil { return err } } return nil } -func (c *Controller) install(ctx context.Context, logE *logrus.Entry, cfgFilePath string, policyConfigs []*policy.Config) error { +func (c *Controller) install(ctx context.Context, logE *logrus.Entry, cfgFilePath string, policyConfigs []*policy.Config, param *config.Param) error { cfg := &aqua.Config{} if cfgFilePath == "" { return finder.ErrConfigFileNotFound @@ -126,5 +126,6 @@ func (c *Controller) install(ctx context.Context, logE *logrus.Entry, cfgFilePat PolicyConfigs: policyConfigs, Checksums: checksums, RequireChecksum: c.requireChecksum, + DisablePolicy: param.DisablePolicy, }) } diff --git a/pkg/installpackage/installer.go b/pkg/installpackage/installer.go index 6bb13ed18..2f6ba0391 100644 --- a/pkg/installpackage/installer.go +++ b/pkg/installpackage/installer.go @@ -117,6 +117,7 @@ type ParamInstallPackages struct { Checksums *checksum.Checksums SkipLink bool RequireChecksum bool + DisablePolicy bool } type ParamInstallPackage struct { @@ -208,6 +209,7 @@ func (is *InstallerImpl) InstallPackages(ctx context.Context, logE *logrus.Entry Checksums: param.Checksums, RequireChecksum: param.Config.RequireChecksum(param.RequireChecksum), PolicyConfigs: param.PolicyConfigs, + DisablePolicy: param.DisablePolicy, }); err != nil { logerr.WithError(logE, err).Error("install the package") handleFailure()