From adc608ea6cc46ab197cda0facd6a62a00ffcc67c Mon Sep 17 00:00:00 2001 From: Roberto Dip Date: Wed, 10 Jul 2024 12:25:10 -0300 Subject: [PATCH] add bundle_identifier to software titles responses (#20298) final bit for #19144, doc changes will be made separately # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Added/updated tests - [x] Manual QA for all new/changed functionality --- server/datastore/mysql/software_titles.go | 2 ++ .../datastore/mysql/software_titles_test.go | 35 +++++++++++++++---- server/fleet/software.go | 6 +++- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/server/datastore/mysql/software_titles.go b/server/datastore/mysql/software_titles.go index 2364614534..68303f0d25 100644 --- a/server/datastore/mysql/software_titles.go +++ b/server/datastore/mysql/software_titles.go @@ -31,6 +31,7 @@ SELECT st.name, st.source, st.browser, + st.bundle_identifier, COALESCE(SUM(sthc.hosts_count), 0) as hosts_count, MAX(sthc.updated_at) as counts_updated_at FROM software_titles st @@ -200,6 +201,7 @@ SELECT st.name, st.source, st.browser, + st.bundle_identifier, MAX(COALESCE(sthc.hosts_count, 0)) as hosts_count, MAX(COALESCE(sthc.updated_at, date('0001-01-01 00:00:00'))) as counts_updated_at, si.filename as software_package, diff --git a/server/datastore/mysql/software_titles_test.go b/server/datastore/mysql/software_titles_test.go index cb837cb0a5..5bff042da7 100644 --- a/server/datastore/mysql/software_titles_test.go +++ b/server/datastore/mysql/software_titles_test.go @@ -517,11 +517,12 @@ func testTeamFilterSoftwareTitles(t *testing.T, ds *Datastore) { // create a software installer for team1 installer1, err := ds.MatchOrCreateSoftwareInstaller(ctx, &fleet.UploadSoftwareInstallerPayload{ - Title: "installer1", - Source: "apps", - InstallScript: "echo", - Filename: "installer1.pkg", - TeamID: &team1.ID, + Title: "installer1", + Source: "apps", + InstallScript: "echo", + Filename: "installer1.pkg", + BundleIdentifier: "foo.bar", + TeamID: &team1.ID, }) require.NoError(t, err) require.NotZero(t, installer1) @@ -570,7 +571,20 @@ func testTeamFilterSoftwareTitles(t *testing.T, ds *Datastore) { require.NoError(t, err) // ListSoftwareTitles does not populate version host counts, so we do that manually titles[0].Versions[0].HostsCount = ptr.Uint(1) - assert.Equal(t, titles[0], fleet.SoftwareTitleListResult{ID: title.ID, Name: title.Name, Source: title.Source, Browser: title.Browser, HostsCount: title.HostsCount, VersionsCount: title.VersionsCount, Versions: title.Versions, CountsUpdatedAt: title.CountsUpdatedAt}) + assert.Equal( + t, + titles[0], + fleet.SoftwareTitleListResult{ + ID: title.ID, + Name: title.Name, + Source: title.Source, + Browser: title.Browser, + HostsCount: title.HostsCount, + VersionsCount: title.VersionsCount, + Versions: title.Versions, + CountsUpdatedAt: title.CountsUpdatedAt, + }, + ) // Testing with team filter -- this team does not contain this software title _, err = ds.SoftwareTitleByID(context.Background(), titles[0].ID, &team1.ID, globalTeamFilter) @@ -598,9 +612,18 @@ func testTeamFilterSoftwareTitles(t *testing.T, ds *Datastore) { require.Equal(t, "chrome_extensions", titles[0].Source) require.Equal(t, "installer1", titles[1].Name) require.Equal(t, "apps", titles[1].Source) + require.NotNil(t, titles[1].BundleIdentifier) + require.Equal(t, "foo.bar", *titles[1].BundleIdentifier) require.Equal(t, uint(1), titles[0].VersionsCount) require.Equal(t, uint(0), titles[1].VersionsCount) + title, err = ds.SoftwareTitleByID(context.Background(), titles[1].ID, &team1.ID, team1TeamFilter) + require.NoError(t, err) + require.Equal(t, "installer1", title.Name) + require.Equal(t, "apps", title.Source) + require.NotNil(t, title.BundleIdentifier) + require.Equal(t, "foo.bar", *title.BundleIdentifier) + // Testing with team filter -- this team does contain this software title title, err = ds.SoftwareTitleByID(context.Background(), titles[0].ID, &team1.ID, team1TeamFilter) require.NoError(t, err) diff --git a/server/fleet/software.go b/server/fleet/software.go index 48f24024a3..0cb90fe2b4 100644 --- a/server/fleet/software.go +++ b/server/fleet/software.go @@ -169,7 +169,7 @@ type SoftwareTitle struct { // BundleIdentifier is used by Apple installers to uniquely identify // the software installed. It's surfaced in software_titles to match // with existing software entries. - BundleIdentifier *string `json:"-" db:"bundle_identifier"` + BundleIdentifier *string `json:"bundle_identifier,omitempty" db:"bundle_identifier"` } // This type is essentially the same as the above SoftwareTitle type. The only difference is that @@ -196,6 +196,10 @@ type SoftwareTitleListResult struct { SoftwarePackage *string `json:"software_package" db:"software_package"` // SelfService indicates if the end user can initiate the installation SelfService bool `json:"self_service" db:"self_service"` + // BundleIdentifier is used by Apple installers to uniquely identify + // the software installed. It's surfaced in software_titles to match + // with existing software entries. + BundleIdentifier *string `json:"bundle_identifier,omitempty" db:"bundle_identifier"` } type SoftwareTitleListOptions struct {