From 08877f950be5f3d149b18c71d61f97910e6c0028 Mon Sep 17 00:00:00 2001 From: hongming Date: Mon, 10 Jun 2019 14:37:33 +0800 Subject: [PATCH] update api docs Signed-off-by: hongming --- pkg/apis/iam/v1alpha2/register.go | 14 +++++++------- pkg/apis/resources/v1alpha2/register.go | 6 +++--- pkg/apis/tenant/v1alpha2/register.go | 9 +++++---- pkg/apiserver/iam/im.go | 6 +++--- pkg/apiserver/resources/resources.go | 4 ++++ pkg/apiserver/tenant/tenant.go | 7 +++++++ 6 files changed, 29 insertions(+), 17 deletions(-) diff --git a/pkg/apis/iam/v1alpha2/register.go b/pkg/apis/iam/v1alpha2/register.go index c6f66ebe5..4fd5312a4 100644 --- a/pkg/apis/iam/v1alpha2/register.go +++ b/pkg/apis/iam/v1alpha2/register.go @@ -133,23 +133,23 @@ func addWebService(c *restful.Container) error { Reads(CreateUserRequest{}). Returns(http.StatusOK, ok, errors.Error{}). Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.DELETE("/users/{name}"). + ws.Route(ws.DELETE("/users/{username}"). To(iam.DeleteUser). Doc("Remove a specified user."). - Param(ws.PathParameter("name", "username")). + Param(ws.PathParameter("username", "username")). Returns(http.StatusOK, ok, errors.Error{}). Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.PUT("/users/{name}"). + ws.Route(ws.PUT("/users/{username}"). To(iam.UpdateUser). Doc("Updates information about the specified user."). - Param(ws.PathParameter("name", "username")). + Param(ws.PathParameter("username", "username")). Reads(UserUpdateRequest{}). Returns(http.StatusOK, ok, errors.Error{}). Metadata(restfulspec.KeyOpenAPITags, tags)) - ws.Route(ws.GET("/users/{name}/log"). + ws.Route(ws.GET("/users/{username}/log"). To(iam.UserLoginLog). Doc("This method is used to retrieve the \"login logs\" for the specified user."). - Param(ws.PathParameter("name", "username")). + Param(ws.PathParameter("username", "username")). Returns(http.StatusOK, ok, LoginLog{}). Metadata(restfulspec.KeyOpenAPITags, tags)) ws.Route(ws.GET("/users"). @@ -296,7 +296,7 @@ func addWebService(c *restful.Container) error { To(iam.RemoveUser). Doc("Remove members from workspace."). Param(ws.PathParameter("workspace", "workspace name")). - Param(ws.PathParameter("name", "username")). + Param(ws.PathParameter("username", "username")). Returns(http.StatusOK, ok, errors.Error{}). Metadata(restfulspec.KeyOpenAPITags, tags)) ws.Route(ws.GET("/workspaces/{workspace}/members/{username}"). diff --git a/pkg/apis/resources/v1alpha2/register.go b/pkg/apis/resources/v1alpha2/register.go index 58487eec0..824adfa66 100644 --- a/pkg/apis/resources/v1alpha2/register.go +++ b/pkg/apis/resources/v1alpha2/register.go @@ -60,7 +60,7 @@ func addWebService(c *restful.Container) error { ok := "ok" webservice.Route(webservice.GET("/namespaces/{namespace}/{resources}"). - To(resources.ListResources). + To(resources.ListNamespacedResources). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Namespace level resource query"). Param(webservice.PathParameter("namespace", "which namespace")). @@ -81,7 +81,7 @@ func addWebService(c *restful.Container) error { Returns(http.StatusOK, ok, models.PageableResponse{}). Metadata(restfulspec.KeyOpenAPITags, tags). Doc("Cluster level resource query"). - Param(webservice.PathParameter("resources", "cluster level resource type"))). + Param(webservice.PathParameter("resources", "cluster level resource type")). Param(webservice.QueryParameter(params.ConditionsParam, "query conditions"). Required(false). DataFormat("key=value,key~value"). @@ -89,7 +89,7 @@ func addWebService(c *restful.Container) error { Param(webservice.QueryParameter(params.PagingParam, "page"). Required(false). DataFormat("limit=%d,page=%d"). - DefaultValue("limit=10,page=1")) + DefaultValue("limit=10,page=1"))) tags = []string{"Applications"} diff --git a/pkg/apis/tenant/v1alpha2/register.go b/pkg/apis/tenant/v1alpha2/register.go index c7d4a7aa3..41391939d 100644 --- a/pkg/apis/tenant/v1alpha2/register.go +++ b/pkg/apis/tenant/v1alpha2/register.go @@ -27,7 +27,7 @@ import ( "kubesphere.io/kubesphere/pkg/apiserver/tenant" "kubesphere.io/kubesphere/pkg/models/devops" "kubesphere.io/kubesphere/pkg/params" - esclient "kubesphere.io/kubesphere/pkg/simple/client/elasticsearch" + "kubesphere.io/kubesphere/pkg/simple/client/elasticsearch" "kubesphere.io/kubesphere/pkg/errors" "kubesphere.io/kubesphere/pkg/models" @@ -59,7 +59,8 @@ func addWebService(c *restful.Container) error { Metadata(restfulspec.KeyOpenAPITags, tags)) ws.Route(ws.GET("/workspaces/{workspace}"). To(tenant.DescribeWorkspace). - Doc("Get workspace detail"). + Doc("Describe workspace"). + Param(ws.PathParameter("workspace", "workspace name")). Returns(http.StatusOK, ok, v1alpha1.Workspace{}). Metadata(restfulspec.KeyOpenAPITags, tags)) ws.Route(ws.GET("/workspaces/{workspace}/rules"). @@ -87,7 +88,7 @@ func addWebService(c *restful.Container) error { Returns(http.StatusOK, ok, []v1.Namespace{}). Metadata(restfulspec.KeyOpenAPITags, tags)) ws.Route(ws.GET("/workspaces/{workspace}/members/{username}/namespaces"). - To(tenant.ListNamespaces). + To(tenant.ListNamespacesByUsername). Param(ws.PathParameter("workspace", "workspace name")). Param(ws.PathParameter("username", "workspace member's username")). Doc("List the namespaces for the workspace member"). @@ -120,7 +121,7 @@ func addWebService(c *restful.Container) error { Doc("List devops projects for the current user"). Metadata(restfulspec.KeyOpenAPITags, tags)) ws.Route(ws.GET("/workspaces/{workspace}/members/{username}/devops"). - To(tenant.ListDevopsProjects). + To(tenant.ListDevopsProjectsByUsername). Param(ws.PathParameter("workspace", "workspace name")). Param(ws.PathParameter("username", "workspace member's username")). Param(ws.QueryParameter(params.PagingParam, "page"). diff --git a/pkg/apiserver/iam/im.go b/pkg/apiserver/iam/im.go index aca828a55..2a2ef4007 100644 --- a/pkg/apiserver/iam/im.go +++ b/pkg/apiserver/iam/im.go @@ -77,7 +77,7 @@ func CreateUser(req *restful.Request, resp *restful.Response) { } func DeleteUser(req *restful.Request, resp *restful.Response) { - username := req.PathParameter("name") + username := req.PathParameter("username") operator := req.HeaderParameter(constants.UserNameHeader) @@ -98,7 +98,7 @@ func DeleteUser(req *restful.Request, resp *restful.Response) { func UpdateUser(req *restful.Request, resp *restful.Response) { - usernameInPath := req.PathParameter("name") + usernameInPath := req.PathParameter("username") usernameInHeader := req.HeaderParameter(constants.UserNameHeader) var user models.User @@ -162,7 +162,7 @@ func isUserManager(username string) (bool, error) { } func UserLoginLog(req *restful.Request, resp *restful.Response) { - username := req.PathParameter("name") + username := req.PathParameter("username") logs, err := iam.LoginLog(username) if err != nil { diff --git a/pkg/apiserver/resources/resources.go b/pkg/apiserver/resources/resources.go index 56b195fbb..66f31afc5 100644 --- a/pkg/apiserver/resources/resources.go +++ b/pkg/apiserver/resources/resources.go @@ -26,6 +26,10 @@ import ( "kubesphere.io/kubesphere/pkg/params" ) +func ListNamespacedResources(req *restful.Request, resp *restful.Response) { + ListResources(req, resp) +} + func ListResources(req *restful.Request, resp *restful.Response) { namespace := req.PathParameter("namespace") resourceName := req.PathParameter("resources") diff --git a/pkg/apiserver/tenant/tenant.go b/pkg/apiserver/tenant/tenant.go index 08e12de94..99355bfdf 100644 --- a/pkg/apiserver/tenant/tenant.go +++ b/pkg/apiserver/tenant/tenant.go @@ -101,6 +101,9 @@ func DescribeWorkspace(req *restful.Request, resp *restful.Response) { resp.WriteAsJson(result) } +func ListNamespacesByUsername(req *restful.Request, resp *restful.Response) { + ListNamespaces(req, resp) +} func ListNamespaces(req *restful.Request, resp *restful.Response) { workspace := req.PathParameter("workspace") @@ -208,6 +211,10 @@ func checkResourceQuotas(wokrspace *v1alpha1.Workspace) error { return nil } +func ListDevopsProjectsByUsername(req *restful.Request, resp *restful.Response) { + ListDevopsProjects(req, resp) +} + func ListDevopsProjects(req *restful.Request, resp *restful.Response) { workspace := req.PathParameter("workspace")