예제 #1
0
파일: kontrol.go 프로젝트: koding/koding
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())
}
예제 #2
0
파일: vagrant.go 프로젝트: koding/koding
// 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
}