Skip to content

Commit

Permalink
add staging flag for hitting staging servers
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton committed May 24, 2016
1 parent ec9f7f4 commit 242e189
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 62 deletions.
18 changes: 14 additions & 4 deletions src/github.com/getlantern/flashlight/config/config.go
Expand Up @@ -59,9 +59,9 @@ type Fetcher interface {
}

// StartPolling starts the process of polling for new configuration files.
func StartPolling() {
func (cfg *Config) StartPolling() {
// Force detour to whitelist chained domain
u, err := url.Parse(chainedCloudConfigURL)
u, err := url.Parse(cfg.CloudConfig)
if err != nil {
log.Fatalf("Unable to parse chained cloud config URL: %v", err)
}
Expand All @@ -78,6 +78,12 @@ func validateConfig(_cfg yamlconf.Config) error {
if !ok {
return fmt.Errorf("Config is not a flashlight config!")
}
if cfg.Client == nil {
return fmt.Errorf("No client config")
}
if cfg.Client.ChainedServers == nil {
return fmt.Errorf("No chained servers")
}
nc := len(cfg.Client.ChainedServers)

log.Debugf("Found %v chained servers in config on disk", nc)
Expand Down Expand Up @@ -228,6 +234,10 @@ func (updated *Config) applyFlags(flags map[string]interface{}) error {
updated.CPUProfile = value.(string)
case "memprofile":
updated.MemProfile = value.(string)
case "staging":
log.Debug("Configuring for staging")
updated.CloudConfig = "http://config-staging.getiantem.org/cloud.yaml.gz"
updated.FrontedCloudConfig = "http://d33pfmbpauhmvd.cloudfront.net/cloud.yaml.gz"
}
}
if visitErr != nil {
Expand All @@ -249,11 +259,11 @@ func (cfg *Config) ApplyDefaults() {
}

if cfg.CloudConfig == "" {
cfg.CloudConfig = chainedCloudConfigURL
cfg.CloudConfig = defaultChainedCloudConfigURL
}

if cfg.FrontedCloudConfig == "" {
cfg.FrontedCloudConfig = frontedCloudConfigURL
cfg.FrontedCloudConfig = defaultFrontedCloudConfigURL
}

if cfg.Client == nil {
Expand Down
73 changes: 23 additions & 50 deletions src/github.com/getlantern/flashlight/config/config_test.go
Expand Up @@ -6,57 +6,30 @@ import (
"github.com/stretchr/testify/assert"
)

/*
func TestInitialConfig(t *testing.T) {
path, _ := ioutil.TempFile("", "config")
yamlPath := "test-packaged.yaml"
data, err := ioutil.ReadFile(yamlPath)
if err != nil {
// This will happen whenever there's no packaged settings, which is often
log.Debugf("Error reading file %v", err)
}
trimmed := strings.TrimSpace(string(data))
log.Debugf("Read bytes: %v", trimmed)
var s client.BootstrapSettings
err = yaml.Unmarshal([]byte(trimmed), &s)
if err != nil {
log.Errorf("Could not read yaml: %v", err)
}
err = fetchInitialConfig(path.Name(), &s)
assert.Nil(t, err, "Should not get an error fetching config")
}
*/
/*
func TestCopyOldConfig(t *testing.T) {
existsFunc := func(file string) (string, bool) {
return "fullpath", true
}
path := copyNewest("lantern-2.yaml", existsFunc)
assert.Equal(t, "fullpath", path, "unexpected path used")
// Test with temp files to make sure the actual copy of an old file to a
// new one works.
tf, _ := ioutil.TempFile("", "2.0.1")
tf2, _ := ioutil.TempFile("", "2.0.2")
log.Debugf("Created temp file: %v", tf.Name())
existsFunc = func(file string) (string, bool) {
if file == "lantern-2.0.1.yaml" {
return tf.Name(), true
}
return tf2.Name(), false
}
path = copyNewest("lantern-2.yaml", existsFunc)
assert.Equal(t, tf.Name(), path, "unexpected path used")
// TestStagingSetup tests to make sure our staging config flag sets the
// appropriate URLs for staging servers.
func TestStagingSetup(t *testing.T) {
userConfig := &userConfig{}
version := "test-version"
flagsAsMap := make(map[string]interface{})

configDir := ""
stickyConfig := false
var cfg *Config
var err error
cfg, err = Init(userConfig, version, configDir, stickyConfig, flagsAsMap)
assert.Nil(t, err)

assert.Equal(t, defaultChainedCloudConfigURL, cfg.CloudConfig)
assert.Equal(t, defaultFrontedCloudConfigURL, cfg.FrontedCloudConfig)

flagsAsMap["staging"] = true
cfg, err = Init(userConfig, version, configDir, stickyConfig, flagsAsMap)
assert.Nil(t, err)

assert.Equal(t, "http://config-staging.getiantem.org/cloud.yaml.gz", cfg.CloudConfig)
assert.Equal(t, "http://d33pfmbpauhmvd.cloudfront.net/cloud.yaml.gz", cfg.FrontedCloudConfig)
}
*/

func TestMajorVersion(t *testing.T) {
ver := "222.00.1"
Expand Down
19 changes: 12 additions & 7 deletions src/github.com/getlantern/flashlight/config/fetcher.go
Expand Up @@ -16,16 +16,17 @@ import (
)

const (
etag = "X-Lantern-Etag"
ifNoneMatch = "X-Lantern-If-None-Match"
userIDHeader = "X-Lantern-User-Id"
tokenHeader = "X-Lantern-Pro-Token"
chainedCloudConfigURL = "http://config.getiantem.org/cloud.yaml.gz"
etag = "X-Lantern-Etag"
ifNoneMatch = "X-Lantern-If-None-Match"
userIDHeader = "X-Lantern-User-Id"
tokenHeader = "X-Lantern-Pro-Token"

defaultChainedCloudConfigURL = "http://config.getiantem.org/cloud.yaml.gz"

// This is over HTTP because proxies do not forward X-Forwarded-For with HTTPS
// and because we only support falling back to direct domain fronting through
// the local proxy for HTTP.
frontedCloudConfigURL = "http://d2wi0vwulmtn99.cloudfront.net/cloud.yaml.gz"
defaultFrontedCloudConfigURL = "http://d2wi0vwulmtn99.cloudfront.net/cloud.yaml.gz"
)

var (
Expand All @@ -50,7 +51,11 @@ type UserConfig interface {
// NewFetcher creates a new configuration fetcher with the specified
// interface for obtaining the user ID and token if those are populated.
func NewFetcher(conf UserConfig, rt http.RoundTripper) Fetcher {
return &fetcher{lastCloudConfigETag: map[string]string{}, user: conf, rt: rt}
return &fetcher{
lastCloudConfigETag: map[string]string{},
user: conf,
rt: rt,
}
}

func (cf *fetcher) pollForConfig(currentCfg yamlconf.Config, stickyConfig bool) (mutate func(yamlconf.Config) error, waitTime time.Duration, err error) {
Expand Down
2 changes: 1 addition & 1 deletion src/github.com/getlantern/flashlight/flashlight.go
Expand Up @@ -134,7 +134,7 @@ func Run(httpProxyAddr string,
// proxying capabilities of Lantern, so it needs everything to be properly
// set up with at least an initial bootstrap config (on first run) to
// complete successfully.
config.StartPolling()
cfg.StartPolling()
afterStart(cfg)
})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions src/github.com/getlantern/flashlight/main/flags.go
Expand Up @@ -23,6 +23,7 @@ var (
forceProxyAddr = flag.String("force-proxy-addr", "", "if specified, force chained proxying to use this address instead of the configured one")
forceAuthToken = flag.String("force-auth-token", "", "if specified, force chained proxying to use this auth token instead of the configured one")
readableconfig = flag.Bool("readableconfig", false, "if specified, disables obfuscation of the config yaml so that it remains human readable")
staging = flag.Bool("staging", false, "if true, run Lantern against our staging infrastructure")
help = flag.Bool("help", false, "Get usage help")
)

Expand Down

0 comments on commit 242e189

Please sign in to comment.