api/pool.go
func poolConstraintSet(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	if !permission.Check(t, permission.PermPoolUpdateConstraintsSet) {
		return permission.ErrUnauthorized
	}
	var poolConstraint pool.PoolConstraint
	err = ParseInput(r, &poolConstraint)
	if err != nil {
		return err
	}
	if poolConstraint.PoolExpr == "" {
		return &terrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: "You must provide a Pool Expression",
		}
	}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypePool, Value: poolConstraint.PoolExpr},
		Kind:       permission.PermPoolUpdateConstraintsSet,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermPoolReadEvents),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	append := false
	if appendStr := InputValue(r, "append"); appendStr != "" {
		append, _ = strconv.ParseBool(appendStr)
	}
	if append {
		return pool.AppendPoolConstraint(&poolConstraint)
	}
	return pool.SetPoolConstraint(&poolConstraint)
}
func poolConstraintSet(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	if !permission.Check(t, permission.PermPoolUpdateConstraintsSet) {
		return permission.ErrUnauthorized
	}
	var poolConstraint pool.PoolConstraint
	err = ParseInput(r, &poolConstraint)
	if err != nil {
		return err
	}
	if poolConstraint.PoolExpr == "" {
		return &terrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: "You must provide a Pool Expression",
		}
	}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypePool, Value: poolConstraint.PoolExpr},
		Kind:       permission.PermPoolUpdateConstraintsSet,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermPoolReadEvents),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	append := false
	if appendStr := InputValue(r, "append"); appendStr != "" {
		append, _ = strconv.ParseBool(appendStr)
	}
	if append {
		return pool.AppendPoolConstraint(&poolConstraint)
	}
	return pool.SetPoolConstraint(&poolConstraint)
}
// title: set a pool constraint
// path: /constraints
// method: PUT
// consume: application/x-www-form-urlencoded
// responses:
//   200: OK
//   401: Unauthorized