Example #1
0
func main() {
	flag.Parse()

	if *flagEnableOutput {
		fmt.Printf("%v", testutil.NewKiteKey().Raw)
		os.Exit(0)
	}

	kitekey.Write(testutil.NewKiteKey().Raw)
}
Example #2
0
// InitializeSelf registers his host by writing a key to ~/.kite/kite.key
func (k *Kontrol) InitializeSelf() error {
	if len(k.lastPublic) == 0 && len(k.lastPrivate) == 0 {
		return errors.New("Please initialize AddKeyPair() method")
	}

	key, err := k.registerUser(k.Kite.Config.Username, k.lastPublic[0], k.lastPrivate[0])
	if err != nil {
		return err
	}
	return kitekey.Write(key)
}
Example #3
0
func (c *Register) Run(args []string) int {
	var kontrolURL, username string
	var err error

	flags := flag.NewFlagSet("register", flag.ExitOnError)
	flags.StringVar(&kontrolURL, "to", defaultKontrolURL, "Kontrol URL")
	flags.StringVar(&username, "username", "", "Username")
	flags.Parse(args)

	// Open up a prompt
	if username == "" {
		username, err = c.Ui.Ask("Username:"******"" {
			c.Ui.Error("Username can not be empty.")
			return 1
		}
	}

	c.KiteClient.Config.Username = username

	if _, err := kitekey.Read(); err == nil {
		c.Ui.Info("Already registered. Registering again...")
	}

	kontrol := c.KiteClient.NewClient(kontrolURL)
	if err := kontrol.Dial(); err != nil {
		c.Ui.Error(err.Error())
		return 1
	}

	result, err := kontrol.TellWithTimeout("registerMachine", 5*time.Minute, username)
	if err != nil {
		c.Ui.Error(err.Error())
		return 1
	}

	if err := kitekey.Write(result.MustString()); err != nil {
		c.Ui.Error(err.Error())
		return 1
	}

	c.Ui.Info("Registered successfully")

	return 0
}