From 25885bf3f6f3d433233d1f34d848e2f647d786b2 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Mon, 4 Sep 2023 15:02:57 +0200 Subject: [PATCH] fix(apigateway): add GetSpecificMethods to resource manager --- cmd/climc/shell/k8s/container_registry.go | 1 + pkg/apigateway/handler/resource.go | 2 +- pkg/mcclient/modulebase/base.go | 16 ++++++++++++++-- pkg/mcclient/modulebase/modules.go | 3 +++ pkg/mcclient/modules/k8s/container_registry.go | 4 +++- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cmd/climc/shell/k8s/container_registry.go b/cmd/climc/shell/k8s/container_registry.go index 2d06123bfa..e659887a21 100644 --- a/cmd/climc/shell/k8s/container_registry.go +++ b/cmd/climc/shell/k8s/container_registry.go @@ -33,6 +33,7 @@ func initContainerRegistry() { cmd := NewK8sResourceCmd(k8s.ContainerRegistries) cmd.List(new(o.RegistryListOptions)) cmd.Show(new(o.RegistryGetOptions)) + cmd.Delete(new(o.RegistryGetOptions)) cmd.Create(new(o.RegistryCreateOptions)) cmd.Get("images", new(o.RegistryGetImagesOptions)) cmd.Get("image-tags", new(o.RegistryGetImageTagsOptions)) diff --git a/pkg/apigateway/handler/resource.go b/pkg/apigateway/handler/resource.go index 7995494c62..2dac0cc683 100644 --- a/pkg/apigateway/handler/resource.go +++ b/pkg/apigateway/handler/resource.go @@ -311,7 +311,7 @@ func (f *ResourceHandlers) getSpecHandler(ctx context.Context, w http.ResponseWr query := req.Query() module2, e := modulebase.GetModule(session, req.Spec()) - if e != nil { + if e != nil || module.GetSpecificMethods().Has(req.Spec()) { obj, e := module.GetSpecific(session, req.ResID(), req.Spec(), query) if e != nil { httperrors.GeneralServerError(ctx, w, e) diff --git a/pkg/mcclient/modulebase/base.go b/pkg/mcclient/modulebase/base.go index e51f7d8d53..c5133f308c 100644 --- a/pkg/mcclient/modulebase/base.go +++ b/pkg/mcclient/modulebase/base.go @@ -28,6 +28,7 @@ import ( "yunion.io/x/pkg/errors" "yunion.io/x/pkg/util/httputils" "yunion.io/x/pkg/util/printutils" + "yunion.io/x/pkg/util/sets" "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" @@ -41,6 +42,8 @@ type BaseManager struct { columns []string adminColumns []string + + specificMethods sets.String } func NewBaseManager(serviceType, endpointType, version string, columns, adminColumns []string) *BaseManager { @@ -49,11 +52,20 @@ func NewBaseManager(serviceType, endpointType, version string, columns, adminCol endpointType: endpointType, version: version, // apiVersion: apiVersion, - columns: columns, - adminColumns: adminColumns, + columns: columns, + adminColumns: adminColumns, + specificMethods: sets.NewString(), } } +func (m *BaseManager) GetSpecificMethods() sets.String { + return m.specificMethods +} + +func (m *BaseManager) SetSpecificMethods(ms ...string) { + m.specificMethods = sets.NewString(ms...) +} + func (this *BaseManager) GetColumns(session *mcclient.ClientSession) []string { cols := this.columns if session.HasSystemAdminPrivilege() && len(this.adminColumns) > 0 { diff --git a/pkg/mcclient/modulebase/modules.go b/pkg/mcclient/modulebase/modules.go index c4012f79a7..825b12aa69 100644 --- a/pkg/mcclient/modulebase/modules.go +++ b/pkg/mcclient/modulebase/modules.go @@ -23,6 +23,7 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/errors" "yunion.io/x/pkg/util/printutils" + "yunion.io/x/pkg/util/sets" "yunion.io/x/onecloud/pkg/mcclient" ) @@ -142,6 +143,8 @@ type Manager interface { BatchDeleteInContextWithParam(session *mcclient.ClientSession, idlist []string, query jsonutils.JSONObject, body jsonutils.JSONObject, ctx Manager, ctxid string) []printutils.SubmitResult BatchDeleteInContexts(session *mcclient.ClientSession, idlist []string, body jsonutils.JSONObject, ctxs []ManagerContext) []printutils.SubmitResult BatchDeleteInContextsWithParam(session *mcclient.ClientSession, idlist []string, query jsonutils.JSONObject, body jsonutils.JSONObject, ctxs []ManagerContext) []printutils.SubmitResult + + GetSpecificMethods() sets.String } type IResourceManager interface { diff --git a/pkg/mcclient/modules/k8s/container_registry.go b/pkg/mcclient/modules/k8s/container_registry.go index 0e028f5b66..86460e306f 100644 --- a/pkg/mcclient/modules/k8s/container_registry.go +++ b/pkg/mcclient/modules/k8s/container_registry.go @@ -44,11 +44,13 @@ type ContainerRegistryManager struct { } func NewContainerRegistryManager() *ContainerRegistryManager { - return &ContainerRegistryManager{ + man := &ContainerRegistryManager{ ResourceManager: NewResourceManager("container_registry", "container_registries", NewResourceCols("Url", "Type"), NewColumns()), } + man.SetSpecificMethods("images") + return man } func (m *ContainerRegistryManager) UploadImage(s *mcclient.ClientSession, id string, params jsonutils.JSONObject, body io.Reader, size int64) (jsonutils.JSONObject, error) {