diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f80250ac7..2564cb94b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -198,20 +198,13 @@ jobs: - run: aqua list - run: aqua update-checksum working-directory: tests/main - - run: aqua update-checksum -deep - working-directory: tests/main - run: aqua update-checksum -prune working-directory: tests/main - run: aqua i -l -a working-directory: tests/main - - run: cmdx -v - working-directory: tests/main - - run: aqua i --test - working-directory: tests/main - - run: aqua which golangci-lint + - run: aqua i working-directory: tests/main - run: aqua which go - - run: golangci-lint version - run: kind version working-directory: tests/main - run: kind version @@ -223,12 +216,6 @@ jobs: - run: gh version - run: tfenv --version - run: aqua -c tests/main/aqua-global.yaml g local,kubernetes-sigs/kustomize - - run: btop -v - - run: btop -v - env: - AQUA_EXPERIMENTAL_X_SYS_EXEC: "true" - - run: wire --help - - run: gox --help - run: bats -v - run: helm version - run: github-compare -v @@ -264,16 +251,10 @@ jobs: - name: Test generate-registry (specify version) run: aqua gr suzuki-shunsuke/tfcmt@v3.2.4 - - name: "test version_source: github_tag" - run: aqua -c aqua-global.yaml g local,mitchellh/gox - working-directory: tests/main - - name: test aqua cp - run: aqua cp actionlint golangci-lint + run: aqua cp actionlint - name: test aqua cp run: dist/actionlint -version - - name: test aqua cp - run: dist/golangci-lint version - name: test aqua cp run: aqua cp - name: test aqua cp -a @@ -314,8 +295,6 @@ jobs: - run: aqua update-checksum -a # Test if global configuration files are read in `aqua list` and `aqua g` - - run: aqua g suzuki-shunsuke/cmdx - working-directory: /tmp - run: aqua list working-directory: /tmp diff --git a/.github/workflows/windows-test.yaml b/.github/workflows/windows-test.yaml index 20348276d..9b0f8baaf 100644 --- a/.github/workflows/windows-test.yaml +++ b/.github/workflows/windows-test.yaml @@ -40,7 +40,7 @@ jobs: working-directory: tests/main - run: cmdx -v working-directory: tests/main - - run: aqua i --test + - run: aqua i working-directory: tests/main - run: aqua which golangci-lint working-directory: tests/main @@ -56,8 +56,6 @@ jobs: - run: ghq -version - run: gh version - run: aqua -c tests/main/aqua-global.yaml g local,kubernetes-sigs/kustomize - - run: wire --help - - run: gox --help - run: github-compare -v - run: helm version - run: terrafmt version @@ -72,10 +70,6 @@ jobs: - name: "Test generate-registry (rust)" run: aqua gr XAMPPRocky/tokei - - name: "test version_source: github_tag" - run: aqua -c aqua-global.yaml g local,mitchellh/gox - working-directory: tests/main - # Test if global configuration files are read in `aqua list` and `aqua g` - run: aqua g suzuki-shunsuke/cmdx working-directory: ${{ env.HOME }} @@ -118,7 +112,7 @@ jobs: working-directory: tests/main - run: cmdx -v working-directory: tests/main - - run: aqua i --test + - run: aqua i working-directory: tests/main - run: aqua which golangci-lint working-directory: tests/main @@ -134,8 +128,6 @@ jobs: - run: ghq -version - run: gh version - run: aqua -c tests/main/aqua-global.yaml g local,kubernetes-sigs/kustomize - - run: wire --help - - run: gox --help - run: github-compare -v - run: terrafmt version - run: helm version @@ -150,10 +142,6 @@ jobs: - name: "Test generate-registry (rust)" run: aqua gr XAMPPRocky/tokei - - name: "test version_source: github_tag" - run: aqua -c aqua-global.yaml g local,mitchellh/gox - working-directory: tests/main - # Test if global configuration files are read in `aqua list` and `aqua g` - run: aqua g suzuki-shunsuke/cmdx working-directory: ${{env.HOME}} diff --git a/pkg/cli/cp.go b/pkg/cli/cp.go index 1c4598faa..cccf71c8b 100644 --- a/pkg/cli/cp.go +++ b/pkg/cli/cp.go @@ -81,7 +81,6 @@ func (runner *Runner) cpAction(c *cli.Context) error { if err := runner.setParam(c, "cp", param); err != nil { return fmt.Errorf("parse the command line arguments: %w", err) } - param.IsTest = true param.SkipLink = true ctrl := controller.InitializeCopyCommandController(c.Context, param, http.DefaultClient, runner.Runtime) if err := ctrl.Copy(c.Context, runner.LogE, param); err != nil { diff --git a/pkg/cli/install.go b/pkg/cli/install.go index f49493ff8..e3dcf0030 100644 --- a/pkg/cli/install.go +++ b/pkg/cli/install.go @@ -44,7 +44,7 @@ $ aqua i --exclude-tags foo # Install only packages not having a tag "foo" }, &cli.BoolFlag{ Name: "test", - Usage: "test file.src after installing the package", + Usage: "This flag was deprecated and had no meaning from aqua v2.0.0. This flag will be removed in aqua v3.0.0. https://github.com/aquaproj/aqua/issues/1691", }, &cli.BoolFlag{ Name: "all", diff --git a/pkg/cli/runner.go b/pkg/cli/runner.go index f74c49785..70fa07221 100644 --- a/pkg/cli/runner.go +++ b/pkg/cli/runner.go @@ -43,7 +43,6 @@ func (runner *Runner) setParam(c *cli.Context, commandName string, param *config param.Dest = c.String("o") param.OutTestData = c.String("out-testdata") param.OnlyLink = c.Bool("only-link") - param.IsTest = c.Bool("test") if commandName == "generate-registry" { param.InsertFile = c.String("i") } else { diff --git a/pkg/cli/update_checksum.go b/pkg/cli/update_checksum.go index acc55c8ce..9b6bcb425 100644 --- a/pkg/cli/update_checksum.go +++ b/pkg/cli/update_checksum.go @@ -12,38 +12,33 @@ import ( func (runner *Runner) newUpdateChecksumCommand() *cli.Command { return &cli.Command{ Name: "update-checksum", - Usage: "Create or Update .aqua-checksums.json", + Usage: "Create or Update aqua-checksums.json", Flags: []cli.Flag{ &cli.BoolFlag{ Name: "all", Aliases: []string{"a"}, - Usage: "Create or Update all .aqua-checksums.json including global configuration", + Usage: "Create or Update all aqua-checksums.json including global configuration", }, &cli.BoolFlag{ Name: "deep", - Usage: "If a package's checksum configuration is disabled, download the asset and calculate the checksum", + Usage: "This flag was deprecated and had no meaning from aqua v2.0.0. This flag will be removed in aqua v3.0.0. https://github.com/aquaproj/aqua/issues/1769", }, &cli.BoolFlag{ Name: "prune", Usage: "Remove unused checksums", }, }, - Description: `Create or Update .aqua-checksums.json. + Description: `Create or Update aqua-checksums.json. e.g. $ aqua update-checksum -By default aqua doesn't update .aqua-checksums.json of the global configuration. +By default aqua doesn't update aqua-checksums.json of the global configuration. If you want to update them too, please set "-a" option. $ aqua update-checksum -a -By default, aqua update-checksum doesn't add checksums if the package's checksum configuration is disabled. -If -deep option is set, aqua update-checksum downloads assets and calculate checksums. - -$ aqua update-checksum -deep - By default, aqua update-checksum doesn't remove existing checksums even if they aren't unused. If -prune option is set, aqua unused checksums would be removed. diff --git a/pkg/config-finder/config_finder.go b/pkg/config-finder/config_finder.go index 2b57909ba..1b9d0dde8 100644 --- a/pkg/config-finder/config_finder.go +++ b/pkg/config-finder/config_finder.go @@ -72,7 +72,7 @@ func (finder *ConfigFinder) Finds(wd, configFilePath string) []string { if configFilePath == "" { return findconfig.Finds(wd, finder.exist, configFileNames()...) } - return append([]string{util.Abs(wd, configFilePath)}, findconfig.Finds(wd, finder.exist, configFileNames()...)...) + return []string{util.Abs(wd, configFilePath)} } func (finder *ConfigFinder) exist(p string) bool { diff --git a/pkg/config-finder/config_finder_test.go b/pkg/config-finder/config_finder_test.go index a65f9634c..af764c9a7 100644 --- a/pkg/config-finder/config_finder_test.go +++ b/pkg/config-finder/config_finder_test.go @@ -109,7 +109,7 @@ func Test_configFinderFind(t *testing.T) { //nolint:funlen } } -func Test_configFinderFinds(t *testing.T) { //nolint:funlen +func Test_configFinderFinds(t *testing.T) { t.Parallel() data := []struct { name string @@ -150,7 +150,6 @@ func Test_configFinderFinds(t *testing.T) { //nolint:funlen }, exp: []string{ "/home/foo/aqua-2.yaml", - "/home/.aqua.yaml", }, }, } diff --git a/pkg/config/package.go b/pkg/config/package.go index a50b3291f..ab816d22f 100644 --- a/pkg/config/package.go +++ b/pkg/config/package.go @@ -181,7 +181,6 @@ type Param struct { Tags map[string]struct{} ExcludedTags map[string]struct{} OnlyLink bool - IsTest bool All bool Insert bool SelectVersion bool diff --git a/pkg/config/registry/package_info.go b/pkg/config/registry/package_info.go index 8ce13ed1f..5fe035a5d 100644 --- a/pkg/config/registry/package_info.go +++ b/pkg/config/registry/package_info.go @@ -3,6 +3,7 @@ package registry import ( "fmt" "path" + "strings" "github.com/aquaproj/aqua/pkg/runtime" "github.com/iancoleman/orderedmap" @@ -14,7 +15,6 @@ const ( PkgInfoTypeGitHubContent = "github_content" PkgInfoTypeGitHubArchive = "github_archive" PkgInfoTypeHTTP = "http" - PkgInfoTypeGo = "go" PkgInfoTypeGoInstall = "go_install" ) @@ -35,7 +35,6 @@ type PackageInfo struct { FormatOverrides []*FormatOverride `yaml:"format_overrides,omitempty" json:"format_overrides,omitempty"` Files []*File `json:"files,omitempty" yaml:",omitempty"` Replacements Replacements `json:"replacements,omitempty" yaml:",omitempty"` - SupportedIf *string `yaml:"supported_if,omitempty" json:"supported_if,omitempty"` SupportedEnvs SupportedEnvs `yaml:"supported_envs,omitempty" json:"supported_envs,omitempty"` VersionFilter *string `yaml:"version_filter,omitempty" json:"version_filter,omitempty"` VersionPrefix *string `yaml:"version_prefix,omitempty" json:"version_prefix,omitempty"` @@ -71,7 +70,6 @@ func (pkgInfo *PackageInfo) Copy() *PackageInfo { FormatOverrides: pkgInfo.FormatOverrides, VersionConstraints: pkgInfo.VersionConstraints, VersionOverrides: pkgInfo.VersionOverrides, - SupportedIf: pkgInfo.SupportedIf, SupportedEnvs: pkgInfo.SupportedEnvs, VersionFilter: pkgInfo.VersionFilter, VersionPrefix: pkgInfo.VersionPrefix, @@ -106,7 +104,6 @@ func (pkgInfo *PackageInfo) resetByPkgType(typ string) { case PkgInfoTypeHTTP: pkgInfo.Path = nil pkgInfo.Asset = nil - case PkgInfoTypeGo: case PkgInfoTypeGoInstall: pkgInfo.URL = nil pkgInfo.Asset = nil @@ -155,9 +152,6 @@ func (pkgInfo *PackageInfo) overrideVersion(child *VersionOverride) *PackageInfo if child.FormatOverrides != nil { pkg.FormatOverrides = child.FormatOverrides } - if child.SupportedIf != nil { - pkg.SupportedIf = child.SupportedIf - } if child.SupportedEnvs != nil { pkg.SupportedEnvs = child.SupportedEnvs } @@ -275,7 +269,6 @@ type VersionOverride struct { FormatOverrides FormatOverrides `yaml:"format_overrides,omitempty" json:"format_overrides,omitempty"` Overrides Overrides `yaml:",omitempty" json:"overrides,omitempty"` Replacements Replacements `yaml:",omitempty" json:"replacements,omitempty"` - SupportedIf *string `yaml:"supported_if,omitempty" json:"supported_if,omitempty"` SupportedEnvs SupportedEnvs `yaml:"supported_envs,omitempty" json:"supported_envs,omitempty"` VersionFilter *string `yaml:"version_filter,omitempty" json:"version_filter,omitempty"` VersionPrefix *string `yaml:"version_prefix,omitempty" json:"version_prefix,omitempty"` @@ -395,7 +388,7 @@ func (pkgInfo *PackageInfo) GetLink() string { } func (pkgInfo *PackageInfo) GetFormat() string { - if pkgInfo.Type == PkgInfoTypeGitHubArchive || pkgInfo.Type == PkgInfoTypeGo { + if pkgInfo.Type == PkgInfoTypeGitHubArchive { return "tar.gz" } return pkgInfo.Format @@ -440,7 +433,7 @@ func (pkgInfo *PackageInfo) Validate() error { //nolint:cyclop return errPkgNameIsRequired } switch pkgInfo.Type { - case PkgInfoTypeGitHubArchive, PkgInfoTypeGo: + case PkgInfoTypeGitHubArchive: if !pkgInfo.HasRepo() { return errRepoRequired } @@ -479,28 +472,34 @@ func (pkgInfo *PackageInfo) GetFiles() []*File { if len(pkgInfo.Files) != 0 { return pkgInfo.Files } - if pkgInfo.HasRepo() { + + if cmdName := pkgInfo.getDefaultCmdName(); cmdName != "" { return []*File{ { - Name: pkgInfo.RepoName, + Name: cmdName, }, } } + return pkgInfo.Files +} + +func (pkgInfo *PackageInfo) getDefaultCmdName() string { + if pkgInfo.HasRepo() { + if pkgInfo.Name == "" { + return pkgInfo.RepoName + } + if i := strings.LastIndex(pkgInfo.Name, "/"); i != -1 { + return pkgInfo.Name[i+1:] + } + return pkgInfo.Name + } if pkgInfo.Type == PkgInfoTypeGoInstall { if pkgInfo.Asset != nil { - return []*File{ - { - Name: *pkgInfo.Asset, - }, - } - } - return []*File{ - { - Name: path.Base(pkgInfo.GetPath()), - }, + return *pkgInfo.Asset } + return path.Base(pkgInfo.GetPath()) } - return pkgInfo.Files + return "" } func (pkgInfo *PackageInfo) SLSASourceURI() string { diff --git a/pkg/config/registry/package_info_test.go b/pkg/config/registry/package_info_test.go index ed3e86d8d..f6546fb5d 100644 --- a/pkg/config/registry/package_info_test.go +++ b/pkg/config/registry/package_info_test.go @@ -207,7 +207,7 @@ func TestPackageInfo_GetReplacements(t *testing.T) { } } -func TestPackageInfo_GetFiles(t *testing.T) { +func TestPackageInfo_GetFiles(t *testing.T) { //nolint:funlen t.Parallel() data := []struct { title string @@ -248,6 +248,20 @@ func TestPackageInfo_GetFiles(t *testing.T) { RepoName: "ci-info", }, }, + { + title: "has name", + exp: []*registry.File{ + { + Name: "cmctl", + }, + }, + pkgInfo: ®istry.PackageInfo{ + Type: "github_release", + RepoOwner: "cert-manager", + RepoName: "cert-manager", + Name: "cert-manager/cert-manager/cmctl", + }, + }, } for _, d := range data { d := d diff --git a/pkg/config/registry/supported_envs.go b/pkg/config/registry/supported_envs.go index 62c0268ac..9fb09bbb8 100644 --- a/pkg/config/registry/supported_envs.go +++ b/pkg/config/registry/supported_envs.go @@ -1,7 +1,6 @@ package registry import ( - "github.com/aquaproj/aqua/pkg/expr" "github.com/aquaproj/aqua/pkg/runtime" ) @@ -9,10 +8,7 @@ func (pkgInfo *PackageInfo) CheckSupported(rt *runtime.Runtime, env string) (boo if pkgInfo.SupportedEnvs != nil { return pkgInfo.CheckSupportedEnvs(rt.GOOS, rt.GOARCH, env), nil } - if pkgInfo.SupportedIf == nil { - return true, nil - } - return expr.EvaluateSupportedIf(pkgInfo.SupportedIf, rt) //nolint:wrapcheck + return true, nil } func (pkgInfo *PackageInfo) CheckSupportedEnvs(goos, goarch, env string) bool { diff --git a/pkg/controller/updatechecksum/update.go b/pkg/controller/updatechecksum/update.go index 12c97020d..70fad3671 100644 --- a/pkg/controller/updatechecksum/update.go +++ b/pkg/controller/updatechecksum/update.go @@ -32,7 +32,6 @@ type Controller struct { chkDL download.ChecksumDownloader parser *checksum.FileParser downloader download.ClientAPI - deep bool prune bool } @@ -48,7 +47,6 @@ func New(param *config.Param, configFinder ConfigFinder, configReader reader.Con chkDL: chkDL, parser: &checksum.FileParser{}, downloader: pkgDownloader, - deep: param.Deep, prune: param.Prune, } } @@ -239,10 +237,6 @@ func (ctrl *Controller) getChecksum(ctx context.Context, logE *logrus.Entry, che pkgInfo := pkg.PackageInfo if !pkg.PackageInfo.Checksum.GetEnabled() { - if !ctrl.deep { - logE.Debug("chekcsum isn't supported") - return nil - } if err := ctrl.dlAssetAndGetChecksum(ctx, logE, checksums, pkg, rt); err != nil { return err } diff --git a/pkg/controller/updatechecksum/update_test.go b/pkg/controller/updatechecksum/update_test.go index 437e984a3..4d6c31d33 100644 --- a/pkg/controller/updatechecksum/update_test.go +++ b/pkg/controller/updatechecksum/update_test.go @@ -90,66 +90,6 @@ func TestController_UpdateChecksum(t *testing.T) { //nolint:funlen repo_owner: cli repo_name: cli asset: gh_{{trimV .Version}}_{{.OS}}_{{.Arch}}.{{.Format}} -`, - }, - }, - fs: afero.NewMemMapFs(), - rt: &runtime.Runtime{ - GOOS: "darwin", - GOARCH: "arm64", - }, - chkDL: &download.MockChecksumDownloader{}, - downloader: &download.Mock{}, - }, - { - name: "deep", - param: &config.Param{ - PWD: "/home/foo/workspace", - Deep: true, - All: true, - GlobalConfigFilePaths: []string{ - "/home/foo/global/aqua.yaml", - }, - }, - cfgFinder: &updatechecksum.MockConfigFinder{ - Files: []string{ - "/home/foo/workspace/aqua.yaml", - }, - }, - cfgReader: &reader.MockConfigReader{ - Cfg: &aqua.Config{ - Checksum: &aqua.Checksum{ - Enabled: boolP(true), - }, - Packages: []*aqua.Package{ - { - Name: "cli/cli", - Version: "v2.17.0", - Registry: "standard", - }, - }, - }, - }, - registInstaller: &rgst.MockInstaller{ - M: map[string]*registry.Config{ - "standard": { - PackageInfos: registry.PackageInfos{ - { - RepoOwner: "cli", - RepoName: "cli", - Type: "github_release", - Asset: strP("gh_{{trimV .Version}}_{{.OS}}_{{.Arch}}.{{.Format}}"), - }, - }, - }, - }, - }, - registDownloader: &domain.MockGitHubContentFileDownloader{ - File: &domain.GitHubContentFile{ - String: `type: github_release -repo_owner: cli -repo_name: cli -asset: gh_{{trimV .Version}}_{{.OS}}_{{.Arch}}.{{.Format}} `, }, }, diff --git a/pkg/controller/which/which_test.go b/pkg/controller/which/which_test.go index ffcda570d..371187610 100644 --- a/pkg/controller/which/which_test.go +++ b/pkg/controller/which/which_test.go @@ -177,7 +177,6 @@ packages: repo_owner: suzuki-shunsuke repo_name: ci-info asset: "ci-info_{{.Arch}}-{{.OS}}.tar.gz" - supported_if: "false" - type: github_release repo_owner: suzuki-shunsuke repo_name: github-comment diff --git a/pkg/exec/exec.go b/pkg/exec/exec.go index b4bc4d6b4..1381b1de0 100644 --- a/pkg/exec/exec.go +++ b/pkg/exec/exec.go @@ -59,12 +59,6 @@ func (exe *Executor) ExecWithEnvsAndGetCombinedOutput(ctx context.Context, exePa return out.String(), code, err } -func (exe *Executor) GoBuild(ctx context.Context, exePath, src, exeDir string) (int, error) { - cmd := exe.command(exec.Command("go", "build", "-o", exePath, src)) - cmd.Dir = exeDir - return exe.exec(ctx, cmd) -} - func (exe *Executor) GoInstall(ctx context.Context, path, gobin string) (int, error) { cmd := exe.command(exec.Command("go", "install", path)) cmd.Env = append(os.Environ(), "GOBIN="+gobin) diff --git a/pkg/exec/mock.go b/pkg/exec/mock.go index c2c166ced..c1813e7b8 100644 --- a/pkg/exec/mock.go +++ b/pkg/exec/mock.go @@ -26,10 +26,6 @@ func (exe *Mock) ExecXSys(exePath string, args []string) error { return exe.Err } -func (exe *Mock) GoBuild(ctx context.Context, exePath, src, exeDir string) (int, error) { - return exe.ExitCode, exe.Err -} - func (exe *Mock) GoInstall(ctx context.Context, path, gobin string) (int, error) { return exe.ExitCode, exe.Err } diff --git a/pkg/expr/package_condition.go b/pkg/expr/package_condition.go deleted file mode 100644 index 13d19ce98..000000000 --- a/pkg/expr/package_condition.go +++ /dev/null @@ -1,18 +0,0 @@ -package expr - -import ( - "github.com/aquaproj/aqua/pkg/runtime" -) - -func EvaluateSupportedIf(supportedIf *string, rt *runtime.Runtime) (bool, error) { - if supportedIf == nil { - return true, nil - } - return evaluateBool(*supportedIf, map[string]interface{}{ - "GOOS": "", - "GOARCH": "", - }, map[string]interface{}{ - "GOOS": rt.GOOS, - "GOARCH": rt.GOARCH, - }) -} diff --git a/pkg/expr/package_condition_test.go b/pkg/expr/package_condition_test.go deleted file mode 100644 index 00e07cb10..000000000 --- a/pkg/expr/package_condition_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package expr_test - -import ( - "testing" - - "github.com/aquaproj/aqua/pkg/expr" - "github.com/aquaproj/aqua/pkg/runtime" -) - -func TestEvaluateSupportedIf(t *testing.T) { - t.Parallel() - data := []struct { - title string - supportedIf string - rt *runtime.Runtime - exp bool - isErr bool - }{ - { - title: "true", - supportedIf: `GOOS == "linux"`, - rt: &runtime.Runtime{ - GOOS: "linux", - GOARCH: "amd64", - }, - exp: true, - }, - } - - for _, d := range data { - d := d - t.Run(d.title, func(t *testing.T) { - t.Parallel() - b, err := expr.EvaluateSupportedIf(&d.supportedIf, d.rt) - if d.isErr { - if err == nil { - t.Fatal("err should be returned") - } - return - } - if err != nil { - t.Fatal(err) - } - if b != d.exp { - t.Fatalf("wanted %v, got %v", d.exp, b) - } - }) - } -} diff --git a/pkg/expr/version_compare.go b/pkg/expr/version_compare.go new file mode 100644 index 000000000..3972865f2 --- /dev/null +++ b/pkg/expr/version_compare.go @@ -0,0 +1,79 @@ +package expr + +import ( + "strings" + + "github.com/hashicorp/go-version" +) + +type Compare struct { + op string + compare func(*version.Version) bool +} + +func comparisons(sv1 *version.Version) []*Compare { + return []*Compare{ + { + op: ">=", + compare: sv1.GreaterThanOrEqual, + }, + { + op: "<=", + compare: sv1.LessThanOrEqual, + }, + { + op: "!=", + compare: func(v *version.Version) bool { + return !sv1.Equal(v) + }, + }, + { + op: ">", + compare: sv1.GreaterThan, + }, + { + op: "<", + compare: sv1.LessThan, + }, + { + op: "=", + compare: sv1.Equal, + }, + } +} + +func getCompareFunc(v string) func(s string) bool { + return func(s string) bool { + return compare(s, v) + } +} + +func compare(constr, ver string) bool { + sv1, err := version.NewVersion(ver) + if err != nil { + panic(err) + } + for _, constraint := range strings.Split(strings.TrimSpace(constr), ",") { + c := strings.TrimSpace(constraint) + matched := false + for _, comp := range comparisons(sv1) { + s := strings.TrimPrefix(c, comp.op) + if s == c { + continue + } + sv2, err := version.NewVersion(strings.TrimSpace(s)) + if err != nil { + panic(err) + } + if !comp.compare(sv2) { + return false + } + matched = true + break + } + if !matched { + panic("invalid operator. Operator must be one of >=, >, <, <=, !=, =") + } + } + return true +} diff --git a/pkg/expr/version_constraint.go b/pkg/expr/version_constraint.go index f6ce8a5c0..10c686a67 100644 --- a/pkg/expr/version_constraint.go +++ b/pkg/expr/version_constraint.go @@ -2,52 +2,27 @@ package expr import ( "strings" - - "github.com/hashicorp/go-version" ) -func emptyTrimPrefix(string, string) string { - return "" -} - func emptySemver(s string) bool { return false } -func emptySemverWithVersion(constr, ver string) bool { - return false -} - -func getSemverFunc(v string) func(s string) bool { - return func(s string) bool { - return semverWithVersion(s, v) - } -} - -func semverWithVersion(constr, ver string) bool { - a, err := version.NewConstraint(constr) - if err != nil { - panic(err) - } - v, err := version.NewVersion(ver) - if err != nil { - panic(err) - } - return a.Check(v) -} - func EvaluateVersionConstraints(constraint, v, semver string) (bool, error) { return evaluateBool(constraint, map[string]interface{}{ "Version": "", "SemVer": "", "semver": emptySemver, - "semverWithVersion": emptySemverWithVersion, - "trimPrefix": emptyTrimPrefix, - }, map[string]interface{}{ - "Version": v, - "SemVer": semver, - "semver": getSemverFunc(semver), - "semverWithVersion": semverWithVersion, + "semverWithVersion": compare, "trimPrefix": strings.TrimPrefix, + }, map[string]interface{}{ + "Version": v, + + "SemVer": semver, + + "semver": getCompareFunc(semver), + "semverWithVersion": compare, + + "trimPrefix": strings.TrimPrefix, }) } diff --git a/pkg/expr/version_filter.go b/pkg/expr/version_filter.go index ef8218d37..1c444a95e 100644 --- a/pkg/expr/version_filter.go +++ b/pkg/expr/version_filter.go @@ -11,8 +11,8 @@ func CompileVersionFilter(versionFilter string) (*vm.Program, error) { return expr.Compile(versionFilter, expr.AsBool(), expr.Env(map[string]interface{}{ //nolint:wrapcheck "Version": "", "semver": emptySemver, - "semverWithVersion": emptySemverWithVersion, - "trimPrefix": emptyTrimPrefix, + "semverWithVersion": compare, + "trimPrefix": strings.TrimPrefix, })) } @@ -20,8 +20,8 @@ func CompileVersionFilterForTest(versionFilter string) *vm.Program { p, err := expr.Compile(versionFilter, expr.AsBool(), expr.Env(map[string]interface{}{ "Version": "", "semver": emptySemver, - "semverWithVersion": emptySemverWithVersion, - "trimPrefix": emptyTrimPrefix, + "semverWithVersion": compare, + "trimPrefix": strings.TrimPrefix, })) if err != nil { panic(err) @@ -32,8 +32,8 @@ func CompileVersionFilterForTest(versionFilter string) *vm.Program { func EvaluateVersionFilter(prog *vm.Program, v string) (bool, error) { return evaluateBoolProg(prog, map[string]interface{}{ "Version": v, - "semver": getSemverFunc(v), - "semverWithVersion": semverWithVersion, + "semver": getCompareFunc(v), + "semverWithVersion": compare, "trimPrefix": strings.TrimPrefix, }) } diff --git a/pkg/installpackage/aqua_test.go b/pkg/installpackage/aqua_test.go index eec696c92..a8b6404a5 100644 --- a/pkg/installpackage/aqua_test.go +++ b/pkg/installpackage/aqua_test.go @@ -41,7 +41,9 @@ func Test_installer_InstallAqua(t *testing.T) { //nolint:funlen param: &config.Param{ RootDir: "/home/foo/.local/share/aquaproj-aqua", }, - files: map[string]string{}, + files: map[string]string{ + "/home/foo/.local/share/aquaproj-aqua/pkgs/github_release/github.com/aquaproj/aqua/v1.6.1/aqua_linux_amd64.tar.gz/aqua": "xxx", + }, version: "v1.6.1", checksumCalculator: &installpackage.MockChecksumCalculator{ Checksum: "c6f3b1f37d9bf4f73e6c6dcf1bd4bb59b48447ad46d4b72e587d15f66a96ab5a", diff --git a/pkg/installpackage/download.go b/pkg/installpackage/download.go index 59b533331..312709189 100644 --- a/pkg/installpackage/download.go +++ b/pkg/installpackage/download.go @@ -164,7 +164,7 @@ func (inst *InstallerImpl) download(ctx context.Context, logE *logrus.Entry, par paramVerifyChecksum.ChecksumID = cid // Even if SLSA Provenance is enabled checksum verification is run paramVerifyChecksum.Checksum = param.Checksums.Get(cid) - if paramVerifyChecksum.Checksum == nil && !pkgInfo.Checksum.GetEnabled() && param.RequireChecksum { + if paramVerifyChecksum.Checksum == nil && param.RequireChecksum { return logerr.WithFields(errChecksumIsRequired, logrus.Fields{ //nolint:wrapcheck "doc": "https://aquaproj.github.io/docs/reference/codes/001", }) diff --git a/pkg/installpackage/installer.go b/pkg/installpackage/installer.go index 6adc32da4..81ed91498 100644 --- a/pkg/installpackage/installer.go +++ b/pkg/installpackage/installer.go @@ -45,7 +45,6 @@ type InstallerImpl struct { slsaVerifier slsa.Verifier progressBar bool onlyLink bool - isTest bool copyDir string policyChecker policy.Checker cosignInstaller *Cosign @@ -78,7 +77,6 @@ func newInstaller(param *config.Param, downloader download.ClientAPI, rt *runtim linker: linker, executor: executor, progressBar: param.ProgressBar, - isTest: param.IsTest, onlyLink: param.OnlyLink, copyDir: param.Dest, unarchiver: unarchiver, @@ -199,7 +197,7 @@ func (inst *InstallerImpl) InstallPackages(ctx context.Context, logE *logrus.Ent return nil } -func (inst *InstallerImpl) InstallPackage(ctx context.Context, logE *logrus.Entry, param *ParamInstallPackage) error { //nolint:cyclop,funlen,gocognit +func (inst *InstallerImpl) InstallPackage(ctx context.Context, logE *logrus.Entry, param *ParamInstallPackage) error { //nolint:cyclop,funlen pkg := param.Pkg checksums := param.Checksums pkgInfo := pkg.PackageInfo @@ -257,22 +255,16 @@ func (inst *InstallerImpl) InstallPackage(ctx context.Context, logE *logrus.Entr failed := false notFound := false - logLevel := logrus.WarnLevel - if inst.isTest { - logLevel = logrus.ErrorLevel - } for _, file := range pkgInfo.GetFiles() { file := file logE := logE.WithField("file_name", file.Name) var errFileNotFound *FileNotFoundError - if err := inst.checkAndCopyFile(ctx, pkg, file, logE); err != nil { + if err := inst.checkAndCopyFile(pkg, file, logE); err != nil { if errors.As(err, &errFileNotFound) { notFound = true } - if inst.isTest { - failed = true - } - logerr.WithError(logE, err).Log(logLevel, "check file_src is correct") + failed = true + logerr.WithError(logE, err).Error("check file_src is correct") } } if notFound { //nolint:nestif @@ -281,9 +273,9 @@ func (inst *InstallerImpl) InstallPackage(ctx context.Context, logE *logrus.Entr logerr.WithError(logE, err).Warn("traverse the content of unarchived package") } else { if len(paths) > 30 { //nolint:gomnd - logE.Logf(logLevel, "executable files aren't found\nFiles in the unarchived package (Only 30 files are shown):\n%s\n ", strings.Join(paths[:30], "\n")) + logE.Errorf("executable files aren't found\nFiles in the unarchived package (Only 30 files are shown):\n%s\n ", strings.Join(paths[:30], "\n")) } else { - logE.Logf(logLevel, "executable files aren't found\nFiles in the unarchived package:\n%s\n ", strings.Join(paths, "\n")) + logE.Errorf("executable files aren't found\nFiles in the unarchived package:\n%s\n ", strings.Join(paths, "\n")) } } } @@ -327,36 +319,8 @@ type DownloadParam struct { RequireChecksum bool } -func (inst *InstallerImpl) checkFileSrcGo(ctx context.Context, pkg *config.Package, file *registry.File, logE *logrus.Entry) (string, error) { - pkgInfo := pkg.PackageInfo - exePath := filepath.Join(inst.rootDir, "pkgs", pkgInfo.GetType(), "github.com", pkgInfo.RepoOwner, pkgInfo.RepoName, pkg.Package.Version, "bin", file.Name) - if isWindows(inst.runtime.GOOS) { - exePath += ".exe" - } - dir, err := pkg.RenderDir(file, inst.runtime) - if err != nil { - return "", fmt.Errorf("render file dir: %w", err) - } - exeDir := filepath.Join(inst.rootDir, "pkgs", pkgInfo.GetType(), "github.com", pkgInfo.RepoOwner, pkgInfo.RepoName, pkg.Package.Version, "src", dir) - if _, err := inst.fs.Stat(exePath); err == nil { - return exePath, nil - } - src := file.Src - if src == "" { - src = "." - } - logE.WithFields(logrus.Fields{ - "go_src": src, - "go_build_dir": exeDir, - }).Info("building Go tool") - if _, err := inst.executor.GoBuild(ctx, exePath, src, exeDir); err != nil { - return "", fmt.Errorf("build Go tool: %w", err) - } - return exePath, nil -} - -func (inst *InstallerImpl) checkAndCopyFile(ctx context.Context, pkg *config.Package, file *registry.File, logE *logrus.Entry) error { - exePath, err := inst.checkFileSrc(ctx, pkg, file, logE) +func (inst *InstallerImpl) checkAndCopyFile(pkg *config.Package, file *registry.File, logE *logrus.Entry) error { + exePath, err := inst.checkFileSrc(pkg, file, logE) if err != nil { return fmt.Errorf("check file_src is correct: %w", err) } @@ -371,11 +335,7 @@ func (inst *InstallerImpl) checkAndCopyFile(ctx context.Context, pkg *config.Pac return nil } -func (inst *InstallerImpl) checkFileSrc(ctx context.Context, pkg *config.Package, file *registry.File, logE *logrus.Entry) (string, error) { - if pkg.PackageInfo.Type == "go" { - return inst.checkFileSrcGo(ctx, pkg, file, logE) - } - +func (inst *InstallerImpl) checkFileSrc(pkg *config.Package, file *registry.File, logE *logrus.Entry) (string, error) { pkgPath, err := pkg.GetPkgPath(inst.rootDir, inst.runtime) if err != nil { return "", fmt.Errorf("get the package install path: %w", err) diff --git a/pkg/installpackage/installer_test.go b/pkg/installpackage/installer_test.go index 684bf568b..fb641a618 100644 --- a/pkg/installpackage/installer_test.go +++ b/pkg/installpackage/installer_test.go @@ -68,11 +68,6 @@ func Test_installer_InstallPackages(t *testing.T) { //nolint:funlen Registry: "standard", Version: "v2.0.3", }, - { - Name: "suzuki-shunsuke/github-comment", - Registry: "standard", - Version: "v4.1.0", - }, }, }, registries: map[string]*registry.Config{ @@ -84,13 +79,6 @@ func Test_installer_InstallPackages(t *testing.T) { //nolint:funlen RepoName: "ci-info", Asset: stringP("ci-info_{{trimV .Version}}_{{.OS}}_amd64.tar.gz"), }, - { - Type: "github_release", - RepoOwner: "suzuki-shunsuke", - RepoName: "github-comment", - Asset: stringP("github-comment_{{trimV .Version}}_{{.OS}}_amd64.tar.gz"), - SupportedIf: stringP("false"), - }, }, }, }, diff --git a/pkg/installpackage/public.go b/pkg/installpackage/public.go index 9e4fe84e3..05f0af159 100644 --- a/pkg/installpackage/public.go +++ b/pkg/installpackage/public.go @@ -5,6 +5,5 @@ import ( ) type Executor interface { - GoBuild(ctx context.Context, exePath, src, exeDir string) (int, error) GoInstall(ctx context.Context, path, gobin string) (int, error) } diff --git a/pkg/policy/config_reader.go b/pkg/policy/config_reader.go index 7de8364a7..a6a049b06 100644 --- a/pkg/policy/config_reader.go +++ b/pkg/policy/config_reader.go @@ -32,6 +32,9 @@ func (reader *MockConfigReader) Read(files []string) ([]*Config, error) { } func (reader *ConfigReaderImpl) Read(files []string) ([]*Config, error) { + if len(files) == 0 { + return reader.readDefault() + } policyCfgs := make([]*Config, len(files)) for i, cfgFilePath := range files { policyCfg := &Config{ @@ -46,6 +49,31 @@ func (reader *ConfigReaderImpl) Read(files []string) ([]*Config, error) { return policyCfgs, nil } +func (reader *ConfigReaderImpl) readDefault() ([]*Config, error) { + // https://github.com/aquaproj/aqua/issues/1404 + // If no policy file is set, only standard registry is allowed by default. + cfg := &Config{ + YAML: &ConfigYAML{ + Registries: []*Registry{ + { + Type: "standard", + }, + }, + Packages: []*Package{ + { + RegistryName: "standard", + }, + }, + }, + } + if err := cfg.Init(); err != nil { + return nil, err + } + return []*Config{ + cfg, + }, nil +} + func (reader *ConfigReaderImpl) read(cfg *Config) error { file, err := reader.fs.Open(cfg.Path) if err != nil { diff --git a/tests/cosign/aqua.yaml b/tests/cosign/aqua.yaml index efebb093e..6486bec73 100644 --- a/tests/cosign/aqua.yaml +++ b/tests/cosign/aqua.yaml @@ -4,6 +4,7 @@ checksum: # https://aquaproj.github.io/docs/reference/checksum/ enabled: true + require_checksum: false registries: - type: standard ref: v3.147.0 # renovate: depName=aquaproj/aqua-registry diff --git a/tests/main/aqua-global.yaml b/tests/main/aqua-global.yaml index c1bcb8774..c7fc6ae22 100644 --- a/tests/main/aqua-global.yaml +++ b/tests/main/aqua-global.yaml @@ -11,13 +11,7 @@ registries: repo_name: aqua-registry path: registry.yaml packages: -- name: cmdx - registry: local - version: v1.6.1 # renovate: depName=suzuki-shunsuke/cmdx - name: x-motemen/ghq@v1.3.0 -- name: golangci-lint # local registry - registry: local - version: v1.50.1 # renovate: depName=golangci/golangci-lint - name: kubernetes-sigs/kind # http package, raw format registry: standard # standard registry version: v0.17.0 # renovate: depName=kubernetes-sigs/kind @@ -35,23 +29,6 @@ packages: - name: tfutils/tfenv@v3.0.0 # github_archive package registry: local -- name: containerd/nerdctl@v1.0.0 - # supported_if - registry: local -- name: aristocratos/btop@v1.2.12 - # replacements_overrides - registry: local -- name: ahmetb/kubens - # alias - registry: local - version: v0.9.4 # renovate: depName=ahmetb/kubectx -- name: google/wire@v0.5.0 - # type: go - registry: local -- name: mitchellh/gox - registry: local - # specify revision - version: 8c3b2b9e647dc52457d6ee7b5adcf97e2bafe131 - name: katbyte/terrafmt@v0.5.2 # type: go_install registry: local diff --git a/tests/main/aqua.yaml b/tests/main/aqua.yaml index 3746d3f79..dfc61e8f5 100644 --- a/tests/main/aqua.yaml +++ b/tests/main/aqua.yaml @@ -1,5 +1,6 @@ checksum: enabled: true + require_checksum: false registries: - type: standard type: standard # duplicated keys diff --git a/tests/main/registry.yaml b/tests/main/registry.yaml index bdc629aa0..89862a69f 100644 --- a/tests/main/registry.yaml +++ b/tests/main/registry.yaml @@ -1,13 +1,4 @@ packages: - - name: golangci-lint - type: github_release - repo_owner: golangci - repo_name: golangci-lint - asset: 'golangci-lint-{{trimV .Version}}-{{.OS}}-{{.Arch}}.tar.gz' - files: - - name: golangci-lint - src: 'golangci-lint-{{trimV .Version}}-{{.OS}}-{{.Arch}}/golangci-lint' - - type: github_release repo_owner: kubernetes-sigs repo_name: kustomize @@ -31,17 +22,6 @@ packages: files: - name: kustomize - - name: cmdx - type: github_release - repo_owner: suzuki-shunsuke - repo_name: cmdx - rosetta2: true - asset: 'cmdx_{{.OS}}_{{.Arch}}.tar.gz' - version_constraint: 'semver(">= 1.6.1")' - version_overrides: - - version_constraint: 'semver("< 1.6.1")' - asset: 'cmdx_{{trimV .Version}}_{{.OS}}_{{.Arch}}.tar.gz' - - type: github_content # github_content package repo_owner: aquaproj repo_name: aqua-installer @@ -56,72 +36,6 @@ packages: - name: terraform src: tfenv-{{trimV .Version}}/bin/terraform - - type: github_release - repo_owner: containerd - repo_name: nerdctl - asset: 'nerdctl-{{trimV .Version}}-{{.OS}}-{{.Arch}}.tar.gz' - supported_if: GOOS != "darwin" # supported_if - - - type: github_release - repo_owner: aristocratos - repo_name: btop - asset: 'btop-{{.Arch}}-{{.OS}}.tbz' - format: tar.bz2 - description: 'A monitor of resources' - replacements: - linux: linux-musl - darwin: macos-monterey - amd64: x86_64 - overrides: - - goos: linux - goarch: arm64 - replacements: - arm64: aarch64 - files: - - name: btop - src: bin/btop - - - name: ahmetb/kubectx/kubens - aliases: - - name: ahmetb/kubens - type: github_release - repo_owner: ahmetb - repo_name: kubectx - asset: "kubens_{{.Version}}_{{.OS}}_{{.Arch}}.{{.Format}}" - description: Faster way to switch between clusters and namespaces in kubectl - search_words: - # search_words - - namespace - files: - - name: kubens - replacements: - 386: i386 - amd64: x86_64 - format: tar.gz - format_overrides: - - goos: windows - format: zip - - # Go - - type: go - repo_owner: google - repo_name: wire - description: Compile-time Dependency Injection for Go - files: - - name: wire - src: ./cmd/wire - dir: "wire-{{trimV .Version}}" - - # version_source: github_tag - - type: go - repo_owner: mitchellh - repo_name: gox - description: A dead simple, no frills Go cross compile tool - version_source: github_tag - files: - - name: gox - dir: "gox-{{trimV .Version}}" - - type: go_install path: github.com/anqiansong/github-compare description: A GitHub repositories statistics command-line tool for the terminal diff --git a/tests/slsa/aqua.yaml b/tests/slsa/aqua.yaml index 01d15df2f..e6e0ab0d4 100644 --- a/tests/slsa/aqua.yaml +++ b/tests/slsa/aqua.yaml @@ -4,6 +4,7 @@ checksum: # https://aquaproj.github.io/docs/reference/checksum/ enabled: true + require_checksum: false registries: - type: standard ref: v3.147.0 # renovate: depName=aquaproj/aqua-registry diff --git a/tests/slsa/registry.yaml b/tests/slsa/registry.yaml index 9c65fc70a..fbcdca02d 100644 --- a/tests/slsa/registry.yaml +++ b/tests/slsa/registry.yaml @@ -5,6 +5,9 @@ packages: repo_owner: suzuki-shunsuke repo_name: test-cosign-keyless-aqua asset: aqua_{{.OS}}_{{.Arch}}.tar.gz + files: + - name: test-cosign-keyless-aqua + src: aqua slsa_provenance: type: github_release asset: multiple.intoto.jsonl