mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-30 14:13:43 +01:00
refactor sync registry API
This commit is contained in:
parent
a901297859
commit
1314ff92f5
@ -16,29 +16,23 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/vmware/harbor/src/common/dao"
|
|
||||||
"github.com/vmware/harbor/src/common/utils/log"
|
|
||||||
"github.com/vmware/harbor/src/common/api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// InternalAPI handles request of harbor admin...
|
// InternalAPI handles request of harbor admin...
|
||||||
type InternalAPI struct {
|
type InternalAPI struct {
|
||||||
api.BaseAPI
|
BaseController
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare validates the URL and parms
|
// Prepare validates the URL and parms
|
||||||
func (ia *InternalAPI) Prepare() {
|
func (ia *InternalAPI) Prepare() {
|
||||||
var currentUserID int
|
ia.BaseController.Prepare()
|
||||||
currentUserID = ia.ValidateUser()
|
if !ia.SecurityCtx.IsAuthenticated() {
|
||||||
isAdmin, err := dao.IsAdminRole(currentUserID)
|
ia.HandleUnauthorized()
|
||||||
if err != nil {
|
return
|
||||||
log.Errorf("Error occurred in IsAdminRole:%v", err)
|
|
||||||
ia.CustomAbort(http.StatusInternalServerError, "Internal error.")
|
|
||||||
}
|
}
|
||||||
if !isAdmin {
|
if !ia.SecurityCtx.IsSysAdmin() {
|
||||||
log.Error("Guests doesn't have the permisson to request harbor internal API.")
|
ia.HandleForbidden(ia.SecurityCtx.GetUsername())
|
||||||
ia.CustomAbort(http.StatusForbidden, "Guests doesn't have the permisson to request harbor internal API.")
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user