func (c *Client) Read(e *config.Environments) *config.Konfig { c.init() k := config.NewKonfig(e) _ = c.commit(func(cache *config.Cache) error { var used usedKonfig var konfigs = make(config.Konfigs) if err := cache.GetValue("konfigs.used", &used); err != nil { return err } if err := cache.GetValue("konfigs", &konfigs); err != nil { return err } if mixin, ok := konfigs[used.ID]; ok { if err := mergeIn(k, mixin); err != nil { return err } } return nil }) return k }
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 }
func main() { var cfg kloud.Config kloudErr := config.Load(&cfg) var schemaCfg SchemaConfig if err := config.Load(&schemaCfg); err == nil && schemaCfg.GenSchema != "" { if err := genSchema(schemaCfg.GenSchema); err != nil { log.Fatal(err) } return } if kloudErr != nil { log.Fatal(kloudErr) } // Load the config, it's reads environment variables or from flags if cfg.Version { fmt.Println(stack.VERSION) os.Exit(0) } k, err := kloud.New(&cfg) if err != nil { log.Fatal(err) } stack.Konfig = konfig.NewKonfig(&konfig.Environments{ Env: k.Kite.Config.Environment, }) // DataDog listens to it go func() { err := http.ListenAndServe("0.0.0.0:6060", nil) if err != nil { log.Fatal(err) } }() k.Kite.Run() }
func migrateKiteKey(konfig *config.Konfig) error { // KiteKey already exists in the DB - we don't care // whether it's our one or user overriden it explictely // as long as it's there. if konfig.KiteKey != "" { return nil } defaultKitekey := config.NewKonfig(&config.Environments{Env: konfig.Environment}).KiteKeyFile if defaultKitekey == "" { defaultKitekey = filepath.FromSlash("/etc/kite/kite.key") } kitekey := konfig.KiteKeyFile if kitekey == "" { kitekey = defaultKitekey } if _, err := os.Stat(kitekey); err != nil { // Either no access to the file or it does not exist, // in either case nothing to do here. return nil } p, err := ioutil.ReadFile(kitekey) if err != nil { return err } if konfig.KiteKeyFile == defaultKitekey { konfig.KiteKeyFile = "" } konfig.KiteKey = string(p) return nil }
import ( konfig "koding/kites/config" "koding/kites/config/configstore" ) var ( Version string Environment string ) const ( Name = "klient" Region = "public-region" ) var envs = &konfig.Environments{ Env: Environment, } // Konfig represents a klient configuration. var Konfig = ReadKonfig() // Builtin represents a builtin configuration. var Builtin = konfig.NewKonfig(envs) // ReadKonfig reads klient configuration. func ReadKonfig() *konfig.Konfig { return configstore.Read(envs) }