本文整理汇总了Golang中github.com/tsuru/tsuru/service.Service.OwnerTeams方法的典型用法代码示例。如果您正苦于以下问题:Golang Service.OwnerTeams方法的具体用法?Golang Service.OwnerTeams怎么用?Golang Service.OwnerTeams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/tsuru/tsuru/service.Service
的用法示例。
在下文中一共展示了Service.OwnerTeams方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: serviceCreate
// title: service create
// path: /services
// method: POST
// consume: application/x-www-form-urlencoded
// responses:
// 201: Service created
// 400: Invalid data
// 401: Unauthorized
// 409: Service already exists
func serviceCreate(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
s := service.Service{
Name: r.FormValue("id"),
Username: r.FormValue("username"),
Endpoint: map[string]string{"production": r.FormValue("endpoint")},
Password: r.FormValue("password"),
}
team := r.FormValue("team")
if team == "" {
team, err = permission.TeamForPermission(t, permission.PermServiceCreate)
if err == permission.ErrTooManyTeams {
return &errors.HTTP{
Code: http.StatusBadRequest,
Message: "You must provide a team responsible for this service in the manifest file.",
}
}
if err != nil {
return err
}
}
s.OwnerTeams = []string{team}
err = serviceValidate(s)
if err != nil {
return err
}
allowed := permission.Check(t, permission.PermServiceCreate,
permission.Context(permission.CtxTeam, s.OwnerTeams[0]),
)
if !allowed {
return permission.ErrUnauthorized
}
delete(r.Form, "password")
evt, err := event.New(&event.Opts{
Target: serviceTarget(s.Name),
Kind: permission.PermServiceCreate,
Owner: t,
CustomData: event.FormToCustomData(r.Form),
Allowed: event.Allowed(permission.PermServiceReadEvents, contextsForServiceProvision(&s)...),
})
if err != nil {
return err
}
defer func() { evt.Done(err) }()
err = s.Create()
if err != nil {
httpError := http.StatusInternalServerError
if err == service.ErrServiceAlreadyExists {
httpError = http.StatusConflict
}
return &errors.HTTP{Code: httpError, Message: err.Error()}
}
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, "success")
return nil
}
示例2: serviceCreate
// title: service create
// path: /services
// method: POST
// consume: application/x-www-form-urlencoded
// responses:
// 201: Service created
// 400: Invalid data
// 401: Unauthorized
// 409: Service already exists
func serviceCreate(w http.ResponseWriter, r *http.Request, t auth.Token) error {
s := service.Service{
Name: r.FormValue("id"),
Username: r.FormValue("username"),
Endpoint: map[string]string{"production": r.FormValue("endpoint")},
Password: r.FormValue("password"),
}
team := r.FormValue("team")
if team == "" {
var err error
team, err = permission.TeamForPermission(t, permission.PermServiceCreate)
if err == permission.ErrTooManyTeams {
return &errors.HTTP{
Code: http.StatusBadRequest,
Message: "You must provide a team responsible for this service in the manifest file.",
}
}
if err != nil {
return err
}
}
s.OwnerTeams = []string{team}
err := serviceValidate(s)
if err != nil {
return err
}
allowed := permission.Check(t, permission.PermServiceCreate,
permission.Context(permission.CtxTeam, s.OwnerTeams[0]),
)
if !allowed {
return permission.ErrUnauthorized
}
rec.Log(t.GetUserName(), "create-service", s.Name, s.Endpoint["production"])
err = s.Create()
if err != nil {
httpError := http.StatusInternalServerError
if err == service.ErrServiceAlreadyExists {
httpError = http.StatusConflict
}
return &errors.HTTP{Code: httpError, Message: err.Error()}
}
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, "success")
return nil
}