// title: remove plan // path: /plans/{name} // method: DELETE // responses: // 200: Plan removed // 401: Unauthorized // 404: Plan not found func removePlan(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) { r.ParseForm() allowed := permission.Check(t, permission.PermPlanDelete) if !allowed { return permission.ErrUnauthorized } planName := r.URL.Query().Get(":planname") evt, err := event.New(&event.Opts{ Target: event.Target{Type: event.TargetTypePlan, Value: planName}, Kind: permission.PermPlanDelete, Owner: t, CustomData: event.FormToCustomData(r.Form), Allowed: event.Allowed(permission.PermPlanReadEvents), }) if err != nil { return err } defer func() { evt.Done(err) }() err = app.PlanRemove(planName) if err == app.ErrPlanNotFound { return &errors.HTTP{ Code: http.StatusNotFound, Message: err.Error(), } } return err }
func (s *S) TestChangePlan(c *check.C) { config.Set("docker:router", "fake") defer config.Unset("docker:router") plans := []app.Plan{ {Name: "hiperplan", Memory: 536870912, Swap: 536870912, CpuShare: 100}, {Name: "superplan", Memory: 268435456, Swap: 268435456, CpuShare: 100}, } for _, plan := range plans { err := plan.Save() c.Assert(err, check.IsNil) defer app.PlanRemove(plan.Name) } a := app.App{Name: "someapp", Platform: "zend", TeamOwner: s.team.Name, Plan: plans[1]} err := app.CreateApp(&a, s.user) c.Assert(err, check.IsNil) defer s.logConn.Logs(a.Name).DropCollection() request, err := http.NewRequest("POST", "/apps/someapp/plan", strings.NewReader(`{"name":"hiperplan"}`)) c.Assert(err, check.IsNil) request.Header.Set("Authorization", "bearer "+s.token.GetValue()) recorder := httptest.NewRecorder() m := RunServer(true) m.ServeHTTP(recorder, request) c.Assert(recorder.Code, check.Equals, http.StatusOK) app, err := app.GetByName(a.Name) c.Assert(err, check.IsNil) c.Assert(app.Plan, check.DeepEquals, plans[0]) c.Assert(s.provisioner.Restarts(&a, ""), check.Equals, 1) }
func removePlan(w http.ResponseWriter, r *http.Request, t auth.Token) error { planName := r.URL.Query().Get(":planname") err := app.PlanRemove(planName) if err == app.ErrPlanNotFound { return &errors.HTTP{ Code: http.StatusNotFound, Message: err.Error(), } } return err }
func removePlan(w http.ResponseWriter, r *http.Request, t auth.Token) error { allowed := permission.Check(t, permission.PermPlanDelete) if !allowed { return permission.ErrUnauthorized } planName := r.URL.Query().Get(":planname") err := app.PlanRemove(planName) if err == app.ErrPlanNotFound { return &errors.HTTP{ Code: http.StatusNotFound, Message: err.Error(), } } return err }
func (s *S) TestChangePlanNotFound(c *check.C) { plan := app.Plan{Name: "superplan", Memory: 268435456, Swap: 268435456, CpuShare: 100} err := plan.Save() c.Assert(err, check.IsNil) defer app.PlanRemove(plan.Name) a := app.App{Name: "someapp", Platform: "zend", Teams: []string{s.team.Name}, Plan: plan} err = app.CreateApp(&a, s.user) c.Assert(err, check.IsNil) defer s.deleteApp(&a) defer s.logConn.Logs(a.Name).DropCollection() request, err := http.NewRequest("POST", "/apps/someapp/plan", strings.NewReader(`{"name":"hiperplan"}`)) c.Assert(err, check.IsNil) request.Header.Set("Authorization", "bearer "+s.token.GetValue()) recorder := httptest.NewRecorder() m := RunServer(true) m.ServeHTTP(recorder, request) c.Check(recorder.Code, check.Equals, http.StatusNotFound) c.Check(recorder.Body.String(), check.Equals, app.ErrPlanNotFound.Error()+"\n") }