mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 00:49:03 +00:00
> Related issue: #22376 # 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] Manual QA for all new/changed functionality - For Orbit and Fleet Desktop changes: - [x] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [ ] Manual QA must be performed in the three main OSs, macOS, Windows and Linux. - [ ] Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).
71 lines
2.5 KiB
Go
71 lines
2.5 KiB
Go
package update
|
|
|
|
import (
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
type SwiftDialogDownloader struct {
|
|
UpdateRunner *Runner
|
|
}
|
|
|
|
type SwiftDialogDownloaderOptions struct {
|
|
// UpdateRunner is the wrapped Runner where swiftDialog will be set as a target. It is responsible for
|
|
// actually ensuring that swiftDialog is installed and updated via the designated TUF server.
|
|
UpdateRunner *Runner
|
|
}
|
|
|
|
func ApplySwiftDialogDownloaderMiddleware(
|
|
runner *Runner,
|
|
) fleet.OrbitConfigReceiver {
|
|
return &SwiftDialogDownloader{UpdateRunner: runner}
|
|
}
|
|
|
|
func (s *SwiftDialogDownloader) Run(cfg *fleet.OrbitConfig) error {
|
|
log.Debug().Msg("running swiftDialog installer middleware")
|
|
|
|
if cfg == nil {
|
|
log.Debug().Msg("SwiftDialogDownloader received nil config")
|
|
return nil
|
|
}
|
|
|
|
if s.UpdateRunner == nil {
|
|
log.Debug().Msg("SwiftDialogDownloader received nil UpdateRunner, this probably indicates that updates are turned off. Skipping any actions related to swiftDialog")
|
|
return nil
|
|
}
|
|
|
|
// TODO: we probably want to ensure that swiftDialog is always installed if we're going to be
|
|
// using it offline.
|
|
if !cfg.Notifications.NeedsMDMMigration && !cfg.Notifications.RenewEnrollmentProfile && !cfg.Notifications.RunSetupExperience {
|
|
log.Debug().Msg("skipping swiftDialog update")
|
|
return nil
|
|
}
|
|
|
|
updaterHasTarget := s.UpdateRunner.HasRunnerOptTarget("swiftDialog")
|
|
runnerHasLocalHash := s.UpdateRunner.HasLocalHash("swiftDialog")
|
|
if !updaterHasTarget || !runnerHasLocalHash {
|
|
log.Info().Msg("refreshing the update runner config with swiftDialog targets and hashes")
|
|
log.Debug().Msgf("updater has target: %t, runner has local hash: %t", updaterHasTarget, runnerHasLocalHash)
|
|
s.UpdateRunner.AddRunnerOptTarget("swiftDialog")
|
|
s.UpdateRunner.updater.SetTargetInfo("swiftDialog", SwiftDialogMacOSTarget)
|
|
// we don't want to keep swiftDialog as a target if we failed to update the
|
|
// cached hashes in the runner.
|
|
if err := s.UpdateRunner.StoreLocalHash("swiftDialog"); err != nil {
|
|
log.Debug().Msgf("removing swiftDialog from target options, error updating local hashes: %s", err)
|
|
s.UpdateRunner.RemoveRunnerOptTarget("swiftDialog")
|
|
s.UpdateRunner.updater.RemoveTargetInfo("swiftDialog")
|
|
return err
|
|
}
|
|
|
|
if cfg.Notifications.RunSetupExperience {
|
|
// Then update immediately, since we need to get swiftDialog quickly to show the setup
|
|
// experience
|
|
_, err := s.UpdateRunner.UpdateAction()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|