Example #1
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
	}
	db.Connect()
	err = validateCmd()
	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
	}
}
Example #2
0
func main() {
	dry := flag.Bool("dry", false, "dry-run: does not start the server (for testing purpose)")
	configFile := flag.String("config", "/etc/gandalf.conf", "Gandalf configuration file")
	flag.Parse()

	err := config.ReadConfigFile(*configFile)
	if err != nil {
		msg := `Could not find gandalf config file. Searched on %s.
For an example conf check gandalf/etc/gandalf.conf file.`
		log.Panicf(msg, *configFile)
	}
	db.Connect()
	router := pat.New()
	router.Post("/user/:name/key", http.HandlerFunc(api.AddKey))
	router.Del("/user/:name/key/:keyname", http.HandlerFunc(api.RemoveKey))
	router.Post("/user", http.HandlerFunc(api.NewUser))
	router.Del("/user/:name", http.HandlerFunc(api.RemoveUser))
	router.Post("/repository", http.HandlerFunc(api.NewRepository))
	router.Post("/repository/grant", http.HandlerFunc(api.GrantAccess))
	router.Del("/repository/revoke", http.HandlerFunc(api.RevokeAccess))
	router.Del("/repository/:name", http.HandlerFunc(api.RemoveRepository))

	port, err := config.GetString("webserver:port")
	if err != nil {
		panic(err)
	}
	if !*dry {
		log.Fatal(http.ListenAndServe(port, router))
	}
}
Example #3
0
func (s *S) SetUpSuite(c *C) {
	err := config.ReadConfigFile("../etc/gandalf.conf")
	c.Assert(err, IsNil)
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "gandalf_repository_tests")
	db.Connect()
}
Example #4
0
///////////////////////////////////////////////////////////////////////////////////////////////////////
// If filePath is defined and the file exists, Load gets the configuration from there, otherwise
// it looks for the filename, specified in NewConfig in the current users home directory. If no file can be found
// the function creates a file with the users default values.
///////////////////////////////////////////////////////////////////////////////////////////////////////
func (c *Config) Load(loadDefaults loadDefFn, filePath string, watchConfig bool) error {

	if len(filePath) == 0 {
		usr, err := user.Current()
		if err != nil {
			return err
		}

		filePath = path.Join(usr.HomeDir, c.configFileName)
	}

	loadDefaults(c)
	if _, err := os.Stat(filePath); err == nil {
		if watchConfig {
			if err := config.ReadAndWatchConfigFile(filePath); err != nil {
				return err
			}
		} else {
			if err := config.ReadConfigFile(filePath); err != nil {
				return err
			}
		}
	} else {
		if err = c.writeDefConfigFile(filePath); err != nil {
			return err
		}
	}

	return nil
}
Example #5
0
func (v *configFile) Set(value string) error {
	err := config.ReadConfigFile(value)
	if err != nil {
		return err
	}
	v.value = value
	return nil
}
Example #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")
	db.Connect()
	s.tmpdir, err = commandmocker.Add("git", "")
	c.Assert(err, gocheck.IsNil)
}
Example #7
0
func main() {
	var (
		configFile string
		dry        bool
	)
	logger, err := syslog.NewLogger(syslog.LOG_INFO, stdlog.LstdFlags)
	if err != nil {
		stdlog.Fatal(err)
	}
	log.SetLogger(logger)
	flag.StringVar(&configFile, "config", "/etc/tsuru/tsuru.conf", "tsuru config file")
	flag.BoolVar(&dry, "dry", false, "dry-run: does not start the agent (for testing purposes)")
	flag.Parse()
	err = config.ReadConfigFile(configFile)
	if err != nil {
		fatal(err)
	}
	connString, err := config.GetString("database:url")
	if err != nil {
		fatal(err)
	}
	dbName, err := config.GetString("database:name")
	if err != nil {
		fatal(err)
	}
	db.Session, err = db.Open(connString, dbName)
	if err != nil {
		fatal(err)
	}
	defer db.Session.Close()
	fmt.Printf("Connected to MongoDB server at %s.\n", connString)
	fmt.Printf("Using the database %q.\n\n", dbName)

	if !dry {
		provisioner, err := config.GetString("provisioner")
		if err != nil {
			fmt.Printf("Warning: %q didn't declare a provisioner, using default provisioner.\n", configFile)
			provisioner = "juju"
		}
		app.Provisioner, err = provision.Get(provisioner)
		if err != nil {
			fatal(err)
		}
		fmt.Printf("Using %q provisioner.\n\n", provisioner)

		qServer, err := config.GetString("queue-server")
		if err != nil {
			fatal(err)
		}
		fmt.Printf("Connected to queue server at %s.\n", qServer)
		go handleMessages()
		ticker := time.Tick(time.Minute)
		fmt.Println("tsuru collector agent started...")
		jujuCollect(ticker)
	}
}
Example #8
0
func (s *S) SetUpSuite(c *C) {
	var err error
	db.Session, err = db.Open("127.0.0.1:27017", "tsuru_collector_test")
	c.Assert(err, IsNil)
	s.provisioner = ttesting.NewFakeProvisioner()
	app.Provisioner = s.provisioner
	err = config.ReadConfigFile("../etc/tsuru.conf")
	c.Assert(err, IsNil)
	config.Set("queue-server", "127.0.0.1:0")
}
Example #9
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.t.StartAmzS3AndIAM(c)
	s.t.SetGitConfs(c)
	s.provisioner = tsuruTesting.NewFakeProvisioner()
	app.Provisioner = s.provisioner
}
Example #10
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.StartAmzS3AndIAM(c)
	s.t.SetGitConfs(c)
	s.provisioner = ttesting.NewFakeProvisioner()
	Provisioner = s.provisioner
	platform := Platform{Name: "python"}
	s.conn.Platforms().Insert(platform)
}
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")
	db.Connect()
	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}}
	err = db.Session.Repository().Insert(s.repo)
	c.Check(err, gocheck.IsNil)
}
Example #12
0
func main() {
	config.ReadConfigFile(configFile)
	path, err := config.GetString("database")
	if err != nil {
		log.Panicln("No database file specified in config file.")
		os.Exit(1)
	}
	db.Init(path)
	models.RegisterEntry()
	models.RegisterValve()
	models.RegisterSchedule()

	flag.Parse()
	flag.Visit(actionFlag)

	flag.PrintDefaults()
}
Example #13
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.rfs = &ftesting.RecordingFs{}
	file, err := s.rfs.Create("/dev/urandom")
	c.Assert(err, gocheck.IsNil)
	file.Write([]byte{16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31})
	fsystem = s.rfs
	s.t = &ttesting.T{}
	s.createUserAndTeam(c)
	s.t.StartAmzS3AndIAM(c)
	s.t.SetGitConfs(c)
	s.provisioner = ttesting.NewFakeProvisioner()
	Provisioner = s.provisioner
}
Example #14
0
func (s *S) SetUpSuite(c *C) {
	var err error
	err = config.ReadConfigFile("../etc/tsuru.conf")
	c.Assert(err, IsNil)
	db.Session, err = db.Open("127.0.0.1:27017", "tsuru_app_test")
	c.Assert(err, IsNil)
	s.rfs = &fsTesting.RecordingFs{}
	file, err := s.rfs.Open("/dev/urandom")
	c.Assert(err, IsNil)
	file.Write([]byte{16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31})
	fsystem = s.rfs
	s.t = &tsuruTesting.T{}
	s.createUserAndTeam(c)
	s.t.StartAmzS3AndIAM(c)
	s.t.SetGitConfs(c)
	s.provisioner = tsuruTesting.NewFakeProvisioner()
	Provisioner = s.provisioner
}
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")
	db.Connect()
}
Example #16
0
File: main.go Project: ngtuna/tsuru
func main() {
	config.ReadConfigFile(defaultConfigPath)
	m := buildManager()
	m.Run(os.Args[1:])
}
Example #17
0
func (s *S) SetUpSuite(c *C) {
	var err error
	err = config.ReadConfigFile("../etc/tsuru.conf")
	c.Assert(err, IsNil)
}
func (s *S) SetUpSuite(c *gocheck.C) {
	config.ReadConfigFile("testdata/tsuru.conf")
}
Example #19
0
func main() {
	goopt.Description = func() string {
		return "Manage server with ssh."
	}
	goopt.Version = "0.05"
	goopt.Summary = "one line to SSH'em all"
	goopt.Parse(nil)
	err := config.ReadConfigFile(CONF_FILE)
	hosts := GetServers(*group)

	if *showlist {
		showListCommand()
	}

	action := ACTION_SSH

	if len(*src) == 0 && len(*dest) > 0 {
		fmt.Println("--src should be setted")
		os.Exit(1)
	}
	if len(*src) > 0 && len(*dest) == 0 {
		fmt.Println("--dest should be setted")
		os.Exit(1)
	}

	if len(*src) > 0 && len(*dest) > 0 {
		action = ACTION_SCP
		if len(*command) > 0 {
			fmt.Println("The command flag will be ignored")
		}
		if len(*execute) > 0 {
			fmt.Println("The execute flag will be ignored")
		}
	}

	if len(*syncfile) > 0 {
		action = ACTION_SYNC_FILE
	}
	if len(*syncgroup) > 0 {
		action = ACTION_SYNC_GROUP
		hosts = GetServers(*syncgroup)
		*group = *syncgroup
	}

	cmd := *execute
	if len(*command) > 0 {
		cmd, err = config.GetString("commands:" + *command + ":cmd")
		if err != nil {
			fmt.Printf("Command does not exists: %s\n", *command)
			os.Exit(1)
		}
	}

	if len(*pwd) == 0 {
		//*pwd, _ = getpass.GetPass()
		var pass string
		fmt.Print("Password: "******"%s", &pass)
		*pwd = pass
	}

	sshResultChan := make(chan string)
	for _, host := range hosts {
		switch action {
		case ACTION_SSH:
			go executeSsh(sshResultChan, host, cmd)

		case ACTION_SCP:
			go executeScp(sshResultChan, host, *src, *dest)

		case ACTION_SYNC_FILE:
			fmt.Println(sshResultChan, "sync file")
			os.Exit(1)

		case ACTION_SYNC_GROUP:
			go syncGroup(sshResultChan, *group, host)
			//os.Exit(1)
		}
	}

	if !*silent {
		fmt.Println("$", cmd, "\n")
	}
	for _, _ = range hosts {
		//Catch the result
		res := <-sshResultChan
		fmt.Println(res)
	}

	if err != nil {
		panic("Failed to dial: " + err.Error())
	}

}
Example #20
0
func main() {
	logger, err := syslog.NewLogger(syslog.LOG_INFO, stdlog.LstdFlags)
	if err != nil {
		stdlog.Fatal(err)
	}
	log.SetLogger(logger)
	configFile := flag.String("config", "/etc/tsuru/tsuru.conf", "tsuru config file")
	dry := flag.Bool("dry", false, "dry-run: does not start the server (for testing purpose)")
	flag.Parse()
	err = config.ReadConfigFile(*configFile)
	if err != nil {
		fatal(err)
	}
	connString, err := config.GetString("database:url")
	if err != nil {
		fatal(err)
	}
	dbName, err := config.GetString("database:name")
	if err != nil {
		fatal(err)
	}
	db.Session, err = db.Open(connString, dbName)
	if err != nil {
		fatal(err)
	}
	defer db.Session.Close()
	fmt.Printf("Connected to MongoDB server at %s.\n", connString)
	fmt.Printf("Using the database %q.\n\n", dbName)

	m := pat.New()

	m.Get("/services/instances", AuthorizationRequiredHandler(consumption.ServicesInstancesHandler))
	m.Post("/services/instances", AuthorizationRequiredHandler(consumption.CreateInstanceHandler))
	m.Put("/services/instances/:instance/:app", AuthorizationRequiredHandler(api.BindHandler))
	m.Del("/services/instances/:instance/:app", AuthorizationRequiredHandler(api.UnbindHandler))
	m.Del("/services/c/instances/:name", AuthorizationRequiredHandler(consumption.RemoveServiceInstanceHandler))
	m.Get("/services/instances/:instance/status", AuthorizationRequiredHandler(consumption.ServiceInstanceStatusHandler))

	m.Get("/services", AuthorizationRequiredHandler(service_provision.ServicesHandler))
	m.Post("/services", AuthorizationRequiredHandler(service_provision.CreateHandler))
	m.Put("/services", AuthorizationRequiredHandler(service_provision.UpdateHandler))
	m.Del("/services/:name", AuthorizationRequiredHandler(service_provision.DeleteHandler))
	m.Get("/services/:name", AuthorizationRequiredHandler(consumption.ServiceInfoHandler))
	m.Get("/services/c/:name/doc", AuthorizationRequiredHandler(consumption.Doc))
	m.Get("/services/:name/doc", AuthorizationRequiredHandler(service_provision.GetDocHandler))
	m.Put("/services/:name/doc", AuthorizationRequiredHandler(service_provision.AddDocHandler))
	m.Put("/services/:service/:team", AuthorizationRequiredHandler(service_provision.GrantAccessToTeamHandler))
	m.Del("/services/:service/:team", AuthorizationRequiredHandler(service_provision.RevokeAccessFromTeamHandler))

	m.Del("/apps/:name", AuthorizationRequiredHandler(api.AppDelete))
	m.Get("/apps/:name/repository/clone", Handler(api.CloneRepositoryHandler))
	m.Get("/apps/:name/avaliable", Handler(api.AppIsAvaliableHandler))
	m.Get("/apps/:name", AuthorizationRequiredHandler(api.AppInfo))
	m.Post("/apps/:name/run", AuthorizationRequiredHandler(api.RunCommand))
	m.Get("/apps/:name/restart", AuthorizationRequiredHandler(api.RestartHandler))
	m.Get("/apps/:name/env", AuthorizationRequiredHandler(api.GetEnv))
	m.Post("/apps/:name/env", AuthorizationRequiredHandler(api.SetEnv))
	m.Del("/apps/:name/env", AuthorizationRequiredHandler(api.UnsetEnv))
	m.Get("/apps", AuthorizationRequiredHandler(api.AppList))
	m.Post("/apps", AuthorizationRequiredHandler(api.CreateAppHandler))
	m.Put("/apps/:name/units", AuthorizationRequiredHandler(api.AddUnitsHandler))
	m.Put("/apps/:app/:team", AuthorizationRequiredHandler(api.GrantAccessToTeamHandler))
	m.Del("/apps/:app/:team", AuthorizationRequiredHandler(api.RevokeAccessFromTeamHandler))
	m.Get("/apps/:name/log", AuthorizationRequiredHandler(api.AppLog))
	m.Post("/apps/:name/log", Handler(api.AddLogHandler))

	m.Post("/users", Handler(auth.CreateUser))
	m.Post("/users/:email/tokens", Handler(auth.Login))
	m.Put("/users/password", AuthorizationRequiredHandler(auth.ChangePassword))
	m.Del("/users", AuthorizationRequiredHandler(auth.RemoveUser))
	m.Post("/users/keys", AuthorizationRequiredHandler(auth.AddKeyToUser))
	m.Del("/users/keys", AuthorizationRequiredHandler(auth.RemoveKeyFromUser))

	m.Get("/teams", AuthorizationRequiredHandler(auth.ListTeams))
	m.Post("/teams", AuthorizationRequiredHandler(auth.CreateTeam))
	m.Del("/teams/:name", AuthorizationRequiredHandler(auth.RemoveTeam))
	m.Put("/teams/:team/:user", AuthorizationRequiredHandler(auth.AddUserToTeam))
	m.Del("/teams/:team/:user", AuthorizationRequiredHandler(auth.RemoveUserFromTeam))

	if !*dry {
		provisioner, err := config.GetString("provisioner")
		if err != nil {
			fmt.Printf("Warning: %q didn't declare a provisioner, using default provisioner.\n", configFile)
			provisioner = "juju"
		}
		app.Provisioner, err = provision.Get(provisioner)
		if err != nil {
			fatal(err)
		}
		fmt.Printf("Using %q provisioner.\n\n", provisioner)

		listen, err := config.GetString("listen")
		if err != nil {
			fatal(err)
		}
		fmt.Printf("tsuru HTTP server listening at %s...\n", listen)
		fatal(http.ListenAndServe(listen, m))
	}
}