func tokenUpdate(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	var args authTypes.TeamTokenUpdateArgs
	err = ParseInput(r, &args)
	if err != nil {
		return err
	}
	args.TokenID = r.URL.Query().Get(":token_id")
	teamToken, err := servicemanager.TeamToken.FindByTokenID(args.TokenID)
	if err != nil {
		if err == authTypes.ErrTeamTokenNotFound {
			return &errors.HTTP{
				Code:    http.StatusNotFound,
				Message: err.Error(),
			}
		}
		return err
	}
	allowed := permission.Check(t, permission.PermTeamTokenUpdate,
		permission.Context(permTypes.CtxTeam, teamToken.Team),
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     teamTarget(teamToken.Team),
		Kind:       permission.PermTeamTokenUpdate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermTeamReadEvents, permission.Context(permTypes.CtxTeam, teamToken.Team)),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	teamToken, err = servicemanager.TeamToken.Update(args, t)
	if err == authTypes.ErrTeamTokenNotFound {
		return &errors.HTTP{
			Code:    http.StatusNotFound,
			Message: err.Error(),
		}
	}
	if err != nil {
		return err
	}
	return json.NewEncoder(w).Encode(teamToken)
}
func tokenUpdate(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	var args authTypes.TeamTokenUpdateArgs
	err = ParseInput(r, &args)
	if err != nil {
		return err
	}
	args.TokenID = r.URL.Query().Get(":token_id")
	teamToken, err := servicemanager.TeamToken.FindByTokenID(args.TokenID)
	if err != nil {
		if err == authTypes.ErrTeamTokenNotFound {
			return &errors.HTTP{
				Code:    http.StatusNotFound,
				Message: err.Error(),
			}
		}
		return err
	}
	allowed := permission.Check(t, permission.PermTeamTokenUpdate,
		permission.Context(permTypes.CtxTeam, teamToken.Team),
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     teamTarget(teamToken.Team),
		Kind:       permission.PermTeamTokenUpdate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermTeamReadEvents, permission.Context(permTypes.CtxTeam, teamToken.Team)),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	teamToken, err = servicemanager.TeamToken.Update(args, t)
	if err == authTypes.ErrTeamTokenNotFound {
		return &errors.HTTP{
			Code:    http.StatusNotFound,
			Message: err.Error(),
		}
	}
	if err != nil {
		return err
	}
	return json.NewEncoder(w).Encode(teamToken)
}
// title: token update
// path: /tokens/{token_id}
// method: PUT
// produce: application/json
// responses:
//   200: Token updated
//   401: Unauthorized
//   404: Token not found