diff --git a/changes/40751-google-drive-brew-version b/changes/40751-google-drive-brew-version new file mode 100644 index 0000000000..bf6ad980df --- /dev/null +++ b/changes/40751-google-drive-brew-version @@ -0,0 +1 @@ +- Fix Google Drive version not matching upstream diff --git a/ee/maintained-apps/ingesters/homebrew/external_refs/google_drive_version_shortener.go b/ee/maintained-apps/ingesters/homebrew/external_refs/google_drive_version_shortener.go new file mode 100644 index 0000000000..d547a61a59 --- /dev/null +++ b/ee/maintained-apps/ingesters/homebrew/external_refs/google_drive_version_shortener.go @@ -0,0 +1,21 @@ +package externalrefs + +import ( + "strings" + + maintained_apps "github.com/fleetdm/fleet/v4/ee/maintained-apps" +) + +func GoogleDriveVersionShortener(app *maintained_apps.FMAManifestApp) (*maintained_apps.FMAManifestApp, error) { + homebrewVersion := app.Version + + // If the google drive version has three or more places, remove all but two + // https://github.com/fleetdm/fleet/issues/40751 + if strings.Count(homebrewVersion, ".") > 1 { + split := strings.Split(homebrewVersion, ".") + shortVersion := strings.Join(split[0:2], ".") + app.Version = shortVersion + } + + return app, nil +} diff --git a/ee/maintained-apps/ingesters/homebrew/external_refs/google_drive_version_shortener_test.go b/ee/maintained-apps/ingesters/homebrew/external_refs/google_drive_version_shortener_test.go new file mode 100644 index 0000000000..73eb83d5ef --- /dev/null +++ b/ee/maintained-apps/ingesters/homebrew/external_refs/google_drive_version_shortener_test.go @@ -0,0 +1,49 @@ +package externalrefs + +import ( + "testing" + + maintained_apps "github.com/fleetdm/fleet/v4/ee/maintained-apps" + "github.com/stretchr/testify/assert" +) + +func TestGoogleDriveVersionShortener(t *testing.T) { + tcs := []struct { + Name string + Version string + Expected string + }{ + { + Name: "no subversion", + Version: "123", + Expected: "123", + }, + { + Name: "one subversion", + Version: "123.45", + Expected: "123.45", + }, + { + Name: "two subversion", + Version: "123.45.67", + Expected: "123.45", + }, + { + Name: "three subversions", + Version: "123.45.67.89", + Expected: "123.45", + }, + } + + for _, tc := range tcs { + t.Run(tc.Name, func(t *testing.T) { + fma := &maintained_apps.FMAManifestApp{ + Version: tc.Version, + } + fma2, err := GoogleDriveVersionShortener(fma) + assert.Equal(t, tc.Expected, fma.Version) + assert.Equal(t, tc.Expected, fma2.Version) + assert.NoError(t, err) + }) + } +} diff --git a/ee/maintained-apps/ingesters/homebrew/external_refs/main.go b/ee/maintained-apps/ingesters/homebrew/external_refs/main.go index 8809d586b8..008b9cd0a5 100644 --- a/ee/maintained-apps/ingesters/homebrew/external_refs/main.go +++ b/ee/maintained-apps/ingesters/homebrew/external_refs/main.go @@ -12,6 +12,7 @@ var Funcs = map[string][]func(*maintained_apps.FMAManifestApp) (*maintained_apps "brave-browser/darwin": {BraveVersionTransformer}, "whatsapp/darwin": {WhatsAppVersionShortener, WhatsAppInstallerURL}, "google-chrome/darwin": {ChromePKGInstaller}, + "google-drive/darwin": {GoogleDriveVersionShortener}, "1password/darwin": {OnePasswordPKGInstaller}, "zoom/darwin": {ZoomPKGInstaller}, "slack/darwin": {SlackPKGInstaller},