|
|
|
|
@@ -25,7 +25,13 @@ import (
|
|
|
|
|
"kubesphere.io/kubesphere/pkg/api/devops/v1alpha2"
|
|
|
|
|
devopsv1alpha1 "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha1"
|
|
|
|
|
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
|
|
|
|
|
"kubesphere.io/kubesphere/pkg/client/clientset/versioned"
|
|
|
|
|
"kubesphere.io/kubesphere/pkg/client/informers/externalversions"
|
|
|
|
|
"kubesphere.io/kubesphere/pkg/constants"
|
|
|
|
|
"kubesphere.io/kubesphere/pkg/simple/client/mysql"
|
|
|
|
|
"kubesphere.io/kubesphere/pkg/simple/client/s3"
|
|
|
|
|
"kubesphere.io/kubesphere/pkg/simple/client/sonarqube"
|
|
|
|
|
|
|
|
|
|
//"kubesphere.io/kubesphere/pkg/models/devops"
|
|
|
|
|
"kubesphere.io/kubesphere/pkg/simple/client/devops"
|
|
|
|
|
|
|
|
|
|
@@ -40,21 +46,40 @@ const (
|
|
|
|
|
|
|
|
|
|
var GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"}
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
WebServiceBuilder = runtime.NewContainerBuilder(addWebService)
|
|
|
|
|
AddToContainer = WebServiceBuilder.AddToContainer
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func addWebService(c *restful.Container) error {
|
|
|
|
|
func addWebService(c *restful.Container, devopsClient devops.Interface,
|
|
|
|
|
dbClient *mysql.Database, sonarClient sonarqube.SonarInterface, ksClient versioned.Interface,
|
|
|
|
|
ksInformer externalversions.SharedInformerFactory, s3Client s3.Interface) error {
|
|
|
|
|
|
|
|
|
|
webservice := runtime.NewWebService(GroupVersion)
|
|
|
|
|
|
|
|
|
|
sonarHandler := NewPipelineSonarHandler()
|
|
|
|
|
sonarEnable := devopsClient != nil && dbClient != nil && sonarClient != nil
|
|
|
|
|
projectPipleineEnable := devopsClient != nil && dbClient != nil
|
|
|
|
|
s2iEnable := ksClient != nil && ksInformer != nil && s3Client != nil
|
|
|
|
|
|
|
|
|
|
projectPipelineHander := NewProjectPipelineHandler()
|
|
|
|
|
if sonarEnable {
|
|
|
|
|
sonarHandler := NewPipelineSonarHandler(devopsClient, dbClient, sonarClient)
|
|
|
|
|
webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/sonarstatus").
|
|
|
|
|
To(sonarHandler.GetPipelineSonarStatusHandler).
|
|
|
|
|
Doc("Get the sonar quality information for the specified pipeline of the DevOps project. More info: https://docs.sonarqube.org/7.4/user-guide/metric-definitions/").
|
|
|
|
|
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
|
|
|
|
|
Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
|
|
|
|
|
Param(webservice.PathParameter("pipeline", "the name of pipeline, e.g. sample-pipeline")).
|
|
|
|
|
Returns(http.StatusOK, RespOK, []sonarqube.SonarStatus{}).
|
|
|
|
|
Writes([]sonarqube.SonarStatus{}))
|
|
|
|
|
|
|
|
|
|
s2iHandler := NewS2iBinaryHandler()
|
|
|
|
|
webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/sonarstatus").
|
|
|
|
|
To(sonarHandler.GetMultiBranchesPipelineSonarStatusHandler).
|
|
|
|
|
Doc("Get the sonar quality check information for the specified pipeline branch of the DevOps project. More info: https://docs.sonarqube.org/7.4/user-guide/metric-definitions/").
|
|
|
|
|
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
|
|
|
|
|
Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
|
|
|
|
|
Param(webservice.PathParameter("pipeline", "the name of pipeline, e.g. sample-pipeline")).
|
|
|
|
|
Param(webservice.PathParameter("branch", "branch name, e.g. master")).
|
|
|
|
|
Returns(http.StatusOK, RespOK, []sonarqube.SonarStatus{}).
|
|
|
|
|
Writes([]sonarqube.SonarStatus{}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if projectPipleineEnable{
|
|
|
|
|
projectPipelineHander := NewProjectPipelineHandler(devopsClient, dbClient)
|
|
|
|
|
webservice.Route(webservice.GET("/devops/{devops}").
|
|
|
|
|
To(projectPipelineHander.GetDevOpsProjectHandler).
|
|
|
|
|
Doc("Get the specified DevOps Project").
|
|
|
|
|
@@ -92,8 +117,8 @@ func addWebService(c *restful.Container) error {
|
|
|
|
|
Param(webservice.QueryParameter(params.ConditionsParam, "query conditions, support using key-value pairs separated by comma to search, like 'conditions:somekey=somevalue,anotherkey=anothervalue'").
|
|
|
|
|
Required(false).
|
|
|
|
|
DataFormat("key=%s,key~%s")).
|
|
|
|
|
Returns(http.StatusOK, RespOK, []devops.DevOpsProjectMembership{}).
|
|
|
|
|
Writes([]devops.DevOpsProjectMembership{}))
|
|
|
|
|
Returns(http.StatusOK, RespOK, []devops.ProjectMembership{}).
|
|
|
|
|
Writes([]devops.ProjectMembership{}))
|
|
|
|
|
|
|
|
|
|
webservice.Route(webservice.GET("/devops/{devops}/members/{member}").
|
|
|
|
|
To(projectPipelineHander.GetDevOpsProjectMemberHandler).
|
|
|
|
|
@@ -101,17 +126,17 @@ func addWebService(c *restful.Container) error {
|
|
|
|
|
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectMemberTag}).
|
|
|
|
|
Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
|
|
|
|
|
Param(webservice.PathParameter("member", "member's username, e.g. admin")).
|
|
|
|
|
Returns(http.StatusOK, RespOK, devops.DevOpsProjectMembership{}).
|
|
|
|
|
Writes(devops.DevOpsProjectMembership{}))
|
|
|
|
|
Returns(http.StatusOK, RespOK, devops.ProjectMembership{}).
|
|
|
|
|
Writes(devops.ProjectMembership{}))
|
|
|
|
|
|
|
|
|
|
webservice.Route(webservice.POST("/devops/{devops}/members").
|
|
|
|
|
To(projectPipelineHander.AddDevOpsProjectMemberHandler).
|
|
|
|
|
Doc("Add a member to the specified DevOps project").
|
|
|
|
|
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectMemberTag}).
|
|
|
|
|
Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
|
|
|
|
|
Returns(http.StatusOK, RespOK, devops.DevOpsProjectMembership{}).
|
|
|
|
|
Writes(devops.DevOpsProjectMembership{}).
|
|
|
|
|
Reads(devops.DevOpsProjectMembership{}))
|
|
|
|
|
Returns(http.StatusOK, RespOK, devops.ProjectMembership{}).
|
|
|
|
|
Writes(devops.ProjectMembership{}).
|
|
|
|
|
Reads(devops.ProjectMembership{}))
|
|
|
|
|
|
|
|
|
|
webservice.Route(webservice.PATCH("/devops/{devops}/members/{member}").
|
|
|
|
|
To(projectPipelineHander.UpdateDevOpsProjectMemberHandler).
|
|
|
|
|
@@ -119,9 +144,9 @@ func addWebService(c *restful.Container) error {
|
|
|
|
|
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectMemberTag}).
|
|
|
|
|
Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
|
|
|
|
|
Param(webservice.PathParameter("member", "member's username, e.g. admin")).
|
|
|
|
|
Returns(http.StatusOK, RespOK, devops.DevOpsProjectMembership{}).
|
|
|
|
|
Reads(devops.DevOpsProjectMembership{}).
|
|
|
|
|
Writes(devops.DevOpsProjectMembership{}))
|
|
|
|
|
Returns(http.StatusOK, RespOK, devops.ProjectMembership{}).
|
|
|
|
|
Reads(devops.ProjectMembership{}).
|
|
|
|
|
Writes(devops.ProjectMembership{}))
|
|
|
|
|
|
|
|
|
|
webservice.Route(webservice.DELETE("/devops/{devops}/members/{member}").
|
|
|
|
|
To(projectPipelineHander.DeleteDevOpsProjectMemberHandler).
|
|
|
|
|
@@ -129,7 +154,7 @@ func addWebService(c *restful.Container) error {
|
|
|
|
|
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsProjectMemberTag}).
|
|
|
|
|
Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
|
|
|
|
|
Param(webservice.PathParameter("member", "member's username, e.g. admin")).
|
|
|
|
|
Writes(devops.DevOpsProjectMembership{}))
|
|
|
|
|
Writes(devops.ProjectMembership{}))
|
|
|
|
|
|
|
|
|
|
webservice.Route(webservice.POST("/devops/{devops}/pipelines").
|
|
|
|
|
To(projectPipelineHander.CreateDevOpsProjectPipelineHandler).
|
|
|
|
|
@@ -165,24 +190,7 @@ func addWebService(c *restful.Container) error {
|
|
|
|
|
Returns(http.StatusOK, RespOK, devops.ProjectPipeline{}).
|
|
|
|
|
Writes(devops.ProjectPipeline{}))
|
|
|
|
|
|
|
|
|
|
webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/sonarstatus").
|
|
|
|
|
To(sonarHandler.GetPipelineSonarStatusHandler).
|
|
|
|
|
Doc("Get the sonar quality information for the specified pipeline of the DevOps project. More info: https://docs.sonarqube.org/7.4/user-guide/metric-definitions/").
|
|
|
|
|
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
|
|
|
|
|
Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
|
|
|
|
|
Param(webservice.PathParameter("pipeline", "the name of pipeline, e.g. sample-pipeline")).
|
|
|
|
|
Returns(http.StatusOK, RespOK, []devops.SonarStatus{}).
|
|
|
|
|
Writes([]devops.SonarStatus{}))
|
|
|
|
|
|
|
|
|
|
webservice.Route(webservice.GET("/devops/{devops}/pipelines/{pipeline}/branches/{branch}/sonarstatus").
|
|
|
|
|
To(sonarHandler.GetMultiBranchesPipelineSonarStatusHandler).
|
|
|
|
|
Doc("Get the sonar quality check information for the specified pipeline branch of the DevOps project. More info: https://docs.sonarqube.org/7.4/user-guide/metric-definitions/").
|
|
|
|
|
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
|
|
|
|
|
Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
|
|
|
|
|
Param(webservice.PathParameter("pipeline", "the name of pipeline, e.g. sample-pipeline")).
|
|
|
|
|
Param(webservice.PathParameter("branch", "branch name, e.g. master")).
|
|
|
|
|
Returns(http.StatusOK, RespOK, []devops.SonarStatus{}).
|
|
|
|
|
Writes([]devops.SonarStatus{}))
|
|
|
|
|
|
|
|
|
|
webservice.Route(webservice.POST("/devops/{devops}/credentials").
|
|
|
|
|
To(projectPipelineHander.CreateDevOpsProjectCredentialHandler).
|
|
|
|
|
@@ -729,26 +737,6 @@ The last one is encrypted info, such as the password of the username-password ty
|
|
|
|
|
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsWebhookTag}).
|
|
|
|
|
Doc("Get commit notification. Github webhook will request here."))
|
|
|
|
|
|
|
|
|
|
webservice.Route(webservice.PUT("/namespaces/{namespace}/s2ibinaries/{s2ibinary}/file").
|
|
|
|
|
To(s2iHandler.UploadS2iBinaryHandler).
|
|
|
|
|
Consumes("multipart/form-data").
|
|
|
|
|
Produces(restful.MIME_JSON).
|
|
|
|
|
Doc("Upload S2iBinary file").
|
|
|
|
|
Param(webservice.PathParameter("namespace", "the name of namespaces")).
|
|
|
|
|
Param(webservice.PathParameter("s2ibinary", "the name of s2ibinary")).
|
|
|
|
|
Param(webservice.FormParameter("s2ibinary", "file to upload")).
|
|
|
|
|
Param(webservice.FormParameter("md5", "md5 of file")).
|
|
|
|
|
Returns(http.StatusOK, RespOK, devopsv1alpha1.S2iBinary{}))
|
|
|
|
|
|
|
|
|
|
webservice.Route(webservice.GET("/namespaces/{namespace}/s2ibinaries/{s2ibinary}/file/{file}").
|
|
|
|
|
To(s2iHandler.DownloadS2iBinaryHandler).
|
|
|
|
|
Produces(restful.MIME_OCTET).
|
|
|
|
|
Doc("Download S2iBinary file").
|
|
|
|
|
Param(webservice.PathParameter("namespace", "the name of namespaces")).
|
|
|
|
|
Param(webservice.PathParameter("s2ibinary", "the name of s2ibinary")).
|
|
|
|
|
Param(webservice.PathParameter("file", "the name of binary file")).
|
|
|
|
|
Returns(http.StatusOK, RespOK, nil))
|
|
|
|
|
|
|
|
|
|
webservice.Route(webservice.POST("/devops/{devops}/pipelines/{pipeline}/checkScriptCompile").
|
|
|
|
|
To(projectPipelineHander.CheckScriptCompile).
|
|
|
|
|
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsPipelineTag}).
|
|
|
|
|
@@ -795,6 +783,31 @@ The last one is encrypted info, such as the password of the username-password ty
|
|
|
|
|
Reads(devops.ReqJenkinsfile{}).
|
|
|
|
|
Returns(http.StatusOK, RespOK, devops.ResJson{}).
|
|
|
|
|
Writes(devops.ResJson{}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if s2iEnable {
|
|
|
|
|
s2iHandler := NewS2iBinaryHandler(ksClient, ksInformer, s3Client)
|
|
|
|
|
webservice.Route(webservice.PUT("/namespaces/{namespace}/s2ibinaries/{s2ibinary}/file").
|
|
|
|
|
To(s2iHandler.UploadS2iBinaryHandler).
|
|
|
|
|
Consumes("multipart/form-data").
|
|
|
|
|
Produces(restful.MIME_JSON).
|
|
|
|
|
Doc("Upload S2iBinary file").
|
|
|
|
|
Param(webservice.PathParameter("namespace", "the name of namespaces")).
|
|
|
|
|
Param(webservice.PathParameter("s2ibinary", "the name of s2ibinary")).
|
|
|
|
|
Param(webservice.FormParameter("s2ibinary", "file to upload")).
|
|
|
|
|
Param(webservice.FormParameter("md5", "md5 of file")).
|
|
|
|
|
Returns(http.StatusOK, RespOK, devopsv1alpha1.S2iBinary{}))
|
|
|
|
|
|
|
|
|
|
webservice.Route(webservice.GET("/namespaces/{namespace}/s2ibinaries/{s2ibinary}/file/{file}").
|
|
|
|
|
To(s2iHandler.DownloadS2iBinaryHandler).
|
|
|
|
|
Produces(restful.MIME_OCTET).
|
|
|
|
|
Doc("Download S2iBinary file").
|
|
|
|
|
Param(webservice.PathParameter("namespace", "the name of namespaces")).
|
|
|
|
|
Param(webservice.PathParameter("s2ibinary", "the name of s2ibinary")).
|
|
|
|
|
Param(webservice.PathParameter("file", "the name of binary file")).
|
|
|
|
|
Returns(http.StatusOK, RespOK, nil))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.Add(webservice)
|
|
|
|
|
|
|
|
|
|
|