本文整理汇总了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
}
开发者ID:renanoliveira,项目名称:tsuru,代码行数:34,代码来源:service_consumption.go
示例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
}
开发者ID:Zapelini,项目名称:tsuru,代码行数:31,代码来源:app.go
示例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
}
开发者ID:edulemasson,项目名称:tsuru,代码行数:25,代码来源:service_instance.go
示例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
}
开发者ID:ningjh,项目名称:tsuru,代码行数:55,代码来源:service_provision.go
示例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)
}
开发者ID:nicolas2bonfils,项目名称:tsuru,代码行数:15,代码来源:auth.go
示例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
}
开发者ID:rualatngua,项目名称:tsuru,代码行数:16,代码来源:service.go
示例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
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:18,代码来源:service_instance.go
示例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
}
开发者ID:rualatngua,项目名称:tsuru,代码行数:19,代码来源:service.go
示例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
}
开发者ID:philiptzou,项目名称:tsuru,代码行数:27,代码来源:app.go
注:本文中的github.com/tsuru/tsuru/auth.GetTeamsNames函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论