예제 #1
0
파일: app.go 프로젝트: astaxie/tsuru
func createAppHelper(instance *app.App, u *auth.User, units uint) ([]byte, error) {
	teams, err := u.Teams()
	if err != nil {
		return nil, err
	}
	if len(teams) < 1 {
		msg := "In order to create an app, you should be member of at least one team"
		return nil, &errors.Http{Code: http.StatusForbidden, Message: msg}
	}
	instance.SetTeams(teams)
	err = app.CreateApp(instance, units)
	if err != nil {
		log.Printf("Got error while creating app: %s", err)
		if e, ok := err.(*app.ValidationError); ok {
			return nil, &errors.Http{Code: http.StatusPreconditionFailed, Message: e.Message}
		}
		if strings.Contains(err.Error(), "key error") {
			msg := fmt.Sprintf(`There is already an app named "%s".`, instance.Name)
			return nil, &errors.Http{Code: http.StatusConflict, Message: msg}
		}
		return nil, err
	}
	msg := map[string]string{
		"status":         "success",
		"repository_url": repository.GetUrl(instance.Name),
	}
	return json.Marshal(msg)
}
예제 #2
0
파일: service.go 프로젝트: JoeyFan/tsuru
func GetServicesByOwnerTeams(teamKind string, u *auth.User) (services []Service, err error) {
	teams, err := u.Teams()
	teamsNames := auth.GetTeamsNames(teams)
	q := bson.M{teamKind: bson.M{"$in": teamsNames}, "status": bson.M{"$ne": "deleted"}}
	err = db.Session.Services().Find(q).All(&services)
	return
}
예제 #3
0
func GetServiceInstancesByServicesAndTeams(services []Service, u *auth.User) (sInstances []ServiceInstance, err error) {
	teams, err := u.Teams()
	if err != nil {
		return
	}
	if len(teams) == 0 {
		return
	}
	q, f := genericServiceInstancesFilter(services, auth.GetTeamsNames(teams))
	err = db.Session.ServiceInstances().Find(q).Select(f).All(&sInstances)
	return
}
예제 #4
0
파일: service.go 프로젝트: JoeyFan/tsuru
func GetServicesByTeamKindAndNoRestriction(teamKind string, u *auth.User) (services []Service, err error) {
	teams, err := u.Teams()
	teamsNames := auth.GetTeamsNames(teams)
	q := bson.M{"$or": []bson.M{
		{teamKind: bson.M{"$in": teamsNames}},
		{"is_restricted": false},
	},
		"status": bson.M{"$ne": "deleted"},
	}
	err = db.Session.Services().Find(q).Select(bson.M{"name": 1}).All(&services)
	return
}
예제 #5
0
파일: app.go 프로젝트: JoeyFan/tsuru
func List(u *auth.User) ([]App, error) {
	var apps []App
	if u.IsAdmin() {
		if err := db.Session.Apps().Find(nil).All(&apps); err != nil {
			return []App{}, err
		}
		return apps, nil
	}
	ts, err := u.Teams()
	if err != nil {
		return []App{}, err
	}
	teams := auth.GetTeamsNames(ts)
	if err := db.Session.Apps().Find(bson.M{"teams": bson.M{"$in": teams}}).All(&apps); err != nil {
		return []App{}, err
	}
	return apps, nil
}
예제 #6
0
func (s *S) TestGetServiceInstancesByServicesAndTeamsForUsersThatAreNotMembersOfAnyTeam(c *C) {
	u := auth.User{Email: "*****@*****.**", Password: "******"}
	err := u.Create()
	c.Assert(err, IsNil)
	defer db.Session.Users().Remove(bson.M{"email": u.Email})
	srvc := Service{Name: "mysql", Teams: []string{s.team.Name}, IsRestricted: true}
	err = srvc.Create()
	c.Assert(err, IsNil)
	defer srvc.Delete()
	instance := ServiceInstance{
		Name:        "j4sql",
		ServiceName: srvc.Name,
	}
	err = instance.Create()
	c.Assert(err, IsNil)
	defer instance.Delete()
	instances, err := GetServiceInstancesByServicesAndTeams([]Service{srvc}, &u)
	c.Assert(err, IsNil)
	c.Assert(instances, IsNil)
}