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.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
This commit is contained in:
Roberto Dip 2024-07-10 12:25:10 -03:00 committed by GitHub
parent 303c0523a0
commit adc608ea6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 36 additions and 7 deletions

View file

@ -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,

View file

@ -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)

View file

@ -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 {