mirror of
https://github.com/safing/portmaster
synced 2025-09-02 18:49:14 +00:00
Configure update registry user agent
This commit is contained in:
parent
e5bad8f067
commit
b6d69ecddd
2 changed files with 18 additions and 2 deletions
|
@ -63,6 +63,7 @@ func init() {
|
||||||
flags := rootCmd.PersistentFlags()
|
flags := rootCmd.PersistentFlags()
|
||||||
{
|
{
|
||||||
flags.StringVar(&dataDir, "data", "", "Configures the data directory. Alternatively, this can also be set via the environment variable PORTMASTER_DATA.")
|
flags.StringVar(&dataDir, "data", "", "Configures the data directory. Alternatively, this can also be set via the environment variable PORTMASTER_DATA.")
|
||||||
|
flags.StringVar(®istry.UserAgent, "update-agent", "Start", "Sets the user agent for requests to the update server")
|
||||||
flags.IntVar(&maxRetries, "max-retries", 5, "Maximum number of retries when starting a Portmaster component")
|
flags.IntVar(&maxRetries, "max-retries", 5, "Maximum number of retries when starting a Portmaster component")
|
||||||
flags.BoolVar(&stdinSignals, "input-signals", false, "Emulate signals using stdid.")
|
flags.BoolVar(&stdinSignals, "input-signals", false, "Emulate signals using stdid.")
|
||||||
_ = rootCmd.MarkPersistentFlagDirname("data")
|
_ = rootCmd.MarkPersistentFlagDirname("data")
|
||||||
|
|
|
@ -2,6 +2,7 @@ package updates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
@ -45,11 +46,18 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
module *modules.Module
|
module *modules.Module
|
||||||
registry *updater.ResourceRegistry
|
registry *updater.ResourceRegistry
|
||||||
|
userAgentFromFlag string
|
||||||
|
|
||||||
updateTask *modules.Task
|
updateTask *modules.Task
|
||||||
updateASAP bool
|
updateASAP bool
|
||||||
disableTaskSchedule bool
|
disableTaskSchedule bool
|
||||||
|
|
||||||
|
// UserAgent is an HTTP User-Agent that is used to add
|
||||||
|
// more context to requests made by the registry when
|
||||||
|
// fetching resources from the update server.
|
||||||
|
UserAgent = "Core"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -62,6 +70,8 @@ func init() {
|
||||||
module = modules.Register(ModuleName, prep, start, stop, "base")
|
module = modules.Register(ModuleName, prep, start, stop, "base")
|
||||||
module.RegisterEvent(VersionUpdateEvent)
|
module.RegisterEvent(VersionUpdateEvent)
|
||||||
module.RegisterEvent(ResourceUpdateEvent)
|
module.RegisterEvent(ResourceUpdateEvent)
|
||||||
|
|
||||||
|
flag.StringVar(&userAgentFromFlag, "update-agent", "", "Sets the user agent for requests to the update server")
|
||||||
}
|
}
|
||||||
|
|
||||||
func prep() error {
|
func prep() error {
|
||||||
|
@ -121,11 +131,16 @@ func start() error {
|
||||||
UpdateURLs: []string{
|
UpdateURLs: []string{
|
||||||
"https://updates.safing.io",
|
"https://updates.safing.io",
|
||||||
},
|
},
|
||||||
|
UserAgent: UserAgent,
|
||||||
MandatoryUpdates: mandatoryUpdates,
|
MandatoryUpdates: mandatoryUpdates,
|
||||||
Beta: releaseChannel() == releaseChannelBeta,
|
Beta: releaseChannel() == releaseChannelBeta,
|
||||||
DevMode: devMode(),
|
DevMode: devMode(),
|
||||||
Online: true,
|
Online: true,
|
||||||
}
|
}
|
||||||
|
if userAgentFromFlag != "" {
|
||||||
|
// override with flag value
|
||||||
|
registry.UserAgent = userAgentFromFlag
|
||||||
|
}
|
||||||
// initialize
|
// initialize
|
||||||
err := registry.Initialize(dataroot.Root().ChildDir("updates", 0755))
|
err := registry.Initialize(dataroot.Root().ChildDir("updates", 0755))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue