diff --git a/pkg/controller/updatepolicy/controller.go b/pkg/controller/updatepolicy/controller.go new file mode 100644 index 000000000..19284ce69 --- /dev/null +++ b/pkg/controller/updatepolicy/controller.go @@ -0,0 +1,28 @@ +package updatepolicy + +import ( + "github.com/aquaproj/aqua/v2/pkg/policy" + "github.com/sirupsen/logrus" + "github.com/spf13/afero" +) + +type Controller struct { + fs afero.Fs + configFinder ConfigFinder + policyReader PolicyReader +} + +func New(fs afero.Fs) *Controller { + return &Controller{ + fs: fs, + } +} + +type ConfigFinder interface { + Finds(wd, configFilePath string) []string +} + +type PolicyReader interface { + Read(policyFilePaths []string) ([]*policy.Config, error) + Append(logE *logrus.Entry, aquaYAMLPath string, policies []*policy.Config, globalPolicyPaths map[string]struct{}) ([]*policy.Config, error) +} diff --git a/pkg/controller/updatepolicy/update_policy.go b/pkg/controller/updatepolicy/update_policy.go new file mode 100644 index 000000000..f4b5061c2 --- /dev/null +++ b/pkg/controller/updatepolicy/update_policy.go @@ -0,0 +1,27 @@ +package updatepolicy + +import ( + "context" + + "github.com/aquaproj/aqua/v2/pkg/config" + "github.com/aquaproj/aqua/v2/pkg/policy" + "github.com/sirupsen/logrus" +) + +func (c *Controller) UpdatePolicy(ctx context.Context, logE *logrus.Entry, param *config.Param) error { + // Find a policy file + // Find aqua.yaml + // list packages + // Update a policy file + var policyCfgs []*policy.Config + for _, cfgFilePath := range c.configFinder.Finds(param.PWD, param.ConfigFilePath) { + policyCfgs, err := c.policyReader.Append(logE, cfgFilePath, policyCfgs, nil) + if err != nil { + return err //nolint:wrapcheck + } + if err := c.install(ctx, logE, cfgFilePath, policyCfgs, param); err != nil { + return err + } + } + return nil +}