// title: update application quota // path: /apps/{appname}/quota // method: PUT // consume: application/x-www-form-urlencoded // responses: // 200: Quota updated // 400: Invalid data // 401: Unauthorized // 404: Application not found func changeAppQuota(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) { r.ParseForm() appName := r.URL.Query().Get(":appname") a, err := getAppFromContext(appName, r) if err != nil { return err } allowed := permission.Check(t, permission.PermAppAdminQuota, contextsForApp(&a)...) if !allowed { return permission.ErrUnauthorized } evt, err := event.New(&event.Opts{ Target: event.Target{Type: event.TargetTypeApp, Value: appName}, Kind: permission.PermAppAdminQuota, Owner: t, CustomData: event.FormToCustomData(r.Form), Allowed: event.Allowed(permission.PermAppReadEvents, contextsForApp(&a)...), }) if err != nil { return err } defer func() { evt.Done(err) }() limit, err := strconv.Atoi(r.FormValue("limit")) if err != nil { return &errors.HTTP{ Code: http.StatusBadRequest, Message: "Invalid limit", } } return app.ChangeQuota(&a, limit) }
func changeAppQuota(w http.ResponseWriter, r *http.Request, t auth.Token) error { limit, err := strconv.Atoi(r.FormValue("limit")) if err != nil { return &errors.HTTP{ Code: http.StatusBadRequest, Message: "Invalid limit", } } appName := r.URL.Query().Get(":appname") a, err := app.GetByName(appName) if err != nil { return err } return app.ChangeQuota(a, limit) }
// title: update application quota // path: /apps/{appname}/quota // method: PUT // consume: application/x-www-form-urlencoded // responses: // 200: Quota updated // 400: Invalid data // 401: Unauthorized // 404: Application not found func changeAppQuota(w http.ResponseWriter, r *http.Request, t auth.Token) error { limit, err := strconv.Atoi(r.FormValue("limit")) if err != nil { return &errors.HTTP{ Code: http.StatusBadRequest, Message: "Invalid limit", } } appName := r.URL.Query().Get(":appname") a, err := getAppFromContext(appName, r) if err != nil { return err } allowed := permission.Check(t, permission.PermAppAdminQuota, append(permission.Contexts(permission.CtxTeam, a.Teams), permission.Context(permission.CtxApp, a.Name), permission.Context(permission.CtxPool, a.Pool), )..., ) if !allowed { return permission.ErrUnauthorized } return app.ChangeQuota(&a, limit) }