diff --git a/pkg/extension/sumologicextension/extension.go b/pkg/extension/sumologicextension/extension.go index 12211eb3c7..0ec91ebbef 100644 --- a/pkg/extension/sumologicextension/extension.go +++ b/pkg/extension/sumologicextension/extension.go @@ -1064,12 +1064,19 @@ func getHostname(logger *zap.Logger) (string, error) { // cleaned up. All other version formats will remain the same. // Cleaned up format: 0.108.0-sumo-2-4d57200692d5c5c39effad4ae3b29fef79209113 func cleanupBuildVersion(version string) string { - pattern := "(^[0-9]+\\.[0-9]+\\.[0-9]+-sumo-[0-9]+)-[0-9a-f]{40}$" + pattern := "^v?([0-9]+\\.[0-9]+\\.[0-9]+-sumo-[0-9]+)(-[0-9a-f]{40}){0,1}(-fips){0,1}$" re := regexp.MustCompile(pattern) - sm := re.FindAllStringSubmatch(version, 1) - if len(sm) == 1 { - ver := sm[0][1] + matches := re.FindAllStringSubmatch(version, 1) + if len(matches) != 1 { + return version + } + subMatches := matches[0] + if len(subMatches) > 1 { + ver := subMatches[1] + if len(subMatches) == 4 { + ver += subMatches[3] + } return "v" + ver } diff --git a/pkg/extension/sumologicextension/extension_test.go b/pkg/extension/sumologicextension/extension_test.go index bbe20d5a07..6e5e36aac6 100644 --- a/pkg/extension/sumologicextension/extension_test.go +++ b/pkg/extension/sumologicextension/extension_test.go @@ -1604,17 +1604,53 @@ func Test_cleanupBuildVersion(t *testing.T) { want string }{ { + name: "already ok", + args: args{version: "0.108.0-sumo-2"}, + want: "v0.108.0-sumo-2", + }, { + name: "no hash fips", + args: args{version: "0.108.0-sumo-2-fips"}, + want: "v0.108.0-sumo-2-fips", + }, { name: "with hash", args: args{version: "0.108.0-sumo-2-4d57200692d5c5c39effad4ae3b29fef79209113"}, want: "v0.108.0-sumo-2", }, { - name: "already ok", + name: "hash fips", + args: args{version: "0.108.0-sumo-2-4d57200692d5c5c39effad4ae3b29fef79209113-fips"}, + want: "v0.108.0-sumo-2-fips", + }, { + name: "v already ok", args: args{version: "v0.108.0-sumo-2"}, want: "v0.108.0-sumo-2", }, { - name: "non v", - args: args{version: "0.108.0-sumo-2"}, - want: "0.108.0-sumo-2", + name: "v no hash fips", + args: args{version: "v0.108.0-sumo-2-fips"}, + want: "v0.108.0-sumo-2-fips", + }, { + name: "v with hash", + args: args{version: "v0.108.0-sumo-2-4d57200692d5c5c39effad4ae3b29fef79209113"}, + want: "v0.108.0-sumo-2", + }, { + name: "v hash fips", + args: args{version: "v0.108.0-sumo-2-4d57200692d5c5c39effad4ae3b29fef79209113-fips"}, + want: "v0.108.0-sumo-2-fips", + }, { + name: "no patch version", + args: args{version: "0.108-sumo-2"}, + want: "0.108-sumo-2", + }, { + name: "v no patch version", + args: args{version: "v0.108-sumo-2"}, + want: "v0.108-sumo-2", + }, { + name: "no sumo version", + args: args{version: "0.108-0-sumo"}, + want: "0.108-0-sumo", + }, { + name: "v no patch version", + args: args{version: "v0.108-0-sumo"}, + want: "v0.108-0-sumo", }, { name: "nonsense", args: args{version: "hfiwe-23rhc8eg.fhf"},