mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Fixed badly formatted error messages in /api/fleet/orbit/device_token endpoint and others. In /api/fleet/orbit/device_token: - Added token validation -- empty token not allowed - Replaced 500 error with 409 when token conflicts with another host #15832 # 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] Changes file added for user-visible changes in `changes/` or `orbit/changes/`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - [x] Added/updated tests - [x] Manual QA
65 lines
2.2 KiB
Go
65 lines
2.2 KiB
Go
package update
|
|
|
|
import (
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
type SwiftDialogDownloader struct {
|
|
Fetcher OrbitConfigFetcher
|
|
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(
|
|
f OrbitConfigFetcher,
|
|
runner *Runner,
|
|
) OrbitConfigFetcher {
|
|
return &SwiftDialogDownloader{Fetcher: f, UpdateRunner: runner}
|
|
}
|
|
|
|
func (s *SwiftDialogDownloader) GetConfig() (*fleet.OrbitConfig, error) {
|
|
log.Debug().Msg("running swiftDialog installer middleware")
|
|
cfg, err := s.Fetcher.GetConfig()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if cfg == nil {
|
|
log.Debug().Msg("SwiftDialogDownloader received nil config")
|
|
return nil, 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 cfg, nil
|
|
}
|
|
|
|
if !cfg.Notifications.NeedsMDMMigration && !cfg.Notifications.RenewEnrollmentProfile {
|
|
return cfg, 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 cfg, err
|
|
}
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|