add group api

Signed-off-by: Roland.Ma <rolandma@yunify.com>
This commit is contained in:
Roland.Ma
2020-12-24 09:27:59 +00:00
parent d814d5db7b
commit bec38d7e0f
4 changed files with 47 additions and 78 deletions

View File

@@ -18,10 +18,11 @@ package v1alpha2
import (
"fmt"
"strings"
authuser "k8s.io/apiserver/pkg/authentication/user"
"kubesphere.io/kubesphere/pkg/apiserver/request"
"kubesphere.io/kubesphere/pkg/models/auth"
"strings"
"github.com/emicklei/go-restful"
rbacv1 "k8s.io/api/rbac/v1"
@@ -1344,9 +1345,8 @@ func (h *iamHandler) PatchGroup(request *restful.Request, response *restful.Resp
func (h *iamHandler) ListGroupBindings(request *restful.Request, response *restful.Response) {
workspaceName := request.PathParameter("workspace")
groupName := request.PathParameter("group")
queryParam := query.ParseQueryParameter(request)
result, err := h.group.ListGroupBindings(workspaceName, groupName, queryParam)
result, err := h.group.ListGroupBindings(workspaceName, queryParam)
if err != nil {
api.HandleError(response, request, err)
return
@@ -1357,20 +1357,8 @@ func (h *iamHandler) ListGroupBindings(request *restful.Request, response *restf
func (h *iamHandler) ListGroupRoleBindings(request *restful.Request, response *restful.Response) {
workspaceName := request.PathParameter("workspace")
groupName := request.PathParameter("group")
result, err := h.am.ListGroupRoleBindings(workspaceName, groupName)
if err != nil {
api.HandleInternalError(response, request, err)
return
}
response.WriteEntity(result)
}
func (h *iamHandler) ListGroupDevOpsRoleBindings(request *restful.Request, response *restful.Response) {
workspaceName := request.PathParameter("workspace")
groupName := request.PathParameter("group")
result, err := h.am.ListGroupDevOpsRoleBindings(workspaceName, groupName)
queryParam := query.ParseQueryParameter(request)
result, err := h.am.ListGroupRoleBindings(workspaceName, queryParam)
if err != nil {
api.HandleInternalError(response, request, err)
return
@@ -1416,8 +1404,8 @@ func (h *iamHandler) DeleteRoleBinding(request *restful.Request, response *restf
func (h *iamHandler) ListGroupWorkspaceRoleBindings(request *restful.Request, response *restful.Response) {
workspaceName := request.PathParameter("workspace")
groupName := request.PathParameter("group")
result, err := h.am.ListGroupWorkspaceRoleBindings(workspaceName, groupName)
queryParam := query.ParseQueryParameter(request)
result, err := h.am.ListGroupWorkspaceRoleBindings(workspaceName, queryParam)
if err != nil {
api.HandleInternalError(response, request, err)
return

View File

@@ -17,9 +17,10 @@ limitations under the License.
package v1alpha2
import (
"kubesphere.io/kubesphere/pkg/apiserver/authorization/authorizer"
"net/http"
"kubesphere.io/kubesphere/pkg/apiserver/authorization/authorizer"
"github.com/emicklei/go-restful"
restfulspec "github.com/emicklei/go-restful-openapi"
rbacv1 "k8s.io/api/rbac/v1"
@@ -518,7 +519,15 @@ func AddToContainer(container *restful.Container, im im.IdentityManagementInterf
Returns(http.StatusOK, api.StatusOK, iamv1alpha2.Group{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.GroupTag}))
ws.Route(ws.GET("/workspaces/{workspace}/groups/{group}/groupbindings").
ws.Route(ws.PATCH("/workspaces/{workspace}/groups/{group}/").
To(handler.PatchGroup).
Param(ws.PathParameter("workspace", "workspace name")).
Doc("Patch Group").
Reads(iamv1alpha2.Group{}).
Returns(http.StatusOK, api.StatusOK, iamv1alpha2.Group{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.GroupTag}))
ws.Route(ws.GET("/workspaces/{workspace}/groupbindings").
To(handler.ListGroupBindings).
Param(ws.PathParameter("workspace", "workspace name")).
Param(ws.PathParameter("group", "group name")).
@@ -526,7 +535,7 @@ func AddToContainer(container *restful.Container, im im.IdentityManagementInterf
Returns(http.StatusOK, api.StatusOK, api.ListResult{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.GroupTag}))
ws.Route(ws.GET("/workspaces/{workspace}/groups/{group}/rolebindings").
ws.Route(ws.GET("/workspaces/{workspace}/rolebindings").
To(handler.ListGroupRoleBindings).
Param(ws.PathParameter("workspace", "workspace name")).
Param(ws.PathParameter("group", "group name")).
@@ -534,7 +543,7 @@ func AddToContainer(container *restful.Container, im im.IdentityManagementInterf
Returns(http.StatusOK, api.StatusOK, api.ListResult{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.GroupTag}))
ws.Route(ws.GET("/workspaces/{workspace}/groups/{group}/workspacerolebindings").
ws.Route(ws.GET("/workspaces/{workspace}/workspacerolebindings").
To(handler.ListGroupWorkspaceRoleBindings).
Param(ws.PathParameter("workspace", "workspace name")).
Param(ws.PathParameter("group", "group name")).
@@ -542,14 +551,6 @@ func AddToContainer(container *restful.Container, im im.IdentityManagementInterf
Returns(http.StatusOK, api.StatusOK, api.ListResult{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.GroupTag}))
ws.Route(ws.GET("/workspaces/{workspace}/groups/{group}/devopsrolebindings").
To(handler.ListGroupDevOpsRoleBindings).
Param(ws.PathParameter("workspace", "workspace name")).
Param(ws.PathParameter("group", "group name")).
Doc("Retrieve group's rolebindings of all devops projects in the workspace.").
Returns(http.StatusOK, api.StatusOK, api.ListResult{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.GroupTag}))
ws.Route(ws.DELETE("/workspaces/{workspace}/groupbindings/{groupbinding}").
To(handler.DeleteGroupBinding).
Param(ws.PathParameter("workspace", "workspace name")).