119
pkg/apis/devops/v1alpha2/register.go
Normal file
119
pkg/apis/devops/v1alpha2/register.go
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
|
||||
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 v1alpha2
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful"
|
||||
"github.com/emicklei/go-restful-openapi"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/devops"
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
|
||||
)
|
||||
|
||||
const GroupName = "devops.kubesphere.io"
|
||||
|
||||
var GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"}
|
||||
|
||||
var (
|
||||
WebServiceBuilder = runtime.NewContainerBuilder(addWebService)
|
||||
AddToContainer = WebServiceBuilder.AddToContainer
|
||||
)
|
||||
|
||||
func addWebService(c *restful.Container) error {
|
||||
webservice := runtime.NewWebService(GroupVersion)
|
||||
|
||||
tags := []string{"devops"}
|
||||
|
||||
// match Jenkisn api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}"
|
||||
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}").
|
||||
To(devops.GetPipeline).
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Doc("Get DevOps Pipelines.").
|
||||
Param(webservice.PathParameter("pipelineName", "pipeline name")).
|
||||
Param(webservice.PathParameter("projectName", "devops project name")))
|
||||
|
||||
// match Jenkisn api: "jenkins_api/blue/rest/search"
|
||||
webservice.Route(webservice.GET("/devops/search").
|
||||
To(devops.SearchPipelines).
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Doc("Search DevOps resource.").
|
||||
Param(webservice.QueryParameter("q", "query pipelines").
|
||||
Required(false)).
|
||||
Param(webservice.QueryParameter("filter", "filter resource").
|
||||
Required(false)).
|
||||
Param(webservice.QueryParameter("start", "start page").
|
||||
Required(false)).
|
||||
Param(webservice.QueryParameter("limit", "limit count").
|
||||
Required(false)))
|
||||
|
||||
// match Jenkisn api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/runs/"
|
||||
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/runs").
|
||||
To(devops.SearchPipelineRuns).
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Doc("Search DevOps Pipelines runs.").
|
||||
Param(webservice.PathParameter("pipelineName", "pipeline name")).
|
||||
Param(webservice.PathParameter("projectName", "devops project name")).
|
||||
Param(webservice.QueryParameter("start", "start page").
|
||||
Required(false)).
|
||||
Param(webservice.QueryParameter("limit", "limit count").
|
||||
Required(false)))
|
||||
|
||||
// match Jenkins api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/"
|
||||
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}").
|
||||
To(devops.GetPipelineRun).
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Doc("Get DevOps Pipelines run.").
|
||||
Param(webservice.PathParameter("pipelineName", "pipeline name")).
|
||||
Param(webservice.PathParameter("projectName", "devops project name")).
|
||||
Param(webservice.PathParameter("branchName", "pipeline branch name")).
|
||||
Param(webservice.PathParameter("runId", "pipeline runs id")))
|
||||
|
||||
// match Jenkins api "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes"
|
||||
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes").
|
||||
To(devops.GetPipelineRunNodes).
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Doc("Get node on DevOps Pipelines run.").
|
||||
Param(webservice.PathParameter("projectName", "devops project name")).
|
||||
Param(webservice.PathParameter("pipelineName", "pipeline name")).
|
||||
Param(webservice.PathParameter("branchName", "pipeline branch name")).
|
||||
Param(webservice.PathParameter("runId", "pipeline runs id")).
|
||||
Param(webservice.QueryParameter("limit", "limit").
|
||||
Required(false).
|
||||
DataFormat("limit=%d").
|
||||
DefaultValue("limit=10000")))
|
||||
|
||||
// match "/blue/rest/organizations/jenkins/pipelines/{projectName}/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log/?start=0"
|
||||
webservice.Route(webservice.GET("/devops/{projectName}/pipelines/{pipelineName}/branches/{branchName}/runs/{runId}/nodes/{nodeId}/steps/{stepId}/log").
|
||||
To(devops.GetStepLog).
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Doc("Get Pipelines step log.").
|
||||
Param(webservice.PathParameter("projectName", "devops project name")).
|
||||
Param(webservice.PathParameter("pipelineName", "pipeline name")).
|
||||
Param(webservice.PathParameter("branchName", "pipeline branch name")).
|
||||
Param(webservice.PathParameter("runId", "pipeline runs id")).
|
||||
Param(webservice.PathParameter("nodeId", "pipeline runs node id")).
|
||||
Param(webservice.PathParameter("stepId", "pipeline runs step id")).
|
||||
Param(webservice.QueryParameter("start", "start").
|
||||
Required(true).
|
||||
DataFormat("start=%d").
|
||||
DefaultValue("start=0")))
|
||||
|
||||
c.Add(webservice)
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user