api/service_broker.go
func serviceBrokerAdd(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	if !permission.Check(t, permission.PermServiceBrokerCreate) {
		return permission.ErrUnauthorized
	}
	broker, err := decodeServiceBroker(r)
	if err != nil {
		return &errors.HTTP{Code: http.StatusBadRequest, Message: err.Error()}
	}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypeServiceBroker, Value: broker.Name},
		Kind:       permission.PermServiceBrokerCreate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermServiceBrokerReadEvents),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	if err = servicemanager.ServiceBroker.Create(*broker); err != nil {
		if err == service.ErrServiceBrokerAlreadyExists {
			return &errors.HTTP{Code: http.StatusConflict, Message: "Broker already exists."}
		}
		return err
	}
	w.WriteHeader(http.StatusCreated)
	return nil
}
func serviceBrokerAdd(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	if !permission.Check(t, permission.PermServiceBrokerCreate) {
		return permission.ErrUnauthorized
	}
	broker, err := decodeServiceBroker(r)
	if err != nil {
		return &errors.HTTP{Code: http.StatusBadRequest, Message: err.Error()}
	}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypeServiceBroker, Value: broker.Name},
		Kind:       permission.PermServiceBrokerCreate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermServiceBrokerReadEvents),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	if err = servicemanager.ServiceBroker.Create(*broker); err != nil {
		if err == service.ErrServiceBrokerAlreadyExists {
			return &errors.HTTP{Code: http.StatusConflict, Message: "Broker already exists."}
		}
		return err
	}
	w.WriteHeader(http.StatusCreated)
	return nil
}
// title: Add service broker
// path: /brokers
// method: POST
// responses:
//   201: Service broker created
//   401: Unauthorized
//   409: Broker already exists