func grantServiceAccess(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	serviceName := r.URL.Query().Get(":service")
	s, err := getService(serviceName)
	if err != nil {
		return err
	}
	allowed := permission.Check(t, permission.PermServiceUpdateGrantAccess,
		contextsForServiceProvision(&s)...,
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	teamName := r.URL.Query().Get(":team")
	team, err := servicemanager.Team.FindByName(teamName)
	if err != nil {
		if err == authTypes.ErrTeamNotFound {
			return &errors.HTTP{Code: http.StatusBadRequest, Message: "Team not found"}
		}
		return err
	}
	evt, err := event.New(&event.Opts{
		Target:     serviceTarget(s.Name),
		Kind:       permission.PermServiceUpdateGrantAccess,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermServiceReadEvents, contextsForServiceProvision(&s)...),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	err = s.GrantAccess(team)
	if err != nil {
		return &errors.HTTP{Code: http.StatusConflict, Message: err.Error()}
	}
	return service.Update(s)
}
func grantServiceAccess(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	serviceName := r.URL.Query().Get(":service")
	s, err := getService(serviceName)
	if err != nil {
		return err
	}
	allowed := permission.Check(t, permission.PermServiceUpdateGrantAccess,
		contextsForServiceProvision(&s)...,
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	teamName := r.URL.Query().Get(":team")
	team, err := servicemanager.Team.FindByName(teamName)
	if err != nil {
		if err == authTypes.ErrTeamNotFound {
			return &errors.HTTP{Code: http.StatusBadRequest, Message: "Team not found"}
		}
		return err
	}
	evt, err := event.New(&event.Opts{
		Target:     serviceTarget(s.Name),
		Kind:       permission.PermServiceUpdateGrantAccess,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermServiceReadEvents, contextsForServiceProvision(&s)...),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	err = s.GrantAccess(team)
	if err != nil {
		return &errors.HTTP{Code: http.StatusConflict, Message: err.Error()}
	}
	return service.Update(s)
}
func grantServiceAccess ( w http . ResponseWriter , r * http . Request , t auth . Token ) ( err error ) { serviceName := r . URL . Query ( ) . Get ( " " ) s , err := getService ( serviceName ) if err != nil { return err } allowed := permission . Check ( t , permission . PermServiceUpdateGrantAccess , contextsForServiceProvision ( & s ) ... , ) if ! allowed { return permission . ErrUnauthorized } teamName := r . URL . Query ( ) . Get ( " " ) team , err := servicemanager . Team . FindByName ( teamName ) if err != nil { if err == authTypes . ErrTeamNotFound { return & errors . HTTP { Code : http . StatusBadRequest , Message : " " } } return err } evt , err := event . New ( & event . Opts { Target : serviceTarget ( s . Name ) , Kind : permission . PermServiceUpdateGrantAccess , Owner : t , CustomData : event . FormToCustomData ( InputFields ( r ) ) , Allowed : event . Allowed ( permission . PermServiceReadEvents , contextsForServiceProvision ( & s ) ... ) , } ) if err != nil { return err } defer func ( ) { evt . Done ( err ) } ( ) err = s . GrantAccess ( team ) if err != nil { return & errors . HTTP { Code : http . StatusConflict , Message : err . Error ( ) } } return service . Update ( s ) }
// title: grant access to a service
// path: /services/{service}/team/{team}
// method: PUT
// responses:
//   200: Service updated
//   400: Team not found
//   401: Unauthorized
//   404: Service not found
//   409: Team already has access to this service
title : grant access to a service path : / services / { service } / team / { team } method : PUT responses : 200 : Service updated 400 : Team not found 401 : Unauthorized 404 : Service not found 409 : Team already has access to this service