예제 #1
0
파일: main.go 프로젝트: rogpeppe/juju
func load() error {
	var confPath string
	if len(os.Args) == 2 {
		if _, err := os.Stat(os.Args[1]); err == nil {
			confPath = os.Args[1]
		}
	}
	if confPath == "" {
		return fmt.Errorf("usage: %s <config path>", filepath.Base(os.Args[0]))
	}
	conf, err := charmstore.ReadConfig(confPath)
	if err != nil {
		return err
	}
	if conf.MongoURL == "" {
		return fmt.Errorf("missing mongo-url in config file")
	}
	s, err := charmstore.Open(conf.MongoURL)
	if err != nil {
		return err
	}
	defer s.Close()
	err = charmstore.PublishCharmsDistro(s, lpad.Production)
	if _, ok := err.(charmstore.PublishBranchErrors); ok {
		// Ignore branch errors since they're commonplace here.
		// They're logged, though.
		return nil
	}
	return err
}
예제 #2
0
func serve() error {
	var confPath string
	if len(os.Args) == 2 {
		if _, err := os.Stat(os.Args[1]); err == nil {
			confPath = os.Args[1]
		}
	}
	if confPath == "" {
		return fmt.Errorf("usage: %s <config path>", filepath.Base(os.Args[0]))
	}
	conf, err := charmstore.ReadConfig(confPath)
	if err != nil {
		return err
	}
	if conf.MongoURL == "" || conf.APIAddr == "" {
		return fmt.Errorf("missing mongo-url or api-addr in config file")
	}
	s, err := charmstore.Open(conf.MongoURL)
	if err != nil {
		return err
	}
	defer s.Close()
	server, err := charmstore.NewServer(s)
	if err != nil {
		return err
	}
	return http.ListenAndServe(conf.APIAddr, server)
}
예제 #3
0
func (s *ConfigSuite) TestReadConfig(c *gc.C) {
	confDir := c.MkDir()
	f, err := os.Create(path.Join(confDir, "charmd.conf"))
	c.Assert(err, gc.IsNil)
	cfgPath := f.Name()
	{
		defer f.Close()
		fmt.Fprint(f, testConfig)
	}

	dstr, err := charmstore.ReadConfig(cfgPath)
	c.Assert(err, gc.IsNil)
	c.Assert(dstr.MongoURL, gc.Equals, "localhost:23456")
}
예제 #4
0
파일: config.go 프로젝트: rogpeppe/juju
func (c *ConfigCommand) ReadConfig(ctx *cmd.Context) (err error) {
	c.Config, err = charmstore.ReadConfig(ctx.AbsPath(c.ConfigPath))
	return err
}