Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update policy #2894

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pkg/controller/updatepolicy/controller.go
Original file line number Diff line number Diff line change
@@ -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)
}
27 changes: 27 additions & 0 deletions pkg/controller/updatepolicy/update_policy.go
Original file line number Diff line number Diff line change
@@ -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 {

Check failure on line 22 in pkg/controller/updatepolicy/update_policy.go

View workflow job for this annotation

GitHub Actions / test / test

c.install undefined (type *Controller has no field or method install) (typecheck)
return err
}
}
return nil
}
Loading