remove the internal legacy API to switch quota

The init design of this API is to avoid the quota error leads to system disaster.
As quota has been refineded and redis lock has been removed, the API can be deprecated safely.

And this API is only call the DB to refresh quota data, user can call the SyncQuota API to handle this.

Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
Wang Yan 2021-09-01 10:49:00 +08:00
parent ff617950b7
commit 581bb8833e
4 changed files with 0 additions and 72 deletions

View File

@ -115,7 +115,6 @@ func init() {
beego.Router("/api/"+api.APIVersion+"/chartrepo/:repo/charts/:name/:version/labels", chartLabelAPIType, "get:GetLabels;post:MarkLabel")
beego.Router("/api/"+api.APIVersion+"/chartrepo/:repo/charts/:name/:version/labels/:id([0-9]+)", chartLabelAPIType, "delete:RemoveLabel")
beego.Router("/api/internal/switchquota", &InternalAPI{}, "put:SwitchQuota")
beego.Router("/api/internal/syncquota", &InternalAPI{}, "post:SyncQuota")
// Init user Info

View File

@ -69,40 +69,6 @@ func (ia *InternalAPI) RenameAdmin() {
ia.DestroySession()
}
// QuotaSwitcher ...
type QuotaSwitcher struct {
Enabled bool
}
// SwitchQuota ...
func (ia *InternalAPI) SwitchQuota() {
var req QuotaSwitcher
if err := ia.DecodeJSONReq(&req); err != nil {
ia.SendBadRequestError(err)
return
}
ctx := orm.NewContext(ia.Ctx.Request.Context(), o.NewOrm())
cur := config.ReadOnly(ctx)
// quota per project from disable to enable, it needs to update the quota usage bases on the DB records.
if !config.QuotaPerProjectEnable(ctx) && req.Enabled {
if !cur {
config.GetCfgManager(ctx).Set(ctx, common.ReadOnly, true)
config.GetCfgManager(ctx).Save(ctx)
}
if err := quota.RefreshForProjects(ctx); err != nil {
ia.SendInternalServerError(err)
return
}
}
defer func() {
ctx := orm.Context()
config.GetCfgManager(ctx).Set(ctx, common.ReadOnly, cur)
config.GetCfgManager(ctx).Set(ctx, common.QuotaPerProjectEnable, req.Enabled)
config.GetCfgManager(ctx).Save(ctx)
}()
return
}
// SyncQuota ...
func (ia *InternalAPI) SyncQuota() {
if !config.QuotaPerProjectEnable(orm.Context()) {

View File

@ -19,42 +19,6 @@ import (
"testing"
)
// cannot verify the real scenario here
func TestSwitchQuota(t *testing.T) {
cases := []*codeCheckingCase{
// 401
{
request: &testingRequest{
method: http.MethodPut,
url: "/api/internal/switchquota",
},
code: http.StatusUnauthorized,
},
// 200
{
request: &testingRequest{
method: http.MethodPut,
url: "/api/internal/switchquota",
credential: sysAdmin,
bodyJSON: &QuotaSwitcher{
Enabled: true,
},
},
code: http.StatusOK,
},
// 403
{
request: &testingRequest{
url: "/api/internal/switchquota",
method: http.MethodPut,
credential: nonSysAdmin,
},
code: http.StatusForbidden,
},
}
runCodeCheckingCases(t, cases...)
}
// cannot verify the real scenario here
func TestSyncQuota(t *testing.T) {
cases := []*codeCheckingCase{

View File

@ -46,7 +46,6 @@ func registerRoutes() {
beego.Router(common.AuthProxyRediretPath, &controllers.AuthProxyController{}, "get:HandleRedirect")
beego.Router("/api/internal/renameadmin", &api.InternalAPI{}, "post:RenameAdmin")
beego.Router("/api/internal/switchquota", &api.InternalAPI{}, "put:SwitchQuota")
beego.Router("/api/internal/syncquota", &api.InternalAPI{}, "post:SyncQuota")
beego.Router("/service/notifications/jobs/webhook/:id([0-9]+)", &jobs.Handler{}, "post:HandleNotificationJob")