@@ -16,7 +16,6 @@ import (
16
16
17
17
"github.com/fleetdm/fleet/v4/pkg/file"
18
18
"github.com/fleetdm/fleet/v4/pkg/fleethttp"
19
- "github.com/fleetdm/fleet/v4/server/authz"
20
19
authz_ctx "github.com/fleetdm/fleet/v4/server/contexts/authz"
21
20
"github.com/fleetdm/fleet/v4/server/contexts/ctxerr"
22
21
hostctx "github.com/fleetdm/fleet/v4/server/contexts/host"
@@ -1017,17 +1016,19 @@ func (svc *Service) InstallSoftwareTitle(ctx context.Context, hostID uint, softw
1017
1016
}
1018
1017
}
1019
1018
1020
- _ , err = svc .installSoftwareFromVPP (ctx , host , vppApp , mobileAppleDevice || fleet .AppleDevicePlatform (platform ) == fleet .MacOSPlatform , false )
1019
+ _ , err = svc .installSoftwareFromVPP (ctx , host , vppApp , mobileAppleDevice || fleet .AppleDevicePlatform (platform ) == fleet .MacOSPlatform , fleet.HostSoftwareInstallOptions {
1020
+ SelfService : false ,
1021
+ })
1021
1022
return err
1022
1023
}
1023
1024
1024
- func (svc * Service ) installSoftwareFromVPP (ctx context.Context , host * fleet.Host , vppApp * fleet.VPPApp , appleDevice bool , selfService bool ) (string , error ) {
1025
+ func (svc * Service ) installSoftwareFromVPP (ctx context.Context , host * fleet.Host , vppApp * fleet.VPPApp , appleDevice bool , opts fleet. HostSoftwareInstallOptions ) (string , error ) {
1025
1026
token , err := svc .GetVPPTokenIfCanInstallVPPApps (ctx , appleDevice , host )
1026
1027
if err != nil {
1027
1028
return "" , err
1028
1029
}
1029
1030
1030
- return svc .InstallVPPAppPostValidation (ctx , host , vppApp , token , selfService , nil )
1031
+ return svc .InstallVPPAppPostValidation (ctx , host , vppApp , token , opts )
1031
1032
}
1032
1033
1033
1034
func (svc * Service ) GetVPPTokenIfCanInstallVPPApps (ctx context.Context , appleDevice bool , host * fleet.Host ) (string , error ) {
@@ -1073,7 +1074,7 @@ func (svc *Service) GetVPPTokenIfCanInstallVPPApps(ctx context.Context, appleDev
1073
1074
return token , nil
1074
1075
}
1075
1076
1076
- func (svc * Service ) InstallVPPAppPostValidation (ctx context.Context , host * fleet.Host , vppApp * fleet.VPPApp , token string , selfService bool , policyID * uint ) (string , error ) {
1077
+ func (svc * Service ) InstallVPPAppPostValidation (ctx context.Context , host * fleet.Host , vppApp * fleet.VPPApp , token string , opts fleet. HostSoftwareInstallOptions ) (string , error ) {
1077
1078
// at this moment, neither the UI nor the back-end are prepared to
1078
1079
// handle [asyncronous errors][1] on assignment, so before assigning a
1079
1080
// device to a license, we need to:
@@ -1137,14 +1138,19 @@ func (svc *Service) InstallVPPAppPostValidation(ctx context.Context, host *fleet
1137
1138
}
1138
1139
}
1139
1140
1140
- // add command to install
1141
- cmdUUID := uuid .NewString ()
1142
- err = svc .mdmAppleCommander .InstallApplication (ctx , []string {host .UUID }, cmdUUID , vppApp .AdamID )
1143
- if err != nil {
1144
- return "" , ctxerr .Wrapf (ctx , err , "sending command to install VPP %s application to host with serial %s" , vppApp .AdamID , host .HardwareSerial )
1145
- }
1141
+ // TODO(mna): should we associate the device (give the license) only when the
1142
+ // upcoming activity is ready to run? I don't think so, because then it could
1143
+ // fail when it's ready to run which is probably a worse UX as once enqueued
1144
+ // you expect it to succeed. But eventually, we should do better management
1145
+ // of the licenses, e.g. if the upcoming activity gets cancelled, it should
1146
+ // release the reserved license.
1147
+ //
1148
+ // But the command is definitely not enqueued now, only when activating the
1149
+ // activity.
1146
1150
1147
- err = svc .ds .InsertHostVPPSoftwareInstall (ctx , host .ID , vppApp .VPPAppID , cmdUUID , eventID , selfService , policyID )
1151
+ // enqueue the VPP app command to install
1152
+ cmdUUID := uuid .NewString ()
1153
+ err = svc .ds .InsertHostVPPSoftwareInstall (ctx , host .ID , vppApp .VPPAppID , cmdUUID , eventID , opts )
1148
1154
if err != nil {
1149
1155
return "" , ctxerr .Wrapf (ctx , err , "inserting host vpp software install for host with serial %s and app with adamID %s" , host .HardwareSerial , vppApp .AdamID )
1150
1156
}
@@ -1170,7 +1176,9 @@ func (svc *Service) installSoftwareTitleUsingInstaller(ctx context.Context, host
1170
1176
}
1171
1177
}
1172
1178
1173
- _ , err := svc .ds .InsertSoftwareInstallRequest (ctx , host .ID , installer .InstallerID , false , nil )
1179
+ _ , err := svc .ds .InsertSoftwareInstallRequest (ctx , host .ID , installer .InstallerID , fleet.HostSoftwareInstallOptions {
1180
+ SelfService : false ,
1181
+ })
1174
1182
return ctxerr .Wrap (ctx , err , "inserting software install request" )
1175
1183
}
1176
1184
@@ -1260,8 +1268,9 @@ func (svc *Service) UninstallSoftwareTitle(ctx context.Context, hostID uint, sof
1260
1268
}
1261
1269
}
1262
1270
1263
- // Get the uninstall script and use the standard script infrastructure to run it.
1264
- contents , err := svc .ds .GetAnyScriptContents (ctx , installer .UninstallScriptContentID )
1271
+ // Get the uninstall script to validate there is one, will use the standard
1272
+ // script infrastructure to run it.
1273
+ _ , err = svc .ds .GetAnyScriptContents (ctx , installer .UninstallScriptContentID )
1265
1274
if err != nil {
1266
1275
if fleet .IsNotFound (err ) {
1267
1276
return ctxerr .Wrap (ctx ,
@@ -1271,32 +1280,11 @@ func (svc *Service) UninstallSoftwareTitle(ctx context.Context, hostID uint, sof
1271
1280
return err
1272
1281
}
1273
1282
1274
- var teamID uint
1275
- if host .TeamID != nil {
1276
- teamID = * host .TeamID
1277
- }
1278
- // create the script execution request; the host will be notified of the
1279
- // script execution request via the orbit config's Notifications mechanism.
1280
- request := fleet.HostScriptRequestPayload {
1281
- HostID : host .ID ,
1282
- ScriptContents : string (contents ),
1283
- ScriptContentID : installer .UninstallScriptContentID ,
1284
- TeamID : teamID ,
1285
- }
1286
- if ctxUser := authz .UserFromContext (ctx ); ctxUser != nil {
1287
- request .UserID = & ctxUser .ID
1288
- }
1289
- scriptResult , err := svc .ds .NewInternalScriptExecutionRequest (ctx , & request )
1290
- if err != nil {
1291
- return ctxerr .Wrap (ctx , err , "create script execution request" )
1292
- }
1293
-
1294
- // Update the host software installs table with the uninstall request.
1295
1283
// Pending uninstalls will automatically show up in the UI Host Details -> Activity -> Upcoming tab.
1296
- if err = svc .insertSoftwareUninstallRequest (ctx , scriptResult .ExecutionID , host , installer ); err != nil {
1284
+ execID := uuid .NewString ()
1285
+ if err = svc .insertSoftwareUninstallRequest (ctx , execID , host , installer ); err != nil {
1297
1286
return err
1298
1287
}
1299
-
1300
1288
return nil
1301
1289
}
1302
1290
@@ -1834,7 +1822,9 @@ func (svc *Service) SelfServiceInstallSoftwareTitle(ctx context.Context, host *f
1834
1822
}
1835
1823
}
1836
1824
1837
- _ , err = svc .ds .InsertSoftwareInstallRequest (ctx , host .ID , installer .InstallerID , true , nil )
1825
+ _ , err = svc .ds .InsertSoftwareInstallRequest (ctx , host .ID , installer .InstallerID , fleet.HostSoftwareInstallOptions {
1826
+ SelfService : true ,
1827
+ })
1838
1828
return ctxerr .Wrap (ctx , err , "inserting self-service software install request" )
1839
1829
}
1840
1830
@@ -1879,7 +1869,9 @@ func (svc *Service) SelfServiceInstallSoftwareTitle(ctx context.Context, host *f
1879
1869
platform := host .FleetPlatform ()
1880
1870
mobileAppleDevice := fleet .AppleDevicePlatform (platform ) == fleet .IOSPlatform || fleet .AppleDevicePlatform (platform ) == fleet .IPadOSPlatform
1881
1871
1882
- _ , err = svc .installSoftwareFromVPP (ctx , host , vppApp , mobileAppleDevice || fleet .AppleDevicePlatform (platform ) == fleet .MacOSPlatform , true )
1872
+ _ , err = svc .installSoftwareFromVPP (ctx , host , vppApp , mobileAppleDevice || fleet .AppleDevicePlatform (platform ) == fleet .MacOSPlatform , fleet.HostSoftwareInstallOptions {
1873
+ SelfService : true ,
1874
+ })
1883
1875
return err
1884
1876
}
1885
1877
0 commit comments