From efdd652f09a3cb2a4471b70a052fd02e24876086 Mon Sep 17 00:00:00 2001 From: Lorenzo Susini Date: Thu, 2 Nov 2023 16:53:08 +0000 Subject: [PATCH] update(build): create new engine_version_semver string for new plugin rulesfiles artifact configs Signed-off-by: Lorenzo Susini --- build/registry/pkg/common/consts.go | 2 +- build/registry/pkg/oci/requirements.go | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/build/registry/pkg/common/consts.go b/build/registry/pkg/common/consts.go index 6034b1dd..3441c619 100644 --- a/build/registry/pkg/common/consts.go +++ b/build/registry/pkg/common/consts.go @@ -21,7 +21,7 @@ const ( RulesArtifactSuffix = "-rules" // EngineVersionKey is the name given to all the engine requirements. // The same name used by Falco when outputting the engine version. - EngineVersionKey = "engine_version" + EngineVersionKey = "engine_version_semver" // PluginAPIVersion is the name givet to the plugin api version requirements. // The same name used by Falco when outputting the plugin api version PluginAPIVersion = "plugin_api_version" diff --git a/build/registry/pkg/oci/requirements.go b/build/registry/pkg/oci/requirements.go index b605ef43..e70689b6 100644 --- a/build/registry/pkg/oci/requirements.go +++ b/build/registry/pkg/oci/requirements.go @@ -65,15 +65,24 @@ func rulesfileRequirement(filePath string) (*oci.ArtifactRequirement, error) { } // Split the requirement and parse the version to semVer. + // In case the requirement was expressed as a numeric value, + // we convert it to semver and treat it as minor version. + var version string tokens := strings.Split(fileScanner.Text(), ":") - reqVer, err := semver.ParseTolerant(tokens[1]) + reqVer, err := semver.Parse(tokens[1]) if err != nil { - return nil, fmt.Errorf("unable to parse to semVer the version requirement %q", tokens[1]) + reqVer = semver.ParseTolerant(tokens[1]) + if err != nil { + return nil, fmt.Errorf("unable to parse requirement %q: %w", tokens[1], err) + } + version = "0." + strconv.FormatUint(reqVer.Major, 10) + ".0" + } else { + version = reqVer.String() } return &oci.ArtifactRequirement{ Name: common.EngineVersionKey, - Version: strconv.FormatUint(reqVer.Major, 10), + Version: version, }, nil }