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) }
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 }
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 }
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 }
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 }