[WIP] API refactor (#1737)

* refactor openpitrix API

Signed-off-by: hongming <talonwan@yunify.com>

* add openpitrix mock client

Signed-off-by: hongming <talonwan@yunify.com>

* refactor tenant API

Signed-off-by: hongming <talonwan@yunify.com>

* refactor IAM API

Signed-off-by: hongming <talonwan@yunify.com>

* refactor IAM API

Signed-off-by: hongming <talonwan@yunify.com>
This commit is contained in:
hongming
2020-01-13 13:36:21 +08:00
committed by zryfish
parent c40d1542a2
commit 71849f028f
66 changed files with 5415 additions and 4366 deletions

View File

@@ -1,18 +0,0 @@
/*
Copyright 2019 The KubeSphere authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package operations contains operations API versions
package openpitrix

View File

@@ -1,33 +0,0 @@
/*
Copyright 2019 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package install
import (
"github.com/emicklei/go-restful"
urlruntime "k8s.io/apimachinery/pkg/util/runtime"
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
"kubesphere.io/kubesphere/pkg/kapis/openpitrix/v1"
)
func init() {
Install(runtime.Container)
}
func Install(container *restful.Container) {
urlruntime.Must(v1.AddToContainer(container))
}

View File

@@ -1,76 +1,925 @@
package v1
import (
"fmt"
"github.com/emicklei/go-restful"
v1 "k8s.io/api/core/v1"
"k8s.io/klog"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
k8sinformers "k8s.io/client-go/informers"
"kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/models"
"kubesphere.io/kubesphere/pkg/models/openpitrix/application"
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3/resource"
"kubesphere.io/kubesphere/pkg/models/openpitrix"
"kubesphere.io/kubesphere/pkg/server/errors"
"kubesphere.io/kubesphere/pkg/server/params"
"openpitrix.io/openpitrix/pkg/pb"
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
op "kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
"net/http"
"strconv"
"strings"
)
type openpitrixHandler struct {
namespacesGetter *resource.NamespacedResourceGetter
applicationOperator application.Interface
openpitrix openpitrix.Interface
informers k8sinformers.SharedInformerFactory
}
func newOpenpitrixHandler(factory informers.InformerFactory, client pb.ClusterManagerClient) *openpitrixHandler {
func newOpenpitrixHandler(k8sClient k8s.Client, opClient op.Client) *openpitrixHandler {
factory := informers.NewInformerFactories(k8sClient.Kubernetes(), k8sClient.KubeSphere(), k8sClient.S2i(), k8sClient.Application())
return &openpitrixHandler{
namespacesGetter: resource.New(factory),
applicationOperator: application.NewApplicaitonOperator(factory.KubernetesSharedInformerFactory(), client),
openpitrix: openpitrix.NewOpenpitrixOperator(factory.KubernetesSharedInformerFactory(), opClient),
informers: factory.KubernetesSharedInformerFactory(),
}
}
func (h *openpitrixHandler) handleListApplications(request *restful.Request, response *restful.Response) {
limit, offset := params.ParsePaging(request.QueryParameter(params.PagingParam))
namespaceName := request.PathParameter("namespace")
conditions, err := params.ParseConditions(request.QueryParameter(params.ConditionsParam))
orderBy := request.QueryParameter(params.OrderByParam)
reverse := params.ParseReverse(request)
if orderBy == "" {
orderBy = "create_time"
reverse = true
}
func (h *openpitrixHandler) ListApplications(request *restful.Request, response *restful.Response) {
limit, offset := params.ParsePaging(request)
namespace := request.PathParameter("namespace")
orderBy := params.GetStringValueWithDefault(request, params.OrderByParam, openpitrix.CreateTime)
reverse := params.GetBoolValueWithDefault(request, params.ReverseParam, true)
conditions, err := params.ParseConditions(request)
if err != nil {
api.HandleBadRequest(response, err)
return
}
if namespaceName != "" {
namespace, err := h.namespacesGetter.Get(api.ResourceKindNamespace, "", namespaceName)
// filter namespaced applications by runtime_id
if namespace != "" {
ns, err := h.informers.Core().V1().Namespaces().Lister().Get(namespace)
if err != nil {
api.HandleInternalError(response, err)
return
}
var runtimeId string
if ns, ok := namespace.(*v1.Namespace); ok {
runtimeId = ns.Annotations[constants.OpenPitrixRuntimeAnnotationKey]
}
runtimeId := ns.Annotations[constants.OpenPitrixRuntimeAnnotationKey]
if runtimeId == "" {
// runtime id not exist,return empty response
response.WriteAsJson(models.PageableResponse{Items: []interface{}{}, TotalCount: 0})
return
} else {
conditions.Match["runtime_id"] = runtimeId
// filter by runtime id
conditions.Match[openpitrix.RuntimeId] = runtimeId
}
}
result, err := h.applicationOperator.List(conditions, limit, offset, orderBy, reverse)
result, err := h.openpitrix.ListApplications(conditions, limit, offset, orderBy, reverse)
if err != nil {
klog.Errorln(err)
api.HandleInternalError(response, err)
return
}
resp.WriteAsJson(result)
response.WriteAsJson(result)
}
func (h *openpitrixHandler) DescribeApplication(req *restful.Request, resp *restful.Response) {
clusterId := req.PathParameter("application")
namespace := req.PathParameter("namespace")
app, err := h.openpitrix.DescribeApplication(namespace, clusterId)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
ns, err := h.informers.Core().V1().Namespaces().Lister().Get(namespace)
if err != nil {
api.HandleInternalError(resp, err)
return
}
runtimeId := ns.Annotations[constants.OpenPitrixRuntimeAnnotationKey]
if runtimeId != app.Cluster.RuntimeId {
err = fmt.Errorf("rumtime not match %s,%s", app.Cluster.RuntimeId, runtimeId)
api.HandleForbidden(resp, err)
return
}
resp.WriteEntity(app)
return
}
func (h *openpitrixHandler) CreateApplication(req *restful.Request, resp *restful.Response) {
namespace := req.PathParameter("namespace")
var createClusterRequest openpitrix.CreateClusterRequest
err := req.ReadEntity(&createClusterRequest)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
createClusterRequest.Username = req.HeaderParameter(constants.UserNameHeader)
err = h.openpitrix.CreateApplication(namespace, createClusterRequest)
if err != nil {
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(errors.None)
}
func (h *openpitrixHandler) ModifyApplication(req *restful.Request, resp *restful.Response) {
var modifyClusterAttributesRequest openpitrix.ModifyClusterAttributesRequest
clusterId := req.PathParameter("application")
namespace := req.PathParameter("namespace")
err := req.ReadEntity(&modifyClusterAttributesRequest)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
app, err := h.openpitrix.DescribeApplication(namespace, clusterId)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
ns, err := h.informers.Core().V1().Namespaces().Lister().Get(namespace)
if err != nil {
api.HandleInternalError(resp, err)
return
}
runtimeId := ns.Annotations[constants.OpenPitrixRuntimeAnnotationKey]
if runtimeId != app.Cluster.RuntimeId {
err = fmt.Errorf("rumtime not match %s,%s", app.Cluster.RuntimeId, runtimeId)
api.HandleForbidden(resp, err)
return
}
err = h.openpitrix.ModifyApplication(modifyClusterAttributesRequest)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(errors.None)
}
func (h *openpitrixHandler) DeleteApplication(req *restful.Request, resp *restful.Response) {
clusterId := req.PathParameter("application")
namespace := req.PathParameter("namespace")
app, err := h.openpitrix.DescribeApplication(namespace, clusterId)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
ns, err := h.informers.Core().V1().Namespaces().Lister().Get(namespace)
if err != nil {
api.HandleInternalError(resp, err)
return
}
runtimeId := ns.Annotations[constants.OpenPitrixRuntimeAnnotationKey]
if runtimeId != app.Cluster.RuntimeId {
err = fmt.Errorf("rumtime not match %s,%s", app.Cluster.RuntimeId, runtimeId)
api.HandleForbidden(resp, err)
return
}
err = h.openpitrix.DeleteApplication(clusterId)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(errors.None)
}
func (h *openpitrixHandler) GetAppVersionPackage(req *restful.Request, resp *restful.Response) {
appId := req.PathParameter("app")
versionId := req.PathParameter("version")
result, err := h.openpitrix.GetAppVersionPackage(appId, versionId)
if err != nil {
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) DoAppAction(req *restful.Request, resp *restful.Response) {
var doActionRequest openpitrix.ActionRequest
err := req.ReadEntity(&doActionRequest)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
appId := req.PathParameter("app")
err = h.openpitrix.DoAppAction(appId, &doActionRequest)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
if status.Code(err) == codes.InvalidArgument {
api.HandleBadRequest(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(errors.None)
}
func (h *openpitrixHandler) DoAppVersionAction(req *restful.Request, resp *restful.Response) {
var doActionRequest openpitrix.ActionRequest
err := req.ReadEntity(&doActionRequest)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
doActionRequest.Username = req.HeaderParameter(constants.UserNameHeader)
versionId := req.PathParameter("version")
err = h.openpitrix.DoAppVersionAction(versionId, &doActionRequest)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
if status.Code(err) == codes.InvalidArgument {
api.HandleBadRequest(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(errors.None)
}
func (h *openpitrixHandler) GetAppVersionFiles(req *restful.Request, resp *restful.Response) {
versionId := req.PathParameter("version")
getAppVersionFilesRequest := &openpitrix.GetAppVersionFilesRequest{}
if f := req.QueryParameter("files"); f != "" {
getAppVersionFilesRequest.Files = strings.Split(f, ",")
}
result, err := h.openpitrix.GetAppVersionFiles(versionId, getAppVersionFilesRequest)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) ListAppVersionAudits(req *restful.Request, resp *restful.Response) {
limit, offset := params.ParsePaging(req)
orderBy := params.GetStringValueWithDefault(req, params.OrderByParam, openpitrix.StatusTime)
reverse := params.GetBoolValueWithDefault(req, params.ReverseParam, true)
appId := req.PathParameter("app")
versionId := req.PathParameter("version")
conditions, err := params.ParseConditions(req)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
conditions.Match[openpitrix.AppId] = appId
if versionId != "" {
conditions.Match[openpitrix.VersionId] = versionId
}
result, err := h.openpitrix.ListAppVersionAudits(conditions, orderBy, reverse, limit, offset)
if err != nil {
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) ListReviews(req *restful.Request, resp *restful.Response) {
limit, offset := params.ParsePaging(req)
orderBy := params.GetStringValueWithDefault(req, params.OrderByParam, openpitrix.StatusTime)
reverse := params.GetBoolValueWithDefault(req, params.ReverseParam, true)
conditions, err := params.ParseConditions(req)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
result, err := h.openpitrix.ListAppVersionReviews(conditions, orderBy, reverse, limit, offset)
if err != nil {
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) ListAppVersions(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, true)
appId := req.PathParameter("app")
statistics := params.GetBoolValueWithDefault(req, "statistics", false)
conditions, err := params.ParseConditions(req)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
conditions.Match[openpitrix.AppId] = appId
result, err := h.openpitrix.ListAppVersions(conditions, orderBy, reverse, limit, offset)
if err != nil {
api.HandleInternalError(resp, err)
return
}
if statistics {
for _, item := range result.Items {
if version, ok := item.(*openpitrix.AppVersion); ok {
statisticsResult, err := h.openpitrix.ListApplications(&params.Conditions{Match: map[string]string{"app_id": version.AppId, "version_id": version.VersionId}}, 0, 0, "", false)
if err != nil {
api.HandleInternalError(resp, err)
return
}
version.ClusterTotal = &statisticsResult.TotalCount
}
}
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) ListApps(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, true)
statistics := params.GetBoolValueWithDefault(req, "statistics", false)
conditions, err := params.ParseConditions(req)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
result, err := h.openpitrix.ListApps(conditions, orderBy, reverse, limit, offset)
if err != nil {
api.HandleInternalError(resp, err)
return
}
if statistics {
for _, item := range result.Items {
if app, ok := item.(*openpitrix.App); ok {
statuses := "active|used|enabled|stopped|pending|creating|upgrading|updating|rollbacking|stopping|starting|recovering|resizing|scaling|deleting"
statisticsResult, err := h.openpitrix.ListApplications(&params.Conditions{Match: map[string]string{openpitrix.AppId: app.AppId, openpitrix.Status: statuses}}, 0, 0, "", false)
if err != nil {
api.HandleInternalError(resp, err)
return
}
app.ClusterTotal = &statisticsResult.TotalCount
}
}
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) ModifyApp(req *restful.Request, resp *restful.Response) {
var patchAppRequest openpitrix.ModifyAppRequest
err := req.ReadEntity(&patchAppRequest)
appId := req.PathParameter("app")
if err != nil {
api.HandleBadRequest(resp, err)
return
}
err = h.openpitrix.ModifyApp(appId, &patchAppRequest)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
if status.Code(err) == codes.InvalidArgument {
api.HandleBadRequest(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(errors.None)
}
func (h *openpitrixHandler) DescribeApp(req *restful.Request, resp *restful.Response) {
appId := req.PathParameter("app")
result, err := h.openpitrix.DescribeApp(appId)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) DeleteApp(req *restful.Request, resp *restful.Response) {
appId := req.PathParameter("app")
err := h.openpitrix.DeleteApp(appId)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(errors.None)
}
func (h *openpitrixHandler) CreateApp(req *restful.Request, resp *restful.Response) {
createAppRequest := &openpitrix.CreateAppRequest{}
err := req.ReadEntity(createAppRequest)
if err != nil {
resp.WriteHeaderAndEntity(http.StatusBadRequest, errors.Wrap(err))
return
}
createAppRequest.Username = req.HeaderParameter(constants.UserNameHeader)
validate, _ := strconv.ParseBool(req.QueryParameter("validate"))
var result interface{}
if validate {
validatePackageRequest := &openpitrix.ValidatePackageRequest{
VersionPackage: createAppRequest.VersionPackage,
VersionType: createAppRequest.VersionType,
}
result, err = h.openpitrix.ValidatePackage(validatePackageRequest)
} else {
result, err = h.openpitrix.CreateApp(createAppRequest)
}
if err != nil {
if status.Code(err) == codes.InvalidArgument {
api.HandleBadRequest(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) CreateAppVersion(req *restful.Request, resp *restful.Response) {
var createAppVersionRequest openpitrix.CreateAppVersionRequest
err := req.ReadEntity(&createAppVersionRequest)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
// override app id
createAppVersionRequest.AppId = req.PathParameter("app")
createAppVersionRequest.Username = req.HeaderParameter(constants.UserNameHeader)
validate, _ := strconv.ParseBool(req.QueryParameter("validate"))
var result interface{}
if validate {
validatePackageRequest := &openpitrix.ValidatePackageRequest{
VersionPackage: createAppVersionRequest.Package,
VersionType: createAppVersionRequest.Type,
}
result, err = h.openpitrix.ValidatePackage(validatePackageRequest)
} else {
result, err = h.openpitrix.CreateAppVersion(&createAppVersionRequest)
}
if err != nil {
if status.Code(err) == codes.InvalidArgument {
api.HandleBadRequest(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) ModifyAppVersion(req *restful.Request, resp *restful.Response) {
var patchAppVersionRequest openpitrix.ModifyAppVersionRequest
err := req.ReadEntity(&patchAppVersionRequest)
versionId := req.PathParameter("version")
if err != nil {
api.HandleBadRequest(resp, err)
return
}
err = h.openpitrix.ModifyAppVersion(versionId, &patchAppVersionRequest)
if err != nil {
if status.Code(err) == codes.InvalidArgument {
api.HandleBadRequest(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(errors.None)
}
func (h *openpitrixHandler) DeleteAppVersion(req *restful.Request, resp *restful.Response) {
versionId := req.PathParameter("version")
err := h.openpitrix.DeleteAppVersion(versionId)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(errors.None)
}
func (h *openpitrixHandler) DescribeAppVersion(req *restful.Request, resp *restful.Response) {
versionId := req.PathParameter("version")
result, err := h.openpitrix.DescribeAppVersion(versionId)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) DescribeAttachment(req *restful.Request, resp *restful.Response) {
attachmentId := req.PathParameter("attachment")
fileName := req.QueryParameter("filename")
result, err := h.openpitrix.DescribeAttachment(attachmentId)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
// file raw
if fileName != "" {
data := result.AttachmentContent[fileName]
resp.Write(data)
resp.Header().Set("Content-Type", "text/plain")
return
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) CreateCategory(req *restful.Request, resp *restful.Response) {
createCategoryRequest := &openpitrix.CreateCategoryRequest{}
err := req.ReadEntity(createCategoryRequest)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
result, err := h.openpitrix.CreateCategory(createCategoryRequest)
if err != nil {
if status.Code(err) == codes.InvalidArgument {
api.HandleBadRequest(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) DeleteCategory(req *restful.Request, resp *restful.Response) {
categoryId := req.PathParameter("category")
err := h.openpitrix.DeleteCategory(categoryId)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(errors.None)
}
func (h *openpitrixHandler) ModifyCategory(req *restful.Request, resp *restful.Response) {
var modifyCategoryRequest openpitrix.ModifyCategoryRequest
categoryId := req.PathParameter("category")
err := req.ReadEntity(&modifyCategoryRequest)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
err = h.openpitrix.ModifyCategory(categoryId, &modifyCategoryRequest)
if err != nil {
if status.Code(err) == codes.InvalidArgument {
api.HandleBadRequest(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(errors.None)
}
func (h *openpitrixHandler) DescribeCategory(req *restful.Request, resp *restful.Response) {
categoryId := req.PathParameter("category")
result, err := h.openpitrix.DescribeCategory(categoryId)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) ListCategories(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, true)
statistics := params.GetBoolValueWithDefault(req, "statistics", false)
conditions, err := params.ParseConditions(req)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
result, err := h.openpitrix.ListCategories(conditions, orderBy, reverse, limit, offset)
if err != nil {
api.HandleInternalError(resp, err)
return
}
if statistics {
for _, item := range result.Items {
if category, ok := item.(*openpitrix.Category); ok {
statisticsResult, err := h.openpitrix.ListApps(&params.Conditions{Match: map[string]string{"category_id": category.CategoryID, "status": openpitrix.StatusActive, "repo": openpitrix.BuiltinRepoId}}, "", false, 0, 0)
if err != nil {
api.HandleInternalError(resp, err)
return
}
category.AppTotal = &statisticsResult.TotalCount
}
}
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) CreateRepo(req *restful.Request, resp *restful.Response) {
createRepoRequest := &openpitrix.CreateRepoRequest{}
err := req.ReadEntity(createRepoRequest)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
validate, _ := strconv.ParseBool(req.QueryParameter("validate"))
var result interface{}
if validate {
validateRepoRequest := &openpitrix.ValidateRepoRequest{
Type: createRepoRequest.Type,
Url: createRepoRequest.URL,
Credential: createRepoRequest.Credential,
}
result, err = h.openpitrix.ValidateRepo(validateRepoRequest)
} else {
result, err = h.openpitrix.CreateRepo(createRepoRequest)
}
if err != nil {
if status.Code(err) == codes.InvalidArgument {
api.HandleBadRequest(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) DoRepoAction(req *restful.Request, resp *restful.Response) {
repoActionRequest := &openpitrix.RepoActionRequest{}
repoId := req.PathParameter("repo")
err := req.ReadEntity(repoActionRequest)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
err = h.openpitrix.DoRepoAction(repoId, repoActionRequest)
if err != nil {
if status.Code(err) == codes.InvalidArgument {
api.HandleBadRequest(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(errors.None)
}
func (h *openpitrixHandler) DeleteRepo(req *restful.Request, resp *restful.Response) {
repoId := req.PathParameter("repo")
err := h.openpitrix.DeleteRepo(repoId)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(errors.None)
}
func (h *openpitrixHandler) ModifyRepo(req *restful.Request, resp *restful.Response) {
var updateRepoRequest openpitrix.ModifyRepoRequest
repoId := req.PathParameter("repo")
err := req.ReadEntity(&updateRepoRequest)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
err = h.openpitrix.ModifyRepo(repoId, &updateRepoRequest)
if err != nil {
if status.Code(err) == codes.InvalidArgument {
api.HandleBadRequest(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(errors.None)
}
func (h *openpitrixHandler) DescribeRepo(req *restful.Request, resp *restful.Response) {
repoId := req.PathParameter("repo")
result, err := h.openpitrix.DescribeRepo(repoId)
if err != nil {
if status.Code(err) == codes.NotFound {
api.HandleNotFound(resp, err)
return
}
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(result)
}
func (h *openpitrixHandler) ListRepos(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, true)
conditions, err := params.ParseConditions(req)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
result, err := h.openpitrix.ListRepos(conditions, orderBy, reverse, limit, offset)
if err != nil {
api.HandleInternalError(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)
conditions, err := params.ParseConditions(req)
if err != nil {
api.HandleBadRequest(resp, err)
return
}
result, err := h.openpitrix.ListRepoEvents(repoId, conditions, limit, offset)
if err != nil {
api.HandleInternalError(resp, err)
return
}
resp.WriteEntity(result)
}

View File

@@ -21,35 +21,33 @@ import (
"github.com/emicklei/go-restful"
"github.com/emicklei/go-restful-openapi"
"k8s.io/apimachinery/pkg/runtime/schema"
"kubesphere.io/kubesphere/pkg/apiserver/openpitrix"
"kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/models"
"kubesphere.io/kubesphere/pkg/models/openpitrix/application"
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
openpitrix2 "kubesphere.io/kubesphere/pkg/models/openpitrix"
"kubesphere.io/kubesphere/pkg/server/errors"
"kubesphere.io/kubesphere/pkg/server/params"
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
op "kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
"net/http"
)
const GroupName = "openpitrix.io"
const (
GroupName = "openpitrix.io"
)
var GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"}
var (
WebServiceBuilder = runtime.NewContainerBuilder(addWebService)
AddToContainer = WebServiceBuilder.AddToContainer
)
func AddToContainer(c *restful.Container, k8s k8s.Client, op op.Client) error {
func addWebService(c *restful.Container) error {
ok := "ok"
mimePatch := []string{restful.MIME_JSON, runtime.MimeMergePatchJson, runtime.MimeJsonPatchJson}
webservice := runtime.NewWebService(GroupVersion)
handler := newOpenpitrixHandler(k8s, op)
webservice.Route(webservice.GET("/applications").
To(openpitrix.ListApplications).
Returns(http.StatusOK, ok, models.PageableResponse{}).
To(handler.ListApplications).
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
Doc("List all applications").
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").
@@ -63,8 +61,8 @@ func addWebService(c *restful.Container) error {
DefaultValue("limit=10,page=1")))
webservice.Route(webservice.GET("/namespaces/{namespace}/applications").
To(openpitrix.ListApplications).
Returns(http.StatusOK, ok, models.PageableResponse{}).
To(handler.ListApplications).
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
Doc("List all applications within the specified namespace").
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").
@@ -78,72 +76,72 @@ func addWebService(c *restful.Container) error {
DefaultValue("limit=10,page=1")))
webservice.Route(webservice.GET("/namespaces/{namespace}/applications/{application}").
To(openpitrix.DescribeApplication).
Returns(http.StatusOK, ok, application.Application{}).
To(handler.DescribeApplication).
Returns(http.StatusOK, api.StatusOK, openpitrix2.Application{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
Doc("Describe the specified application of the namespace").
Param(webservice.PathParameter("namespace", "the name of the project")).
Param(webservice.PathParameter("application", "application ID")))
webservice.Route(webservice.POST("/namespaces/{namespace}/applications").
To(openpitrix.CreateApplication).
To(handler.CreateApplication).
Doc("Deploy a new application").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
Reads(types.CreateClusterRequest{}).
Returns(http.StatusOK, ok, errors.Error{}).
Reads(openpitrix2.CreateClusterRequest{}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("namespace", "the name of the project")))
webservice.Route(webservice.PATCH("/namespaces/{namespace}/applications/{application}").
Consumes(mimePatch...).
To(openpitrix.ModifyApplication).
To(handler.ModifyApplication).
Doc("Modify application").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
Reads(types.ModifyClusterAttributesRequest{}).
Returns(http.StatusOK, ok, errors.Error{}).
Reads(openpitrix2.ModifyClusterAttributesRequest{}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("namespace", "the name of the project")).
Param(webservice.PathParameter("application", "the id of the application cluster")))
webservice.Route(webservice.DELETE("/namespaces/{namespace}/applications/{application}").
To(openpitrix.DeleteApplication).
To(handler.DeleteApplication).
Doc("Delete the specified application").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
Returns(http.StatusOK, ok, errors.Error{}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("namespace", "the name of the project")).
Param(webservice.PathParameter("application", "the id of the application cluster")))
webservice.Route(webservice.POST("/apps/{app}/versions").
To(openpitrix.CreateAppVersion).
To(handler.CreateAppVersion).
Doc("Create a new app template version").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Reads(types.CreateAppVersionRequest{}).
Reads(openpitrix2.CreateAppVersionRequest{}).
Param(webservice.QueryParameter("validate", "Validate format of package(pack by op tool)")).
Returns(http.StatusOK, ok, types.CreateAppVersionResponse{}).
Returns(http.StatusOK, api.StatusOK, openpitrix2.CreateAppVersionResponse{}).
Param(webservice.PathParameter("app", "app template id")))
webservice.Route(webservice.DELETE("/apps/{app}/versions/{version}").
To(openpitrix.DeleteAppVersion).
To(handler.DeleteAppVersion).
Doc("Delete the specified app template version").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Returns(http.StatusOK, ok, errors.Error{}).
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}").
Consumes(mimePatch...).
To(openpitrix.ModifyAppVersion).
To(handler.ModifyAppVersion).
Doc("Patch the specified app template version").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Reads(types.ModifyAppVersionRequest{}).
Returns(http.StatusOK, ok, errors.Error{}).
Reads(openpitrix2.ModifyAppVersionRequest{}).
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.GET("/apps/{app}/versions/{version}").
To(openpitrix.DescribeAppVersion).
To(handler.DescribeAppVersion).
Doc("Describe the specified app template version").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Returns(http.StatusOK, ok, types.AppVersion{}).
Returns(http.StatusOK, api.StatusOK, openpitrix2.AppVersion{}).
Param(webservice.PathParameter("version", "app template version id")).
Param(webservice.PathParameter("app", "app template id")))
webservice.Route(webservice.GET("/apps/{app}/versions").
To(openpitrix.ListAppVersions).
To(handler.ListAppVersions).
Doc("Get active versions of app, can filter with these fields(version_id, app_id, name, owner, description, package_name, status, type), default return all active app versions").
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).
@@ -155,33 +153,33 @@ func addWebService(c *restful.Container) error {
Param(webservice.PathParameter("app", "app template id")).
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, ok, models.PageableResponse{}))
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}))
webservice.Route(webservice.GET("/apps/{app}/versions/{version}/audits").
To(openpitrix.ListAppVersionAudits).
To(handler.ListAppVersionAudits).
Doc("List audits information of version-specific app template").
Returns(http.StatusOK, ok, types.AppVersionAudit{}).
Returns(http.StatusOK, api.StatusOK, openpitrix2.AppVersionAudit{}).
Param(webservice.PathParameter("version", "app template version id")).
Param(webservice.PathParameter("app", "app template id")))
webservice.Route(webservice.GET("/apps/{app}/versions/{version}/package").
To(openpitrix.GetAppVersionPackage).
To(handler.GetAppVersionPackage).
Doc("Get packages of version-specific app").
Returns(http.StatusOK, ok, types.GetAppVersionPackageResponse{}).
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").
To(openpitrix.DoAppVersionAction).
To(handler.DoAppVersionAction).
Doc("Perform submit or other operations on app").
Returns(http.StatusOK, ok, errors.Error{}).
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.GET("/apps/{app}/versions/{version}/files").
To(openpitrix.GetAppVersionFiles).
To(handler.GetAppVersionFiles).
Doc("Get app template package files").
Returns(http.StatusOK, ok, types.GetAppVersionPackageFilesResponse{}).
Returns(http.StatusOK, api.StatusOK, openpitrix2.GetAppVersionPackageFilesResponse{}).
Param(webservice.PathParameter("version", "app template version id")).
Param(webservice.PathParameter("app", "app template id")))
webservice.Route(webservice.GET("/reviews").
To(openpitrix.ListReviews).
To(handler.ListReviews).
Doc("Get reviews of version-specific app").
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).
@@ -190,47 +188,47 @@ func addWebService(c *restful.Container) error {
Required(false).
DataFormat("limit=%d,page=%d").
DefaultValue("limit=10,page=1")).
Returns(http.StatusOK, ok, types.AppVersionReview{}))
Returns(http.StatusOK, api.StatusOK, openpitrix2.AppVersionReview{}))
webservice.Route(webservice.GET("/apps/{app}/audits").
To(openpitrix.ListAppVersionAudits).
To(handler.ListAppVersionAudits).
Doc("List audits information of the specific app template").
Param(webservice.PathParameter("app", "app template id")).
Returns(http.StatusOK, ok, types.AppVersionAudit{}))
Returns(http.StatusOK, api.StatusOK, openpitrix2.AppVersionAudit{}))
webservice.Route(webservice.POST("/apps").
To(openpitrix.CreateApp).
To(handler.CreateApp).
Doc("Create a new app template").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Returns(http.StatusOK, ok, types.CreateAppResponse{}).
Reads(types.CreateAppRequest{}).
Returns(http.StatusOK, api.StatusOK, openpitrix2.CreateAppResponse{}).
Reads(openpitrix2.CreateAppRequest{}).
Param(webservice.PathParameter("app", "app template id")))
webservice.Route(webservice.DELETE("/apps/{app}").
To(openpitrix.DeleteApp).
To(handler.DeleteApp).
Doc("Delete the specified app template").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Returns(http.StatusOK, ok, errors.Error{}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("app", "app template id")))
webservice.Route(webservice.PATCH("/apps/{app}").
Consumes(mimePatch...).
To(openpitrix.ModifyApp).
To(handler.ModifyApp).
Doc("Patch the specified app template").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Reads(types.ModifyAppVersionRequest{}).
Returns(http.StatusOK, ok, errors.Error{}).
Reads(openpitrix2.ModifyAppVersionRequest{}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("app", "app template id")))
webservice.Route(webservice.GET("/apps/{app}").
To(openpitrix.DescribeApp).
To(handler.DescribeApp).
Doc("Describe the specified app template").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Returns(http.StatusOK, ok, types.AppVersion{}).
Returns(http.StatusOK, api.StatusOK, openpitrix2.AppVersion{}).
Param(webservice.PathParameter("app", "app template id")))
webservice.Route(webservice.POST("/apps/{app}/action").
To(openpitrix.DoAppAction).
To(handler.DoAppAction).
Doc("Perform recover or suspend operation on app").
Returns(http.StatusOK, ok, errors.Error{}).
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.GET("/apps").
To(openpitrix.ListApps).
To(handler.ListApps).
Doc("List app templates").
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).
@@ -241,36 +239,36 @@ func addWebService(c *restful.Container) error {
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, ok, models.PageableResponse{}))
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}))
webservice.Route(webservice.POST("/categories").
To(openpitrix.CreateCategory).
To(handler.CreateCategory).
Doc("Create app template category").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Reads(types.CreateCategoryRequest{}).
Returns(http.StatusOK, ok, types.CreateCategoryResponse{}).
Reads(openpitrix2.CreateCategoryRequest{}).
Returns(http.StatusOK, api.StatusOK, openpitrix2.CreateCategoryResponse{}).
Param(webservice.PathParameter("app", "app template id")))
webservice.Route(webservice.DELETE("/categories/{category}").
To(openpitrix.DeleteCategory).
To(handler.DeleteCategory).
Doc("Delete the specified category").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Returns(http.StatusOK, ok, errors.Error{}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("category", "category id")))
webservice.Route(webservice.PATCH("/categories/{category}").
Consumes(mimePatch...).
To(openpitrix.ModifyCategory).
To(handler.ModifyCategory).
Doc("Patch the specified category").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Reads(types.ModifyCategoryRequest{}).
Returns(http.StatusOK, ok, errors.Error{}).
Reads(openpitrix2.ModifyCategoryRequest{}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("category", "category id")))
webservice.Route(webservice.GET("/categories/{category}").
To(openpitrix.DescribeCategory).
To(handler.DescribeCategory).
Doc("Describe the specified category").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Returns(http.StatusOK, ok, types.Category{}).
Returns(http.StatusOK, api.StatusOK, openpitrix2.Category{}).
Param(webservice.PathParameter("category", "category id")))
webservice.Route(webservice.GET("/categories").
To(openpitrix.ListCategories).
To(handler.ListCategories).
Doc("List categories").
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).
@@ -281,43 +279,43 @@ func addWebService(c *restful.Container) error {
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, ok, models.PageableResponse{}))
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}))
webservice.Route(webservice.GET("/attachments/{attachment}").
To(openpitrix.DescribeAttachment).
To(handler.DescribeAttachment).
Doc("Get attachment by attachment id").
Param(webservice.PathParameter("attachment", "attachment id")).
Returns(http.StatusOK, ok, types.Attachment{}))
Returns(http.StatusOK, api.StatusOK, openpitrix2.Attachment{}))
webservice.Route(webservice.POST("/repos").
To(openpitrix.CreateRepo).
To(handler.CreateRepo).
Doc("Create repository, repository used to store package of app").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Param(webservice.QueryParameter("validate", "Validate repository")).
Returns(http.StatusOK, ok, types.CreateRepoResponse{}).
Reads(types.CreateRepoRequest{}))
Returns(http.StatusOK, api.StatusOK, openpitrix2.CreateRepoResponse{}).
Reads(openpitrix2.CreateRepoRequest{}))
webservice.Route(webservice.DELETE("/repos/{repo}").
To(openpitrix.DeleteRepo).
To(handler.DeleteRepo).
Doc("Delete the specified repository").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Returns(http.StatusOK, ok, errors.Error{}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("repo", "repo id")))
webservice.Route(webservice.PATCH("/repos/{repo}").
Consumes(mimePatch...).
To(openpitrix.ModifyRepo).
To(handler.ModifyRepo).
Doc("Patch the specified repository").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Reads(types.ModifyRepoRequest{}).
Returns(http.StatusOK, ok, errors.Error{}).
Reads(openpitrix2.ModifyRepoRequest{}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("repo", "repo id")))
webservice.Route(webservice.GET("/repos/{repo}").
To(openpitrix.DescribeRepo).
To(handler.DescribeRepo).
Doc("Describe the specified repository").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.OpenpitrixTag}).
Returns(http.StatusOK, ok, types.Repo{}).
Returns(http.StatusOK, api.StatusOK, openpitrix2.Repo{}).
Param(webservice.PathParameter("repo", "repo id")))
webservice.Route(webservice.GET("/repos").
To(openpitrix.ListRepos).
To(handler.ListRepos).
Doc("List repositories").
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).
@@ -328,17 +326,17 @@ func addWebService(c *restful.Container) error {
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, ok, models.PageableResponse{}))
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}))
webservice.Route(webservice.POST("/repos/{repo}/action").
To(openpitrix.DoRepoAction).
To(handler.DoRepoAction).
Doc("Start index repository event").
Reads(types.RepoActionRequest{}).
Returns(http.StatusOK, ok, errors.Error{}).
Reads(openpitrix2.RepoActionRequest{}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("repo", "repo id")))
webservice.Route(webservice.GET("/repos/{repo}/events").
To(openpitrix.ListRepoEvents).
To(handler.ListRepoEvents).
Doc("Get repository events").
Returns(http.StatusOK, ok, models.PageableResponse{}).
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}).
Param(webservice.PathParameter("repo", "repo id")))
c.Add(webservice)