Added Exit(-1) on bad cmd args, fixed bug with SSH and Tun starting with token

This commit is contained in:
Alex Lyulkov 2015-09-04 23:57:46 +03:00
parent 4733028760
commit 4d5d0e618f
2 changed files with 12 additions and 7 deletions

View file

@ -170,7 +170,7 @@ func initSSH(t *TeleportService, cfg Config) error {
// this means the server has not been initialized yet we are starting
// the registering client that attempts to connect ot the auth server
// and provision the keys
return initRegister(t, *cfg.SSH.Token, cfg)
return initRegister(t, *cfg.SSH.Token, cfg, initSSHEndpoint)
}
return initSSHEndpoint(t, cfg)
}
@ -212,7 +212,8 @@ func initSSHEndpoint(t *TeleportService, cfg Config) error {
return nil
}
func initRegister(t *TeleportService, token string, cfg Config) error {
func initRegister(t *TeleportService, token string, cfg Config,
initFunc func(*TeleportService, Config) error) error {
// we are on the same server as the auth endpoint
// and there's no token. we can handle this
if cfg.Auth.Enabled && token == "" {
@ -236,7 +237,7 @@ func initRegister(t *TeleportService, token string, cfg Config) error {
return err
}
log.Infof("teleport:register registered successfully")
return initSSHEndpoint(t, cfg)
return initFunc(t, cfg)
})
return nil
}
@ -256,7 +257,7 @@ func initTun(t *TeleportService, cfg Config) error {
// this means the server has not been initialized yet we are starting
// the registering client that attempts to connect ot the auth server
// and provision the keys
return initRegister(t, *cfg.Tun.Token, cfg)
return initRegister(t, *cfg.Tun.Token, cfg, initTunAgent)
}
return initTunAgent(t, cfg)
}

View file

@ -62,12 +62,12 @@ func main() {
srv, err := service.NewTeleport(cfg)
if err != nil {
fmt.Printf("error starting teleport: %v\n", err)
return
os.Exit(-1)
}
if err := srv.Start(); err != nil {
log.Errorf("teleport failed to start with error: %v", err)
return
os.Exit(-1)
}
srv.Wait()
}
@ -162,7 +162,11 @@ func getFilledConfig(args []string, commandIsFirst bool) service.Config {
cfg.Tun.Token = tunCmd.Flag("token", "one time provisioning token for tun agent to register with authority").OverrideDefaultFromEnvar("TELEPORT_TUN_TOKEN").String()
kingpin.MustParse(app.Parse(args))
_, err := app.Parse(args)
if err != nil {
fmt.Printf("Error: %s, try --help\n", err.Error())
os.Exit(-1)
}
return cfg