未验证 提交 ebca5a00 编写于 作者: Z Zhengyi Lai

Refactor OpenPitrix API path

Signed-off-by: NZhengyi Lai <zheng1@yunify.com>
上级 86a027e4
......@@ -399,6 +399,10 @@ func (h *openpitrixHandler) ListApps(req *restful.Request, resp *restful.Respons
statistics := params.GetBoolValueWithDefault(req, "statistics", false)
conditions, err := params.ParseConditions(req)
if req.PathParameter("workspace") != "" {
conditions.Match["isv"] = req.PathParameter("workspace")
}
if err != nil {
klog.V(4).Infoln(err)
api.HandleBadRequest(resp, nil, err)
......@@ -858,29 +862,6 @@ func (h *openpitrixHandler) ListRepos(req *restful.Request, resp *restful.Respon
resp.WriteEntity(result)
}
func (h *openpitrixHandler) ListEvents(req *restful.Request, resp *restful.Response) {
limit, offset := params.ParsePaging(req)
orderBy := params.GetStringValueWithDefault(req, params.OrderByParam, openpitrix.CreateTime)
reverse := params.GetBoolValueWithDefault(req, params.ReverseParam, false)
conditions, err := params.ParseConditions(req)
if err != nil {
klog.V(4).Infoln(err)
api.HandleBadRequest(resp, nil, err)
return
}
result, err := h.openpitrix.ListEvents(conditions, orderBy, reverse, limit, offset)
if err != nil {
klog.Errorln(err)
handleOpenpitrixError(resp, err)
return
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) ListRepoEvents(req *restful.Request, resp *restful.Response) {
repoId := req.PathParameter("repo")
limit, offset := params.ParsePaging(req)
......
......@@ -57,7 +57,7 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
DataFormat("limit=%d,page=%d").
DefaultValue("limit=10,page=1")))
webservice.Route(webservice.GET("/namespaces/{namespace}/applications").
webservice.Route(webservice.GET("/workspaces/{workspace}/namespaces/{namespace}/applications").
To(handler.ListApplications).
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
......@@ -72,7 +72,7 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
DataFormat("limit=%d,page=%d").
DefaultValue("limit=10,page=1")))
webservice.Route(webservice.GET("/namespaces/{namespace}/applications/{application}").
webservice.Route(webservice.GET("/workspaces/{workspace}/namespaces/{namespace}/applications/{application}").
To(handler.DescribeApplication).
Returns(http.StatusOK, api.StatusOK, openpitrix2.Application{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
......@@ -80,7 +80,7 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
Param(webservice.PathParameter("namespace", "the name of the project").Required(true)).
Param(webservice.PathParameter("application", "the id of the application").Required(true)))
webservice.Route(webservice.GET("/clusters/{cluster}/applications").
webservice.Route(webservice.GET("/workspaces/{workspace}/clusters/{cluster}/applications").
To(handler.ListApplications).
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
......@@ -95,7 +95,7 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
DataFormat("limit=%d,page=%d").
DefaultValue("limit=10,page=1")))
webservice.Route(webservice.GET("/clusters/{cluster}/namespaces/{namespace}/applications").
webservice.Route(webservice.GET("/workspaces/{workspace}/clusters/{cluster}/namespaces/{namespace}/applications").
To(handler.ListApplications).
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
......@@ -111,7 +111,7 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
DataFormat("limit=%d,page=%d").
DefaultValue("limit=10,page=1")))
webservice.Route(webservice.GET("/clusters/{cluster}/namespaces/{namespace}/applications/{application}").
webservice.Route(webservice.GET("/workspaces/{workspace}/clusters/{cluster}/namespaces/{namespace}/applications/{application}").
To(handler.DescribeApplication).
Returns(http.StatusOK, api.StatusOK, openpitrix2.Application{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
......@@ -120,7 +120,7 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
Param(webservice.PathParameter("namespace", "the name of the project").Required(true)).
Param(webservice.PathParameter("application", "the id of the application").Required(true)))
webservice.Route(webservice.POST("/clusters/{cluster}/namespaces/{namespace}/applications").
webservice.Route(webservice.POST("/workspaces/{workspace}/clusters/{cluster}/namespaces/{namespace}/applications").
To(handler.CreateApplication).
Doc("Deploy a new application").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
......@@ -129,7 +129,7 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
Param(webservice.PathParameter("cluster", "the name of the cluster.").Required(true)).
Param(webservice.PathParameter("namespace", "the name of the project").Required(true)))
webservice.Route(webservice.PATCH("/clusters/{cluster}/namespaces/{namespace}/applications/{application}").
webservice.Route(webservice.PATCH("/workspaces/{workspace}/clusters/{cluster}/namespaces/{namespace}/applications/{application}").
Consumes(mimePatch...).
To(handler.ModifyApplication).
Doc("Modify application").
......@@ -140,7 +140,7 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
Param(webservice.PathParameter("namespace", "the name of the project").Required(true)).
Param(webservice.PathParameter("application", "the id of the application").Required(true)))
webservice.Route(webservice.DELETE("/clusters/{cluster}/namespaces/{namespace}/applications/{application}").
webservice.Route(webservice.DELETE("/workspaces/{workspace}/clusters/{cluster}/namespaces/{namespace}/applications/{application}").
To(handler.DeleteApplication).
Doc("Delete the specified application").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
......@@ -149,7 +149,7 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
Param(webservice.PathParameter("namespace", "the name of the project").Required(true)).
Param(webservice.PathParameter("application", "the id of the application").Required(true)))
webservice.Route(webservice.POST("/clusters/{cluster}/namespaces/{namespace}/applications/{application}").
webservice.Route(webservice.POST("/workspaces/{workspace}/clusters/{cluster}/namespaces/{namespace}/applications/{application}").
Consumes(mimePatch...).
To(handler.UpgradeApplication).
Doc("Upgrade application").
......@@ -160,7 +160,7 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
Param(webservice.PathParameter("namespace", "the name of the project").Required(true)).
Param(webservice.PathParameter("application", "the id of the application").Required(true)))
webservice.Route(webservice.POST("/apps/{app}/versions").
webservice.Route(webservice.POST("/workspaces/{workspace}/apps/{app}/versions").
To(handler.CreateAppVersion).
Doc("Create a new app template version").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
......@@ -168,14 +168,14 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
Param(webservice.QueryParameter("validate", "Validate format of package(pack by op tool)")).
Returns(http.StatusOK, api.StatusOK, openpitrix2.CreateAppVersionResponse{}).
Param(webservice.PathParameter("app", "app template id")))
webservice.Route(webservice.DELETE("/apps/{app}/versions/{version}").
webservice.Route(webservice.DELETE("/workspaces/{workspace}/apps/{app}/versions/{version}").
To(handler.DeleteAppVersion).
Doc("Delete the specified app template version").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("version", "app template version id")).
Param(webservice.PathParameter("app", "app template id")))
webservice.Route(webservice.PATCH("/apps/{app}/versions/{version}").
webservice.Route(webservice.PATCH("/workspaces/{workspace}/apps/{app}/versions/{version}").
Consumes(mimePatch...).
To(handler.ModifyAppVersion).
Doc("Patch the specified app template version").
......@@ -217,7 +217,7 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
Returns(http.StatusOK, api.StatusOK, openpitrix2.GetAppVersionPackageResponse{}).
Param(webservice.PathParameter("version", "app template version id")).
Param(webservice.PathParameter("app", "app template id")))
webservice.Route(webservice.POST("/apps/{app}/versions/{version}/action").
webservice.Route(webservice.POST("/workspaces/{workspace}/apps/{app}/versions/{version}/action").
To(handler.DoAppVersionAction).
Doc("Perform submit or other operations on app").
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
......@@ -245,20 +245,20 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
Doc("List audits information of the specific app template").
Param(webservice.PathParameter("app", "app template id")).
Returns(http.StatusOK, api.StatusOK, openpitrix2.AppVersionAudit{}))
webservice.Route(webservice.POST("/apps").
webservice.Route(webservice.POST("/workspaces/{workspace}/apps").
To(handler.CreateApp).
Doc("Create a new app template").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Returns(http.StatusOK, api.StatusOK, openpitrix2.CreateAppResponse{}).
Reads(openpitrix2.CreateAppRequest{}).
Param(webservice.PathParameter("app", "app template id")))
webservice.Route(webservice.DELETE("/apps/{app}").
webservice.Route(webservice.DELETE("/workspaces/{workspace}/apps/{app}").
To(handler.DeleteApp).
Doc("Delete the specified app template").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("app", "app template id")))
webservice.Route(webservice.PATCH("/apps/{app}").
webservice.Route(webservice.PATCH("/workspaces/{workspace}/apps/{app}").
Consumes(mimePatch...).
To(handler.ModifyApp).
Doc("Patch the specified app template").
......@@ -272,7 +272,7 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Returns(http.StatusOK, api.StatusOK, openpitrix2.AppVersion{}).
Param(webservice.PathParameter("app", "app template id")))
webservice.Route(webservice.POST("/apps/{app}/action").
webservice.Route(webservice.POST("/workspaces/{workspace}/apps/{app}/action").
To(handler.DoAppAction).
Doc("Perform recover or suspend operation on app").
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
......@@ -291,6 +291,20 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
Param(webservice.QueryParameter(params.ReverseParam, "sort parameters, e.g. reverse=true")).
Param(webservice.QueryParameter(params.OrderByParam, "sort parameters, e.g. orderBy=createTime")).
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}))
webservice.Route(webservice.GET("/workspaces/{workspace}/apps").
To(handler.ListApps).
Doc("List app templates in the specified workspace.").
Param(webservice.PathParameter("workspace", "workspace name")).
Param(webservice.QueryParameter(params.ConditionsParam, "query conditions,connect multiple conditions with commas, equal symbol for exact query, wave symbol for fuzzy query e.g. name~a").
Required(false).
DataFormat("key=%s,key~%s")).
Param(webservice.QueryParameter(params.PagingParam, "paging query, e.g. limit=100,page=1").
Required(false).
DataFormat("limit=%d,page=%d").
DefaultValue("limit=10,page=1")).
Param(webservice.QueryParameter(params.ReverseParam, "sort parameters, e.g. reverse=true")).
Param(webservice.QueryParameter(params.OrderByParam, "sort parameters, e.g. orderBy=createTime")).
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}))
webservice.Route(webservice.POST("/categories").
To(handler.CreateCategory).
Doc("Create app template category").
......@@ -338,36 +352,36 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
Param(webservice.PathParameter("attachment", "attachment id")).
Returns(http.StatusOK, api.StatusOK, openpitrix2.Attachment{}))
webservice.Route(webservice.POST("/repos").
webservice.Route(webservice.POST("/workspaces/{workspace}/repos").
To(handler.CreateRepo).
Doc("Create repository, repository used to store package of app").
Doc("Create repository in the specified workspace, repository used to store package of app").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Param(webservice.QueryParameter("validate", "Validate repository")).
Returns(http.StatusOK, api.StatusOK, openpitrix2.CreateRepoResponse{}).
Reads(openpitrix2.CreateRepoRequest{}))
webservice.Route(webservice.DELETE("/repos/{repo}").
webservice.Route(webservice.DELETE("/workspaces/{workspace}/repos/{repo}").
To(handler.DeleteRepo).
Doc("Delete the specified repository").
Doc("Delete the specified repository in the specified workspace").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("repo", "repo id")))
webservice.Route(webservice.PATCH("/repos/{repo}").
webservice.Route(webservice.PATCH("/workspaces/{workspace}/repos/{repo}").
Consumes(mimePatch...).
To(handler.ModifyRepo).
Doc("Patch the specified repository").
Doc("Patch the specified repository in the specified workspace").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Reads(openpitrix2.ModifyRepoRequest{}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("repo", "repo id")))
webservice.Route(webservice.GET("/repos/{repo}").
webservice.Route(webservice.GET("/workspaces/{workspace}/repos/{repo}").
To(handler.DescribeRepo).
Doc("Describe the specified repository").
Doc("Describe the specified repository in the specified workspace").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Returns(http.StatusOK, api.StatusOK, openpitrix2.Repo{}).
Param(webservice.PathParameter("repo", "repo id")))
webservice.Route(webservice.GET("/repos").
webservice.Route(webservice.GET("/workspaces/{workspace}/repos").
To(handler.ListRepos).
Doc("List repositories").
Doc("List repositories in the specified workspace").
Param(webservice.QueryParameter(params.ConditionsParam, "query conditions,connect multiple conditions with commas, equal symbol for exact query, wave symbol for fuzzy query e.g. name~a").
Required(false).
DataFormat("key=%s,key~%s")).
......@@ -378,20 +392,15 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
Param(webservice.QueryParameter(params.ReverseParam, "sort parameters, e.g. reverse=true")).
Param(webservice.QueryParameter(params.OrderByParam, "sort parameters, e.g. orderBy=createTime")).
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}))
webservice.Route(webservice.POST("/repos/{repo}/action").
webservice.Route(webservice.POST("/workspaces/{workspace}/repos/{repo}/action").
To(handler.DoRepoAction).
Doc("Start index repository event").
Reads(openpitrix2.RepoActionRequest{}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("repo", "repo id")))
webservice.Route(webservice.GET("/events").
To(handler.ListEvents).
Doc("Get events").
Param(webservice.QueryParameter(params.ConditionsParam, "query conditions,connect multiple conditions with commas, equal symbol for exact query, wave symbol for fuzzy query e.g. name~a").
Required(false).
DataFormat("key=%s,key~%s")).
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}))
webservice.Route(webservice.GET("/repos/{repo}/events").
webservice.Route(webservice.GET("/workspaces/{workspace}/repos/{repo}/events").
To(handler.ListRepoEvents).
Doc("Get repository events").
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}).
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册