Exemple #1
0
func init() {
	config.ReadConfigFile("settings.yaml")
	//TODO: Error Checking
	basePath, _ := config.GetString("TEMPLATES:BASE")
	layoutsPath, _ := config.GetString("TEMPLATES:LAYOUTS")
	partialsPath, _ := config.GetString("TEMPLATES:PARTIALS")

	dir, _ := os.Getwd()
	templatesPath = filepath.Join(dir, basePath)
	fmt.Printf("Processing templates in %s\n", templatesPath)

	if templates == nil {
		templates = make(map[string]*template.Template)
	}

	layouts, err := filepath.Glob(templatesPath + "/" + layoutsPath + "/*")
	if err != nil {
		log.Fatal(err)
	}

	partials, err := filepath.Glob(templatesPath + "/" + partialsPath + "/*")
	if err != nil {
		log.Fatal(err)
	}

	for _, layout := range layouts {
		files := append(partials, layout)
		templates[filepath.Base(layout)] = template.Must(template.ParseFiles(files...))
	}

	UserRepo = user.NewBaseUserRepository()
	if _, err := UserRepo.NewUser("jeff", "password"); err != nil {
		fmt.Println(err)
	}
}
Exemple #2
0
func main() {
	var err error
	log, err = syslog.New(syslog.LOG_INFO, "gandalf-listener")
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		panic(err.Error())
	}
	err = config.ReadConfigFile("/etc/gandalf.conf")
	if err != nil {
		log.Err(err.Error())
		fmt.Fprintln(os.Stderr, err.Error())
		return
	}
	_, _, err = parseGitCommand()
	if err != nil {
		log.Err(err.Error())
		fmt.Fprintln(os.Stderr, err.Error())
		return
	}
	a := action()
	if a == "git-receive-pack" {
		executeAction(hasWritePermission, "You don't have access to write in this repository.", os.Stdout)
		return
	}
	if a == "git-upload-pack" {
		executeAction(hasReadPermission, "You don't have access to read this repository.", os.Stdout)
		return
	}
}
Exemple #3
0
func (s *S) SetUpSuite(c *check.C) {
	err := config.ReadConfigFile("testdata/config.yaml")
	c.Assert(err, check.IsNil)
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "tsuru_api_base_test")
	app.LogPubSubQueuePrefix = "pubsub:api-base-test:"
}
Exemple #4
0
func (s *S) SetUpTest(c *check.C) {
	config.ReadConfigFile("testdata/tsuru.conf")
	conn, err := db.Conn()
	c.Assert(err, check.IsNil)
	defer conn.Close()
	dbtest.ClearAllCollections(conn.Apps().Database)
	repositorytest.Reset()
}
func (v *configFile) Set(value string) error {
	err := config.ReadConfigFile(value)
	if err != nil {
		return err
	}
	v.value = value
	return nil
}
Exemple #6
0
func (s *S) SetUpSuite(c *gocheck.C) {
	err := config.ReadConfigFile("../etc/gandalf.conf")
	c.Assert(err, gocheck.IsNil)
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "gandalf_api_tests")
	s.tmpdir, err = commandmocker.Add("git", "")
	c.Assert(err, gocheck.IsNil)
}
Exemple #7
0
func main() {
	p, _ := filepath.Abs(defaultConfigPath)
	log.Println(fmt.Errorf("Conf: %s", p))
	config.ReadConfigFile(defaultConfigPath)
	name := cmd.ExtractProgramName(os.Args[0])
	manager := buildManager(name)
	manager.Run(os.Args[1:])
}
Exemple #8
0
func FlagResolve(localAddr *string, serverAddr *string, username *string, password *string) {
	flag.Parse()

	if *helpFlag != false {
		//log.Log("info", "", nil)
		fmt.Println("Usage:...........!!!!!")
		os.Exit(0)
	}
	if *versionFlag != false {
		err := config.ReadConfigFile("../client/config/version.yml")
		if err != nil {
			fmt.Println(err)
			os.Exit(0)
		}
		version, _ := config.GetString("version")
		update, _ := config.GetList("update")
		instruction, _ := config.GetString("instruction")
		fmt.Printf("CaeserClient version: %s\n", version)
		fmt.Printf("New speciality contrast to old version: \n")
		for k, v := range update {
			fmt.Printf("%d-- %s\n", k+1, v)
		}
		fmt.Printf("       %s\n", instruction)
		os.Exit(0)
	}
	if *localFlag != "" {
		*localAddr = *localFlag
		log.Log("info", "you set a new addres", log.Fields{"address": *localFlag})
		//fmt.Println("--Notice: you have set a new address", *localAddr)
	} else {
		//fmt.Println("--Didn't set the start port. Caesar will start at default port.")
		log.Log("info", "Didn't set the start port. Caesar will start at default port.", log.Fields{"default address": *localAddr})
	}
	if *serverFlag != "" {
		fp, err := regexp.MatchString(ipPattern, *serverFlag)
		handleError(err)
		if !fp {
			//fmt.Printf("\"%s\" is not a valid address, please check it and try again!\n", *serverFlag)
			warnMsg := *serverFlag + "is not a valid address, please check it and try again!"
			log.Log("warn", warnMsg, nil)
			os.Exit(0)
		}
		*serverAddr = *serverFlag
		log.Log("info", "You have set a new server address", log.Fields{"new address": *serverAddr})
		//fmt.Println("--Notice: you have set a new server address", *serverAddr)
	} else {
		log.Log("info", "Didn't set the server address.Caesar will connect the default address.", log.Fields{"new address": *serverAddr})
		//fmt.Println("--Didn't set the server address. Caesar will connect the default address.")
	}
	if *userFlag != "" && *passwordFlag != "" {
		*username = *userFlag
		*password = *passwordFlag
		fmt.Println(*username, *password)
	} else {
		//fmt.Println("--Anonymous login, can do nothing! Please login with exgist user or register a new user.")
		log.Log("info", "Anonymous login, can do nothing! Please login with exgist user or register a new user.", nil)
	}
}
Exemple #9
0
func listenSignals() {
	ch := make(chan os.Signal, 1)
	signal.Notify(ch, syscall.SIGHUP)
	go func() {
		for range ch {
			config.ReadConfigFile(configPath)
		}
	}()
}
Exemple #10
0
func (s *S) SetUpSuite(c *gocheck.C) {
	err := config.ReadConfigFile("testdata/config.yaml")
	s.conn, err = db.Conn()
	c.Assert(err, gocheck.IsNil)
	s.createUserAndTeam(c)
	s.t = &tsuruTesting.T{}
	s.provisioner = tsuruTesting.NewFakeProvisioner()
	app.Provisioner = s.provisioner
	p := app.Platform{Name: "zend"}
	s.conn.Platforms().Insert(p)
}
Exemple #11
0
func init() {
	err := config.ReadConfigFile("../config/msgserver.yaml")
	if err != nil {
		//fmt.Print(err)
		mylog.Log("err", err.Error(), nil)
	} else {
		mylog.Log("info", "Message server config read!", nil)
	}
	ListenPort, err = config.GetString("listenport")
	handleErr(err)
}
Exemple #12
0
func readConfig(path string) (Config, error) {
	cfg := Config{}
	configFile := filepath.Join(path, "config.yaml")

	err := config.ReadConfigFile(configFile)
	if err != nil {
		return cfg, err
	}

	cfg.Id, err = config.GetString("id")
	if err != nil {
		return cfg, err
	}

	cfg.Hostname, err = config.GetString("hostname")
	if err != nil {
		return cfg, err
	}

	cfg.DiskPath = filepath.Join(path, "disk.qcow")
	cfg.Disk, err = config.GetInt("disk")
	if err != nil {
		return cfg, err
	}

	cfg.Cpu, err = config.GetInt("cpu")
	if err != nil {
		return cfg, err
	}

	cfg.Memory, err = config.GetInt("memory")
	if err != nil {
		return cfg, err
	}

	cfg.DNS, err = config.GetString("dns")
	if err != nil {
		return cfg, err
	}

	cfg.Docker, err = config.GetString("docker")
	if err != nil {
		return cfg, err
	}

	cfg.Extra, err = config.GetString("extra")
	if err != nil {
		return cfg, err
	}

	cfg.Route, err = config.GetBool("route")
	return cfg, err
}
Exemple #13
0
//Read the config file and set the config.
func Readconfig(local *string, server *string) {
	err := config.ReadConfigFile("../client/config/client.yml")
	handleError(err)

	*local, err = config.GetString("localaddress")
	handleError(err)

	*server, err = config.GetString("serveraddress")

	handleError(err)

}
Exemple #14
0
func (s *EventSuite) SetUpSuite(c *check.C) {
	err := config.ReadConfigFile("testdata/config.yaml")
	c.Assert(err, check.IsNil)
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "tsuru_events_api_tests")
	config.Set("auth:hash-cost", 4)
	config.Set("repo-manager", "fake")
	s.conn, err = db.Conn()
	c.Assert(err, check.IsNil)
	s.logConn, err = db.LogConn()
	c.Assert(err, check.IsNil)
}
Exemple #15
0
func (s *S) SetUpSuite(c *gocheck.C) {
	err := config.ReadConfigFile("testdata/config.yaml")
	c.Assert(err, gocheck.IsNil)
	s.conn, err = db.Conn()
	c.Assert(err, gocheck.IsNil)
	s.t = &ttesting.T{}
	s.createUserAndTeam(c)
	s.t.SetGitConfs(c)
	s.provisioner = ttesting.NewFakeProvisioner()
	Provisioner = s.provisioner
	platform := Platform{Name: "python"}
	s.conn.Platforms().Insert(platform)
}
Exemple #16
0
func listenSignals() {
	ch := make(chan os.Signal, 2)
	go func() {
		for sig := range ch {
			switch sig {
			case syscall.SIGUSR1:
				pprof.Lookup("goroutine").WriteTo(os.Stdout, 2)
			case syscall.SIGHUP:
				config.ReadConfigFile(configPath)
			}
		}
	}()
	signal.Notify(ch, syscall.SIGHUP, syscall.SIGUSR1)
}
Exemple #17
0
func (c *tsrCommand) Run(context *cmd.Context, client *cmd.Client) error {
	fmt.Fprintf(context.Stderr, "Opening config file: %s\n", configPath)
	err := config.ReadConfigFile(configPath)
	if err != nil {
		msg := `Could not open tsuru config file at %s (%s).
  For an example, see: tsuru/etc/tsuru.conf
  Note that you can specify a different config file with the --config option -- e.g.: --config=./etc/tsuru.conf
`
		fmt.Fprintf(context.Stderr, msg, configPath, err)
		return err
	}
	fmt.Fprintf(context.Stderr, "Done reading config file: %s\n", configPath)
	return c.Command.Run(context, client)
}
Exemple #18
0
//Load configuration file.
func loadConf() {
	log.Log("info", "Load config file...", nil)
	err := config.ReadConfigFile("../config/server.yaml")
	if err != nil {
		//fmt.Print(err)
		log.Log("err", err.Error(), nil)
	} else {
		log.Log("info", "Completely read!", nil)
	}

	listenAddr, err = config.GetString("rpcAddress")
	handleErr(err)
	msgAddr, err = config.GetString("msgAddress")
	handleErr(err)
}
Exemple #19
0
func (s *S) SetUpSuite(c *check.C) {
	err := config.ReadConfigFile("testdata/config.yaml")
	c.Assert(err, check.IsNil)
	s.conn, err = db.Conn()
	c.Assert(err, check.IsNil)
	s.logConn, err = db.LogConn()
	c.Assert(err, check.IsNil)
	s.provisioner = provisiontest.NewFakeProvisioner()
	Provisioner = s.provisioner
	AuthScheme = nativeScheme
	data, err := json.Marshal(AppLock{})
	c.Assert(err, check.IsNil)
	err = json.Unmarshal(data, &s.zeroLock)
	c.Assert(err, check.IsNil)
}
Exemple #20
0
func configDaemon(imp, file string) {
	var watchers []*fsnotify.Watcher

	// closeWatchers is iterating over available watchers
	// and closes them.
	closeWatchers := func() {
		for i := range watchers {
			watchers[i].Close()
		}
		watchers = []*fsnotify.Watcher{}
	}
	defer closeWatchers() // Close watchers when we are done.

	for {
		// Wait till we are asked to reload the config file.
		<-restart

		// Closing old watchers to create new ones.
		closeWatchers()

		// Trying to read a configuration file..
		err := config.ReadConfigFile(file)
		if err != nil {
			log.Error.Printf(
				`Are you sure "%s" is a path of goal project?
"%s" file is missing.`, imp, file,
			)
			notify <- syscall.SIGTERM
			return
		}

		// Parsing configuration file and extracting the values
		// we need.
		log.Trace.Printf(`Starting to parse "%s"...`, file)
		c := parseConf(file)

		// Start init tasks.
		c.init()

		// Start watching the requested directories.
		w := watcher.NewType()
		watchers = append(watchers, w.ListenFile("./"+ConfigFile, reloadConfig))
		for pattern := range c.watch {
			watchers = append(watchers, w.Listen(pattern, c.watch[pattern]))
		}
	}
}
Exemple #21
0
func (s *S) SetUpSuite(c *gocheck.C) {
	var err error
	log, err = syslog.New(syslog.LOG_INFO, "gandalf-listener")
	c.Check(err, gocheck.IsNil)
	err = config.ReadConfigFile("../etc/gandalf.conf")
	c.Check(err, gocheck.IsNil)
	config.Set("database:name", "gandalf_bin_tests")
	s.user, err = user.New("testuser", map[string]string{})
	c.Check(err, gocheck.IsNil)
	// does not uses repository.New to avoid creation of bare git repo
	s.repo = &repository.Repository{Name: "myapp", Users: []string{s.user.Name}}
	conn, err := db.Conn()
	c.Assert(err, gocheck.IsNil)
	defer conn.Close()
	err = conn.Repository().Insert(s.repo)
	c.Check(err, gocheck.IsNil)
}
Exemple #22
0
func init() {
	err := config.ReadConfigFile("../config/db.yaml")
	if err != nil {
		//fmt.Print(err)
		log.Log("err", err.Error(), nil)
	} else {
		log.Log("info", "DB config read!", nil)
	}
	user, err = config.GetString("username")
	handleErr(err)
	pwd, err = config.GetString("password")
	handleErr(err)
	dbname, err = config.GetString("dbname")
	handleErr(err)
	dbaddress, err = config.GetString("address")
	handleErr(err)
	//log.Log("info", "", log.Fields{"username":user,"password":pwd,"dbname":dbname,"address":dbaddress})
	DB = mysql.New("tcp", "", dbaddress, user, pwd, dbname)
}
Exemple #23
0
func (s *S) SetUpSuite(c *check.C) {
	err := config.ReadConfigFile("testdata/config.yaml")
	c.Assert(err, check.IsNil)
	config.Set("queue:mongo-url", "127.0.0.1:27017")
	config.Set("queue:mongo-database", "queue_app_pkg_tests")
	config.Set("queue:mongo-polling-interval", 0.01)
	config.Set("docker:registry", "registry.somewhere")
	s.conn, err = db.Conn()
	c.Assert(err, check.IsNil)
	s.logConn, err = db.LogConn()
	c.Assert(err, check.IsNil)
	s.provisioner = provisiontest.ProvisionerInstance
	provision.DefaultProvisioner = "fake"
	AuthScheme = nativeScheme
	data, err := json.Marshal(AppLock{})
	c.Assert(err, check.IsNil)
	err = json.Unmarshal(data, &s.zeroLock)
	c.Assert(err, check.IsNil)
	LogPubSubQueuePrefix = "pubsub:app-test:"
}
Exemple #24
0
// LoadOptions TODO: doc
func LoadOptions(configFile string) (Options, error) {
	var options Options
	err := config.ReadConfigFile(configFile)
	if err != nil {
		return options, err
	}

	brokers, err := config.GetList("kafka:brokers")
	if err != nil || len(brokers) == 0 {
		return options, errors.New("You must provide at least one kafka broker")
	}

	zookeepers, err := config.GetList("kafka:zookeeper")
	if err != nil || len(zookeepers) == 0 {
		return options, errors.New("You must provide at least one zookeeper")
	}

	consumerGroup, err := config.GetString("kafka:group")
	if err != nil {
		return options, errors.New("You must provide the consumer group")
	}

	kafkaTopics, err := config.GetList("kafka:topics")
	if err != nil || len(kafkaTopics) == 0 {
		return options, errors.New("You must provide at least one topic")
	}

	consumersCmd, err := config.GetList("consumers")
	if err != nil || len(consumersCmd) == 0 {
		return options, errors.New("You must provide at least one consumer command")
	}

	options = Options{
		Brokers:       brokers,
		Zookeepers:    zookeepers,
		ConsumerGroup: consumerGroup,
		KafkaTopics:   kafkaTopics,
		ConsumersCmd:  consumersCmd,
	}
	return options, nil
}
Exemple #25
0
func main() {
	gopsAgent := agent.Agent{
		HandleSignals: false,
	}
	if err := gopsAgent.Start(); err != nil {
		log.Fatalf("Unable to start a Gops agent %s", err)
	}
	defer gopsAgent.Stop()
	if inDockerMachineDriverMode() {
		err := dockermachine.RunDriver(os.Getenv(localbinary.PluginEnvDriverName))
		if err != nil {
			log.Fatalf("Error running driver: %s", err)
		}
	} else {
		localbinary.CurrentBinaryIsDockerMachine = true
		config.ReadConfigFile(configPath)
		listenSignals()
		m := buildManager()
		m.Run(os.Args[1:])
	}
}
Exemple #26
0
func FlagResolve(listenAddr *string) {
	flag.Parse()

	if *versionFlag != false {
		err := config.ReadConfigFile("../config/server.yml")
		if err != nil {
			fmt.Println(err)
			os.Exit(0)
		}
		version, _ := config.GetString("version")
		update, _ := config.GetList("update")
		instruction, _ := config.GetString("instruction")
		fmt.Printf("CaeserClient version: %s\n", version)
		fmt.Printf("New speciality contrast to old version: \n")
		for k, v := range update {
			fmt.Printf("%d-- %s\n", k+1, v)
		}
		fmt.Printf("       %s\n", instruction)
		os.Exit(0)
	}
	if *runtimeFlag == "min" {
		log.Log("warn", "Start up with least CPU's resousces", log.Fields{"Occupy CPU Num": 1})
	}

	if *listenFlag != "" {
		fp, err := regexp.MatchString(ipPattern, *listenFlag)
		handleError(err)
		if !fp {
			//fmt.Printf("\"%s\" is not a valid address, please check it and try again!\n", *listenFlag)
			log.Log("fatal", "-address is not a valid address, please check it and try again!", map[string]interface{}{"address": *listenFlag})
			os.Exit(0)
		}
		*listenAddr = *listenFlag
		fmt.Println("--Notice: you have set a new listen address", *listenAddr)
	} else {
		//fmt.Println("--Didn't set the listen address. Server will start at default address.")
		log.Log("info", "Didn't set the listen address. Server will start at default address.", log.Fields{"Default Address": *listenAddr})
	}
}
Exemple #27
0
	"github.com/urfave/cli"
)

var initCommand = cli.Command{
	Name:        "init",
	Usage:       "initialize your dlite installation",
	Description: "perform setup of dlite for the currently logged in user",
	Action: func(ctx *cli.Context) error {
		currentUser := getUser()
		configPath := getPath(currentUser)
		binPath := filepath.Join(configPath, "bin")
		configFile := filepath.Join(configPath, "config.yaml")
		diskFile := filepath.Join(configPath, "disk.qcow")
		cfg := Config{}

		err := config.ReadConfigFile(configFile)
		if err == nil {
			fmt.Println("WARNING: It appears you have already initialized dlite. Continuing will destroy your current virtual machine and its configuration.")
			if !confirm("Continue? (y/n)") {
				return cli.NewExitError("Aborting initialization...", 1)
			}
		}

		fmt.Println("")

		err = os.RemoveAll(configPath)
		if err != nil {
			return cli.NewExitError(err.Error(), 1)
		}

		err = os.MkdirAll(configPath, 0755)
Exemple #28
0
func (s *S) SetUpSuite(c *gocheck.C) {
	err := config.ReadConfigFile("../etc/gandalf.conf")
	c.Assert(err, gocheck.IsNil)
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "gandalf_repository_tests")
}
Exemple #29
0
func main() {
	config.ReadConfigFile(configPath)
	listenSignals()
	m := buildManager()
	m.Run(os.Args[1:])
}
Exemple #30
0
func (s *S) SetUpSuite(c *gocheck.C) {
	err := config.ReadConfigFile("../etc/gandalf.conf")
	c.Check(err, gocheck.IsNil)
	config.Set("database:name", "gandalf_user_tests")
}