mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
fix: don't fail when there are no VPP app version updates (#26677)
> For #26675 # 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] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [x] Added/updated automated tests - [x] Manual QA for all new/changed functionality
This commit is contained in:
parent
8f1626303a
commit
fc1c901238
2 changed files with 23 additions and 4 deletions
|
|
@ -3,6 +3,7 @@ package vpp
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/fleetdm/fleet/v4/server/contexts/ctxerr"
|
||||
"github.com/fleetdm/fleet/v4/server/fleet"
|
||||
"github.com/fleetdm/fleet/v4/server/mdm/apple/itunes"
|
||||
)
|
||||
|
|
@ -11,7 +12,12 @@ import (
|
|||
func RefreshVersions(ctx context.Context, ds fleet.Datastore) error {
|
||||
apps, err := ds.GetAllVPPApps(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
return ctxerr.Wrap(ctx, err, "getting all VPP apps")
|
||||
}
|
||||
|
||||
if len(apps) == 0 {
|
||||
// nothing to do
|
||||
return nil
|
||||
}
|
||||
|
||||
var adamIDs []string
|
||||
|
|
@ -23,7 +29,7 @@ func RefreshVersions(ctx context.Context, ds fleet.Datastore) error {
|
|||
|
||||
meta, err := itunes.GetAssetMetadata(adamIDs, &itunes.AssetMetadataFilter{Entity: "software"})
|
||||
if err != nil {
|
||||
return err
|
||||
return ctxerr.Wrap(ctx, err, "getting VPP app metadata from iTunes API")
|
||||
}
|
||||
|
||||
var appsToUpdate []*fleet.VPPApp
|
||||
|
|
@ -36,8 +42,13 @@ func RefreshVersions(ctx context.Context, ds fleet.Datastore) error {
|
|||
}
|
||||
}
|
||||
|
||||
if len(appsToUpdate) == 0 {
|
||||
// nothing to do
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ds.InsertVPPApps(ctx, appsToUpdate); err != nil {
|
||||
return err
|
||||
return ctxerr.Wrap(ctx, err, "inserting VPP apps with new versions")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -13781,6 +13781,10 @@ func (s *integrationMDMTestSuite) TestRefreshVPPAppVersions() {
|
|||
var resPatchVPP patchVPPTokensTeamsResponse
|
||||
s.DoJSON("PATCH", fmt.Sprintf("/api/latest/fleet/vpp_tokens/%d/teams", resp.Tokens[0].ID), patchVPPTokensTeamsRequest{TeamIDs: []uint{team.ID}}, http.StatusOK, &resPatchVPP)
|
||||
|
||||
// No VPP apps added yet, so this is a no-op
|
||||
err := vpp.RefreshVersions(ctx, s.ds)
|
||||
require.NoError(t, err)
|
||||
|
||||
var appResp getAppStoreAppsResponse
|
||||
s.DoJSON("GET", "/api/latest/fleet/software/app_store_apps", &getAppStoreAppsRequest{}, http.StatusOK, &appResp, "team_id",
|
||||
fmt.Sprint(team.ID))
|
||||
|
|
@ -13831,7 +13835,7 @@ func (s *integrationMDMTestSuite) TestRefreshVPPAppVersions() {
|
|||
s.appleITunesSrvData["2"] = `{"bundleId": "b-2", "artworkUrl512": "https://example.com/images/2", "version": "10.10.10", "trackName": "App 2", "TrackID": 2,
|
||||
"supportedDevices": ["MacDesktop-MacDesktop", "iPhone5s-iPhone5s", "iPadAir-iPadAir"] }`
|
||||
|
||||
err := vpp.RefreshVersions(ctx, s.ds)
|
||||
err = vpp.RefreshVersions(ctx, s.ds)
|
||||
require.NoError(t, err)
|
||||
|
||||
// 1 and 2 should be updated
|
||||
|
|
@ -13850,4 +13854,8 @@ func (s *integrationMDMTestSuite) TestRefreshVPPAppVersions() {
|
|||
require.Len(t, listSWTitlesResp.SoftwareTitles, 1)
|
||||
require.NotNil(t, listSWTitlesResp.SoftwareTitles[0].AppStoreApp)
|
||||
require.Equal(t, "3.0.0", listSWTitlesResp.SoftwareTitles[0].AppStoreApp.Version)
|
||||
|
||||
// Refresh again. There are no version changes this time, so this is a no-op.
|
||||
err = vpp.RefreshVersions(ctx, s.ds)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue