mirror of
https://github.com/goharbor/harbor.git
synced 2024-09-28 21:37:31 +02:00
Merge pull request #15521 from wy65701436/remove-quota-switch
remove the internal legacy API to switch quota
This commit is contained in:
commit
5522ccbd93
@ -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
|
||||
|
@ -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()) {
|
||||
|
@ -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{
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user