Skip to content

Commit

Permalink
added back flag override support
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton committed Aug 3, 2016
1 parent cb9e104 commit 76ef309
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
30 changes: 30 additions & 0 deletions src/github.com/getlantern/flashlight/config/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,33 @@ type Global struct {
// TrustedCAs are trusted CAs for domain fronting domains only.
TrustedCAs []*fronted.CA
}

// applyFlags updates this config from any command-line flags that were passed
// in.
func (cfg *Global) applyFlags(flags map[string]interface{}) error {
if cfg.Client == nil {
cfg.Client = &client.ClientConfig{}
}

var visitErr error

// Visit all flags that have been set and copy to config
for key, value := range flags {
switch key {
// General
case "cloudconfigca":
cfg.CloudConfigCA = value.(string)
case "borda-report-interval":
cfg.BordaReportInterval = value.(time.Duration)
case "borda-sample-percentage":
cfg.BordaSamplePercentage = value.(float64)
case "loggly-sample-percentage":
cfg.LogglySamplePercentage = value.(float64)
}
}
if visitErr != nil {
return visitErr
}

return nil
}
16 changes: 9 additions & 7 deletions src/github.com/getlantern/flashlight/config/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ var (

// Init initializes the config setup for both fetching per-user proxies as well
// as the global config.
func Init(configDir string, flagsAsMap map[string]interface{},
func Init(configDir string, flags map[string]interface{},
userConfig UserConfig, proxiesDispatch func(interface{}),
globalDispatch func(interface{})) {
staging := isStaging(flagsAsMap)
staging := isStaging(flags)
// These are the options for fetching the per-user proxy config.
proxyOptions := &options{
saveDir: configDir,
obfuscate: obfuscate(flagsAsMap),
obfuscate: obfuscate(flags),
name: "proxies.yaml",
urls: checkOverrides(flagsAsMap, getProxyURLs(staging), "proxies.yaml.gz"),
urls: checkOverrides(flags, getProxyURLs(staging), "proxies.yaml.gz"),
userConfig: userConfig,
yamlTemplater: func() interface{} {
return make(map[string]*client.ChainedServerInfo)
Expand All @@ -70,12 +70,14 @@ func Init(configDir string, flagsAsMap map[string]interface{},
// These are the options for fetching the global config.
globalOptions := &options{
saveDir: configDir,
obfuscate: obfuscate(flagsAsMap),
obfuscate: obfuscate(flags),
name: "global.yaml",
urls: checkOverrides(flagsAsMap, getGlobalURLs(staging), "global.yaml.gz"),
urls: checkOverrides(flags, getGlobalURLs(staging), "global.yaml.gz"),
userConfig: userConfig,
yamlTemplater: func() interface{} {
return &Global{}
gl := &Global{}
gl.applyFlags(flags)
return gl
},
dispatch: globalDispatch,
embeddedData: generated.GlobalConfig,
Expand Down

0 comments on commit 76ef309

Please sign in to comment.