Esempio n. 1
0
func init() {
	stack.Konfig = &config.Konfig{
		Endpoints: &config.Endpoints{
			Koding:       config.NewEndpoint(""),
			Tunnel:       config.NewEndpoint(""),
			KlientLatest: config.NewEndpoint(""),
		},
	}
}
Esempio n. 2
0
func newEndpoints(cfg *Config) *config.Endpoints {
	e := config.NewKonfig(&config.Environments{Env: cfg.Environment}).Endpoints

	if cfg.KodingURL != nil {
		e.Koding.Public = cfg.KodingURL
	}

	if cfg.TunnelURL != "" {
		if u, err := url.Parse(cfg.TunnelURL); err == nil {
			u.Path = "/kite"
			e.Tunnel = config.NewEndpoint(u.String())
		}
	}

	return e
}
Esempio n. 3
0
func migrateKonfigBolt(cache *config.Cache) error {
	var used usedKonfig
	var oldKonfig config.Konfig
	var konfigs = make(config.Konfigs)

	if err := cache.GetValue("konfig", &oldKonfig); isFatal(err) {
		return err
	}

	if err := cache.GetValue("konfigs", &konfigs); isFatal(err) {
		return err
	}

	if err := cache.GetValue("konfigs.used", &used); isFatal(err) {
		return err
	}

	// If old konfig exists, try to migrate it over to konfigs.
	if oldKonfig.Valid() == nil {
		id := oldKonfig.ID()

		if _, ok := konfigs[id]; !ok {
			if oldKonfig.Endpoints == nil {
				oldKonfig.Endpoints = &config.Endpoints{}
			}

			if u, err := url.Parse(oldKonfig.KontrolURL); err == nil && oldKonfig.KontrolURL != "" {
				u.Path = ""
				oldKonfig.Endpoints.Koding = config.NewEndpointURL(u)
			}

			if oldKonfig.TunnelURL != "" {
				oldKonfig.Endpoints.Tunnel = config.NewEndpoint(oldKonfig.TunnelURL)
			}

			// Best-effort attemp to ensure /etc/kite/kite.key is stored
			// in ~/.config/koding/konfig.bolt, so it is possible to
			// use kd / konfig with koding deployments that sign with
			// different kontrol keys, e.g. production <-> sandbox or
			// production <-> self-hosted opensource version.
			_ = migrateKiteKey(&oldKonfig)

			konfigs[id] = &oldKonfig

			_ = cache.SetValue("konfigs", konfigs)
		}
	}

	// If no konfig is in use (e.g. we just migrated one),
	// try to set to the default one.
	if used.ID == "" && len(konfigs) == 1 {
		for id, konfig := range konfigs {
			if konfig.Valid() == nil {
				_ = cache.SetValue("konfigs.used", &usedKonfig{ID: id})
			}
			break
		}
	}

	return nil
}