本文整理汇总了Golang中github.com/tsuru/tsuru/auth.GetTeamsNames函数的典型用法代码示例。如果您正苦于以下问题:Golang GetTeamsNames函数的具体用法?Golang GetTeamsNames怎么用?Golang GetTeamsNames使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetTeamsNames函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: serviceInfo
func serviceInfo(w http.ResponseWriter, r *http.Request, t *auth.Token) error {
u, err := t.User()
if err != nil {
return err
}
serviceName := r.URL.Query().Get(":name")
rec.Log(u.Email, "service-info", serviceName)
_, err = getServiceOrError(serviceName, u)
if err != nil {
return err
}
instances := []service.ServiceInstance{}
teams, err := u.Teams()
if err != nil {
return err
}
conn, err := db.Conn()
if err != nil {
return err
}
defer conn.Close()
teamsNames := auth.GetTeamsNames(teams)
q := bson.M{"service_name": serviceName, "teams": bson.M{"$in": teamsNames}}
err = conn.ServiceInstances().Find(q).All(&instances)
if err != nil {
return err
}
b, err := json.Marshal(instances)
if err != nil {
return nil
}
w.Write(b)
return nil
}
示例2: List
// List returns the list of apps that the given user has access to.
//
// If the user does not have access to any app, this function returns an empty
// list and a nil error.
//
// The list can be filtered through the filter parameter.
func List(u *auth.User, filter *Filter) ([]App, error) {
var apps []App
conn, err := db.Conn()
if err != nil {
return nil, err
}
defer conn.Close()
query := filter.Query()
if u == nil || u.IsAdmin() {
if err = conn.Apps().Find(query).All(&apps); err != nil {
return []App{}, err
}
return apps, nil
}
ts, err := u.Teams()
if err != nil {
return []App{}, err
}
teams := auth.GetTeamsNames(ts)
query["teams"] = bson.M{"$in": teams}
if err := conn.Apps().Find(query).All(&apps); err != nil {
return []App{}, err
}
return apps, nil
}
示例3: GetServiceInstancesByServicesAndTeams
func GetServiceInstancesByServicesAndTeams(services []Service, u *auth.User, appName string) ([]ServiceInstance, error) {
var instances []ServiceInstance
teams, err := u.Teams()
if err != nil {
return nil, err
}
if len(teams) == 0 {
return nil, nil
}
conn, err := db.Conn()
if err != nil {
return nil, err
}
defer conn.Close()
var teamNames []string
if !u.IsAdmin() {
teamNames = auth.GetTeamsNames(teams)
}
query := genericServiceInstancesFilter(services, teamNames)
if appName != "" {
query["apps"] = appName
}
err = conn.ServiceInstances().Find(query).All(&instances)
return instances, err
}
示例4: serviceCreate
func serviceCreate(w http.ResponseWriter, r *http.Request, t auth.Token) error {
defer r.Body.Close()
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return err
}
var sy serviceYaml
err = yaml.Unmarshal(body, &sy)
if err != nil {
return err
}
err = sy.validate()
if err != nil {
return err
}
u, err := t.User()
if err != nil {
return err
}
rec.Log(u.Email, "create-service", sy.Id, sy.Endpoint)
conn, err := db.Conn()
if err != nil {
return err
}
defer conn.Close()
var teams []auth.Team
err = conn.Teams().Find(bson.M{"users": u.Email}).All(&teams)
if err != nil {
return err
}
if len(teams) == 0 {
msg := "In order to create a service, you should be member of at least one team"
return &errors.HTTP{Code: http.StatusForbidden, Message: msg}
}
n, err := conn.Services().Find(bson.M{"_id": sy.Id}).Count()
if err != nil {
return &errors.HTTP{Code: http.StatusInternalServerError, Message: err.Error()}
}
if n != 0 {
msg := fmt.Sprintf("Service with name %s already exists.", sy.Id)
return &errors.HTTP{Code: http.StatusInternalServerError, Message: msg}
}
s := service.Service{
Name: sy.Id,
Endpoint: sy.Endpoint,
Password: sy.Password,
OwnerTeams: auth.GetTeamsNames(teams),
}
err = s.Create()
if err != nil {
return err
}
fmt.Fprint(w, "success")
return nil
}
示例5: listUsers
func listUsers(w http.ResponseWriter, r *http.Request, t auth.Token) error {
users, err := auth.ListUsers()
if err != nil {
return err
}
apiUsers := make([]apiUser, len(users))
for i, user := range users {
var teamsNames []string
if teams, err := user.Teams(); err == nil {
teamsNames = auth.GetTeamsNames(teams)
}
apiUsers[i] = apiUser{Email: user.Email, Teams: teamsNames}
}
return json.NewEncoder(w).Encode(apiUsers)
}
示例6: GetServicesByOwnerTeams
func GetServicesByOwnerTeams(teamKind string, u *auth.User) ([]Service, error) {
teams, err := u.Teams()
if err != nil {
return nil, err
}
conn, err := db.Conn()
if err != nil {
return nil, err
}
defer conn.Close()
teamsNames := auth.GetTeamsNames(teams)
q := bson.M{teamKind: bson.M{"$in": teamsNames}}
var services []Service
err = conn.Services().Find(q).All(&services)
return services, err
}
示例7: GetServiceInstancesByServicesAndTeams
func GetServiceInstancesByServicesAndTeams(services []Service, u *auth.User) ([]ServiceInstance, error) {
var instances []ServiceInstance
teams, err := u.Teams()
if err != nil {
return nil, err
}
if len(teams) == 0 {
return nil, nil
}
conn, err := db.Conn()
if err != nil {
return nil, err
}
defer conn.Close()
q, f := genericServiceInstancesFilter(services, auth.GetTeamsNames(teams))
err = conn.ServiceInstances().Find(q).Select(f).All(&instances)
return instances, err
}
示例8: GetServicesByTeamKindAndNoRestriction
func GetServicesByTeamKindAndNoRestriction(teamKind string, u *auth.User) ([]Service, error) {
teams, err := u.Teams()
if err != nil {
return nil, err
}
conn, err := db.Conn()
if err != nil {
return nil, err
}
defer conn.Close()
teamsNames := auth.GetTeamsNames(teams)
q := bson.M{"$or": []bson.M{
{teamKind: bson.M{"$in": teamsNames}},
{"is_restricted": false},
}}
var services []Service
err = conn.Services().Find(q).Select(bson.M{"name": 1}).All(&services)
return services, err
}
示例9: List
// List returns the list of apps that the given user has access to.
//
// If the user does not have acces to any app, this function returns an empty
// list and a nil error.
func List(u *auth.User) ([]App, error) {
var apps []App
conn, err := db.Conn()
if err != nil {
return nil, err
}
defer conn.Close()
if u.IsAdmin() {
if err := conn.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 := conn.Apps().Find(bson.M{"teams": bson.M{"$in": teams}}).All(&apps); err != nil {
return []App{}, err
}
return apps, nil
}