api/service.go
func serviceUpdate(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	d := service.Service{
		Username: InputValue(r, "username"),
		Endpoint: map[string]string{"production": InputValue(r, "endpoint")},
		Password: InputValue(r, "password"),
		Name:     r.URL.Query().Get(":name"),
	}
	team := InputValue(r, "team")
	s, err := getService(d.Name)
	if err != nil {
		return err
	}
	allowed := permission.Check(t, permission.PermServiceUpdate,
		contextsForServiceProvision(&s)...,
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	delete(r.Form, "password")
	evt, err := event.New(&event.Opts{
		Target:     serviceTarget(s.Name),
		Kind:       permission.PermServiceUpdate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermServiceReadEvents, contextsForServiceProvision(&s)...),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	s.Endpoint = d.Endpoint
	s.Password = d.Password
	s.Username = d.Username
	if team != "" {
		s.OwnerTeams = []string{team}
	}
	return service.Update(s)
}
func serviceUpdate(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	d := service.Service{
		Username: InputValue(r, "username"),
		Endpoint: map[string]string{"production": InputValue(r, "endpoint")},
		Password: InputValue(r, "password"),
		Name:     r.URL.Query().Get(":name"),
	}
	team := InputValue(r, "team")
	s, err := getService(d.Name)
	if err != nil {
		return err
	}
	allowed := permission.Check(t, permission.PermServiceUpdate,
		contextsForServiceProvision(&s)...,
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	delete(r.Form, "password")
	evt, err := event.New(&event.Opts{
		Target:     serviceTarget(s.Name),
		Kind:       permission.PermServiceUpdate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermServiceReadEvents, contextsForServiceProvision(&s)...),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	s.Endpoint = d.Endpoint
	s.Password = d.Password
	s.Username = d.Username
	if team != "" {
		s.OwnerTeams = []string{team}
	}
	return service.Update(s)
}
// title: service update
// path: /services/{name}
// method: PUT
// consume: application/x-www-form-urlencoded
// responses:
//   200: Service updated
//   400: Invalid data
//   401: Unauthorized
//   403: Forbidden (team is not the owner)
//   404: Service not found