Example #1
0
func main() {
	cfgPath := flag.String("config_file", "", "Path to config file.")
	flag.Parse()

	cfg, err := loadConfigFromPath(*cfgPath)
	if err != nil {
		glog.Errorf(err.Error())
		syscall.Exit(1)
	}

	if cfg.Verbosity >= 2 {
		etcd.OpenDebug()
	}

	srv := server.New(*cfg)
	srv.Run()

	reconfigure := func() {
		glog.Infof("Reloading config file from %s", *cfgPath)
		cfg, err := loadConfigFromPath(*cfgPath)
		if err != nil {
			glog.Errorf(err.Error())
			syscall.Exit(1)
		} else {
			srv.Configure(cfg)
		}
	}

	listenForSignal(syscall.SIGHUP, reconfigure)
}
Example #2
0
// NewController setup debug mode and return an initialized controller
func NewController(user string, debug bool) *Controller {
	// Print out requests etcd is processing
	if debug {
		etcd.OpenDebug()
	}
	// Default config
	//TODO machines ip https://github.com/coreos/go-etcd/blob/master/etcd/client.go
	machines := []string{"http://127.0.0.1:4001"}
	return &Controller{
		db:          etcd.NewClient(machines),
		maxMachines: MaxMachinesRule,
		user:        user,
	}
}
Example #3
0
// EtcdCheckCredentials queries the etcd database to compare given and stored hashes.
func EtcdCheckCredentials(username, hash string, debug bool) (bool, error) {
	//TODO This is no longer hash but clear passwd for now
	if debug {
		etcd.OpenDebug()
		defer etcd.CloseDebug()
	}
	//FIXME Should I use controller here ?
	machines := []string{"http://127.0.0.1:4001"}
	storage := etcd.NewClient(machines)
	// Global settings
	response, err := storage.Get(filepath.Join("hivy/security", username, "password"))
	fmt.Println(response)
	fmt.Println(username)
	if err != nil || len(response) != 1 {
		return false, fmt.Errorf("[db.EtcdCheckCredentials::storage.Get] %v\n", err)
	}
	return (hash == response[0].Value), nil
}
Example #4
0
func main() {
	// We use a custom FlagSet since golang/glog adds a bunch of flags we
	// do not want to publish
	flagset := flag.NewFlagSet("coreinit", flag.ExitOnError)
	cfgPath := flagset.String("config_file", "", "Path to config file.")
	err := flagset.Parse(os.Args[1:])

	// We do this manually since we're using a custom FlagSet
	if err == flag.ErrHelp {
		flag.Usage()
		syscall.Exit(1)
	}

	// Print out to stderr by default (stderr instead of stdout due to glog's choices)
	flag.Lookup("logtostderr").Value.Set("true")

	cfg, err := loadConfigFromPath(*cfgPath)
	if err != nil {
		glog.Errorf(err.Error())
		syscall.Exit(1)
	}

	if cfg.Verbosity >= 3 {
		etcd.OpenDebug()
	}

	srv := server.New(*cfg)
	srv.Run()

	reconfigure := func() {
		glog.Infof("Reloading config file from %s", *cfgPath)
		cfg, err := loadConfigFromPath(*cfgPath)
		if err != nil {
			glog.Errorf(err.Error())
			syscall.Exit(1)
		} else {
			srv.Configure(cfg)
		}
	}

	listenForSignal(syscall.SIGHUP, reconfigure)
}