Add get workspace API
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/emicklei/go-restful"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/klog"
|
||||
|
||||
@@ -78,3 +79,18 @@ func (h *tenantHandler) ListWorkspaces(req *restful.Request, resp *restful.Respo
|
||||
|
||||
resp.WriteEntity(result)
|
||||
}
|
||||
|
||||
func (h *tenantHandler) GetWorkspace(request *restful.Request, response *restful.Response) {
|
||||
workspace, err := h.tenant.GetWorkspace(request.PathParameter("workspace"))
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
if errors.IsNotFound(err) {
|
||||
api.HandleNotFound(response, request, err)
|
||||
return
|
||||
}
|
||||
api.HandleInternalError(response, request, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.WriteEntity(workspace)
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
restfulspec "github.com/emicklei/go-restful-openapi"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
tenantv1alpha1 "kubesphere.io/api/tenant/v1alpha1"
|
||||
"sigs.k8s.io/controller-runtime/pkg/cache"
|
||||
|
||||
tenantv1alpha2 "kubesphere.io/api/tenant/v1alpha2"
|
||||
@@ -115,6 +116,13 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, k8s
|
||||
Doc("List all workspaces that belongs to the current user").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.WorkspaceTag}))
|
||||
|
||||
ws.Route(ws.GET("/workspaces/{workspace}").
|
||||
To(handler.GetWorkspace).
|
||||
Param(ws.PathParameter("workspace", "workspace name")).
|
||||
Returns(http.StatusOK, api.StatusOK, tenantv1alpha1.Workspace{}).
|
||||
Doc("Get workspace.").
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.WorkspaceTag}))
|
||||
|
||||
c.Add(ws)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user