Revamp automatic updates setting and adapt its usage

This commit is contained in:
Daniel 2020-11-04 14:50:42 +01:00
parent 30f84e8009
commit 385c0a164c
2 changed files with 20 additions and 20 deletions

View file

@ -14,10 +14,10 @@ const (
var ( var (
releaseChannel config.StringOption releaseChannel config.StringOption
devMode config.BoolOption devMode config.BoolOption
disableUpdates config.BoolOption enableUpdates config.BoolOption
previousReleaseChannel string previousReleaseChannel string
updatesCurrentlyDisabled bool updatesCurrentlyEnabled bool
previousDevMode bool previousDevMode bool
) )
@ -42,9 +42,9 @@ func registerConfig() error {
}, },
}, },
Annotations: config.Annotations{ Annotations: config.Annotations{
config.DisplayOrderAnnotation: 1, config.DisplayOrderAnnotation: -4,
config.DisplayHintAnnotation: config.DisplayHintOneOf, config.DisplayHintAnnotation: config.DisplayHintOneOf,
config.CategoryAnnotation: "Expertise & Release", config.CategoryAnnotation: "Updates",
}, },
}) })
if err != nil { if err != nil {
@ -52,17 +52,17 @@ func registerConfig() error {
} }
err = config.Register(&config.Option{ err = config.Register(&config.Option{
Name: "Disable Updates", Name: "Automatic Updates",
Key: disableUpdatesKey, Key: enableUpdatesKey,
Description: "Disable automatic updates. This affects all kinds of updates, including intelligence feeds and broadcast notifications.", Description: "Enable automatic checking, downloading and applying of updates. This affects all kinds of updates, including intelligence feeds and broadcast notifications.",
OptType: config.OptTypeBool, OptType: config.OptTypeBool,
ExpertiseLevel: config.ExpertiseLevelExpert, ExpertiseLevel: config.ExpertiseLevelExpert,
ReleaseLevel: config.ReleaseLevelStable, ReleaseLevel: config.ReleaseLevelStable,
RequiresRestart: false, RequiresRestart: false,
DefaultValue: false, DefaultValue: true,
Annotations: config.Annotations{ Annotations: config.Annotations{
config.DisplayOrderAnnotation: 64, config.DisplayOrderAnnotation: -12,
config.CategoryAnnotation: "General", config.CategoryAnnotation: "Updates",
}, },
}) })
if err != nil { if err != nil {
@ -76,8 +76,8 @@ func initConfig() {
releaseChannel = config.GetAsString(releaseChannelKey, releaseChannelStable) releaseChannel = config.GetAsString(releaseChannelKey, releaseChannelStable)
previousReleaseChannel = releaseChannel() previousReleaseChannel = releaseChannel()
disableUpdates = config.GetAsBool(disableUpdatesKey, false) enableUpdates = config.GetAsBool(enableUpdatesKey, true)
updatesCurrentlyDisabled = disableUpdates() updatesCurrentlyEnabled = enableUpdates()
devMode = config.GetAsBool(cfgDevModeKey, false) devMode = config.GetAsBool(cfgDevModeKey, false)
previousDevMode = devMode() previousDevMode = devMode()
@ -99,10 +99,10 @@ func updateRegistryConfig(_ context.Context, _ interface{}) error {
changed = true changed = true
} }
if disableUpdates() != updatesCurrentlyDisabled { if enableUpdates() != updatesCurrentlyEnabled {
updatesCurrentlyDisabled = disableUpdates() updatesCurrentlyEnabled = enableUpdates()
changed = true changed = true
forceUpdate = !updatesCurrentlyDisabled forceUpdate = updatesCurrentlyEnabled
} }
if changed { if changed {
@ -113,7 +113,7 @@ func updateRegistryConfig(_ context.Context, _ interface{}) error {
module.Resolve(updateFailed) module.Resolve(updateFailed)
_ = TriggerUpdate() _ = TriggerUpdate()
log.Infof("updates: automatic updates enabled again.") log.Infof("updates: automatic updates enabled again.")
} else if updatesCurrentlyDisabled { } else if !updatesCurrentlyEnabled {
module.Warning(updateFailed, "Automatic updates are disabled! This also affects security updates and threat intelligence.") module.Warning(updateFailed, "Automatic updates are disabled! This also affects security updates and threat intelligence.")
log.Warningf("updates: automatic updates are now disabled.") log.Warningf("updates: automatic updates are now disabled.")
} }

View file

@ -20,7 +20,7 @@ const (
releaseChannelStable = "stable" releaseChannelStable = "stable"
releaseChannelBeta = "beta" releaseChannelBeta = "beta"
disableUpdatesKey = "core/disableUpdates" enableUpdatesKey = "core/automaticUpdates"
// ModuleName is the name of the update module // ModuleName is the name of the update module
// and can be used when declaring module dependencies. // and can be used when declaring module dependencies.
@ -245,7 +245,7 @@ func DisableUpdateSchedule() error {
} }
func checkForUpdates(ctx context.Context) (err error) { func checkForUpdates(ctx context.Context) (err error) {
if updatesCurrentlyDisabled { if !updatesCurrentlyEnabled {
log.Debugf("updates: automatic updates are disabled") log.Debugf("updates: automatic updates are disabled")
return nil return nil
} }