Beispiel #1
0
func (cmd *KontrolKey) Run(ctx context.Context) error {
	kiteID := uuid.NewV4().String()

	keycreator := &keycreator.Key{
		KontrolURL:        cmd.kontrolURL,
		KontrolPrivateKey: defaultPrivateKey,
		KontrolPublicKey:  defaultPublicKey,
	}

	kiteKey, err := keycreator.Create(cmd.username, kiteID)
	if err != nil {
		return err
	}

	f := os.Stdout
	if cmd.output != "-" {
		f, err = os.Create(cmd.output)
		if err != nil {
			return err
		}
	}

	_, err = io.Copy(f, strings.NewReader(kiteKey))
	return nonil(err, f.Sync(), f.Close())
}
Beispiel #2
0
// provisionData creates the base64-json-encoded userdata.Value to be sent
// altogether with create request.
func (cmd *VagrantCreate) provisionData(log logging.Logger) (string, error) {
	kiteID := uuid.NewV4().String()

	keycreator := &keycreator.Key{
		KontrolURL:        cmd.KontrolURL,
		KontrolPrivateKey: defaultPrivateKey,
		KontrolPublicKey:  defaultPublicKey,
	}

	kiteKey, err := keycreator.Create(cmd.Username, kiteID)
	if err != nil {
		return "", err
	}

	data := &puser.Value{
		Username:        cmd.Username,
		Groups:          []string{"sudo"},
		Hostname:        cmd.Username,
		KiteKey:         kiteKey,
		LatestKlientURL: cmd.KlientURL,
		RegisterURL:     cmd.RegisterURL,
		KontrolURL:      cmd.KontrolURL,
	}

	log.Debug("provision data: %+v", data)

	p, err := json.Marshal(data)
	if err != nil {
		return "", err
	}

	return base64.StdEncoding.EncodeToString(p), nil
}