Beispiel #1
0
// initialize proxymgr
func initialize() {
	config.LogLevel = "FATAL"
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt(config.LogLevel))

	// bad initialize proxymgr
	config.RouteHttp = "!@#$%^&*"
	err := proxymgr.Init()
	if err == nil {
		fmt.Printf("Proxymgr init succeeded when it should have failed\n")
		os.Exit(1)
	}

	// initialize proxymgr
	config.RouteHttp = "0.0.0.0:9083"
	config.RouteTls = "0.0.0.0:9446"
	err = proxymgr.Init()
	if err != nil {
		fmt.Printf("Proxymgr init failed - %v\n", err)
		os.Exit(1)
	}
}
Beispiel #2
0
func initialize() {
	rExec, err := exec.Command("redis-server", "-v").CombinedOutput()
	if err != nil {
		fmt.Printf("Failed to run redis-server - %s%v\n", rExec, err.Error())
		skip = true
	}

	config.RouteHttp = "0.0.0.0:9082"
	config.RouteTls = "0.0.0.0:9445"
	config.LogLevel = "FATAL"
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt(config.LogLevel))

	if !skip {
		config.ClusterConnection = "redis://127.0.0.1:6379"
		config.DatabaseConnection = "scribble:///tmp/clusterTest"

		err = database.Init()
		if err != nil {
			fmt.Printf("database init failed - %v\n", err)
			os.Exit(1)
		}

		balance.Balancer = &database.ScribbleDatabase{}
		err = balance.Balancer.Init()
		if err != nil {
			fmt.Printf("balance init failed - %v\n", err)
			os.Exit(1)
		}

		// initialize proxymgr
		err = proxymgr.Init()
		if err != nil {
			fmt.Printf("Proxymgr init failed - %v\n", err)
			os.Exit(1)
		}

		// initialize vipmgr
		err = vipmgr.Init()
		if err != nil {
			fmt.Printf("Vipmgr init failed - %v\n", err)
			os.Exit(1)
		}

		err = cluster.Init()
		if err != nil {
			fmt.Printf("Cluster init failed - %v\n", err)
			os.Exit(1)
		}
	}
}
Beispiel #3
0
// manually configure and start internals
func initialize() {
	http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
	config.DatabaseConnection = "scribble:///tmp/cliTest"
	config.ClusterConnection = "none://"
	config.ApiHost = "127.0.0.1"
	config.ApiPort = "8445"
	config.ApiToken = ""
	config.RouteHttp = "0.0.0.0:9081"
	config.RouteTls = "0.0.0.0:9444"
	config.LogLevel = "FATAL"
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt(config.LogLevel))
	apiAddr = fmt.Sprintf("%v:%v", config.ApiHost, config.ApiPort)

	// initialize database
	err := database.Init()
	if err != nil {
		fmt.Printf("Database init failed - %v\n", err)
		os.Exit(1)
	}
	// initialize balancer
	balance.Balancer = &database.ScribbleDatabase{}
	err = balance.Balancer.Init()
	if err != nil {
		fmt.Printf("Balancer init failed - %v\n", err)
		os.Exit(1)
	}
	// initialize proxymgr
	err = proxymgr.Init()
	if err != nil {
		fmt.Printf("Proxymgr init failed - %v\n", err)
		os.Exit(1)
	}
	// initialize vipmgr
	err = vipmgr.Init()
	if err != nil {
		fmt.Printf("Vipmgr init failed - %v\n", err)
		os.Exit(1)
	}
	// initialize clusterer
	err = cluster.Init()
	if err != nil {
		fmt.Printf("Clusterer init failed - %v\n", err)
		os.Exit(1)
	}
}
Beispiel #4
0
func TestSetCerts(t *testing.T) {
	if err := proxymgr.SetCerts([]core.CertBundle{testCert}); err != nil {
		t.Errorf("Failed to SET certs - %v", err)
		t.FailNow()
	}

	certs, err := proxymgr.GetCerts()
	if err != nil {
		t.Error(err)
	}

	if len(certs) == 1 && certs[0].Cert != testCert.Cert {
		t.Errorf("Read cert differs from written cert")
	}

	// test bad tls start (certs must be in place)
	config.RouteHttp = "0.0.0.0:9084"
	config.RouteTls = "!@#$%^&*"
	err = proxymgr.Init()
	if err == nil {
		fmt.Printf("Proxymgr init succeeded when it should have failed\n")
		os.Exit(1)
	}
}
Beispiel #5
0
func startPortal(ccmd *cobra.Command, args []string) error {
	if config.LogFile == "" {
		config.Log = lumber.NewConsoleLogger(lumber.LvlInt(config.LogLevel))
	} else {
		var err error
		config.Log, err = lumber.NewFileLogger(config.LogFile, lumber.LvlInt(config.LogLevel), lumber.ROTATE, 5000, 9, 100)
		if err != nil {
			config.Log.Fatal("File logger init failed - %v", err)
			return fmt.Errorf("")
		}
	}

	// ensure proxy ports are unique. we need to check because tls will not listen
	// until a cert is added. we want it to break sooner.
	if config.RouteHttp == config.RouteTls {
		config.Log.Fatal("Proxy addresses must be unique")
		return fmt.Errorf("")
	}
	// need ':' in case tls is double apiport (8080, 80)
	apiPort := fmt.Sprintf(":%s", config.ApiPort)
	if strings.HasSuffix(config.RouteTls, apiPort) {
		config.Log.Fatal("TLS proxy address must be unique")
		return fmt.Errorf("")
	}

	// initialize database
	err := database.Init()
	if err != nil {
		config.Log.Fatal("Database init failed - %v", err)
		return fmt.Errorf("")
	}
	// initialize balancer
	err = balance.Init()
	if err != nil {
		config.Log.Fatal("Balancer init failed - %v", err)
		return fmt.Errorf("")
	}
	// initialize proxymgr
	err = proxymgr.Init()
	if err != nil {
		config.Log.Fatal("Proxymgr init failed - %v", err)
		return fmt.Errorf("")
	}
	// initialize vipmgr
	err = vipmgr.Init()
	if err != nil {
		config.Log.Fatal("Vipmgr init failed - %v", err)
		return fmt.Errorf("")
	}
	// initialize cluster
	err = cluster.Init()
	if err != nil {
		config.Log.Fatal("Cluster init failed - %v", err)
		return fmt.Errorf("")
	}

	go sigHandle()

	// start api
	err = api.StartApi()
	if err != nil {
		config.Log.Fatal("Api start failed - %v", err)
		return fmt.Errorf("")
	}
	return nil
}
Beispiel #6
0
// manually configure and start internals
func initialize() {
	http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
	config.DatabaseConnection = "scribble:///tmp/portalTest"
	config.ClusterConnection = "none://"
	config.ApiHost = "127.0.0.1"
	config.ApiPort = "8444"
	config.ApiToken = ""
	config.RouteHttp = "0.0.0.0:9080"
	config.RouteTls = "0.0.0.0:9443"
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt("FATAL"))
	config.LogLevel = "FATAL"
	apiAddr = fmt.Sprintf("%v:%v", config.ApiHost, config.ApiPort)

	// initialize database
	err := database.Init()
	if err != nil {
		fmt.Printf("Database init failed - %v\n", err)
		os.Exit(1)
	}
	// initialize balancer
	balance.Balancer = &database.ScribbleDatabase{}
	err = balance.Balancer.Init()
	if err != nil {
		fmt.Printf("Balancer init failed - %v\n", err)
		os.Exit(1)
	}
	// initialize proxymgr
	err = proxymgr.Init()
	if err != nil {
		fmt.Printf("Proxymgr init failed - %v\n", err)
		os.Exit(1)
	}
	// initialize vipmgr
	err = vipmgr.Init()
	if err != nil {
		fmt.Printf("Vipmgr init failed - %v\n", err)
		os.Exit(1)
	}
	// initialize clusterer
	err = cluster.Init()
	if err != nil {
		fmt.Printf("Clusterer init failed - %v\n", err)
		os.Exit(1)
	}
	// load saved rules
	services, err := database.Backend.GetServices()
	if err != nil {
		// if error is not about a missing db, continue
		if !strings.Contains(err.Error(), "Found") {
			// todo: this requires backends to return NoServiceError in GetServices
			fmt.Printf("Get services from backend failed - %v\n", err)
			os.Exit(1)
		}
	}
	// apply saved rules
	err = balance.Balancer.SetServices(services)
	if err != nil {
		fmt.Printf("Balancer sync failed - %v\n", err)
		os.Exit(1)
	}
}