未验证 提交 8381bba4 编写于 作者: B Benjamin Huo 提交者: GitHub

Merge branch 'master' into monitoring

......@@ -175,13 +175,6 @@ func addWebService(c *restful.Container) error {
Param(webservice.PathParameter("devops", "devops project's Id")).
Param(webservice.PathParameter("pipelines", "pipeline name")))
webservice.Route(webservice.PUT("/devops/{devops}/pipelines").
To(devopsapi.CreateDevOpsProjectPipelineHandler).
Doc("update devops project pipeline").
Param(webservice.PathParameter("devops", "devops project's Id")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(devops.ProjectPipeline{}))
webservice.Route(webservice.POST("/devops/{devops}/credentials").
To(devopsapi.CreateDevOpsProjectCredentialHandler).
Doc("add project credential pipeline").
......@@ -565,7 +558,7 @@ func addWebService(c *restful.Container) error {
Metadata(restfulspec.KeyOpenAPITags, tags).
Doc("Start a build.").
Produces("text/html; charset=utf-8").
Param(webservice.PathParameter("projecFtName", "devops project name")).
Param(webservice.PathParameter("projectName", "devops project name")).
Param(webservice.PathParameter("pipelineName", "pipeline name")).
Param(webservice.QueryParameter("delay", "delay time").
Required(true).
......
......@@ -32,6 +32,12 @@ import (
func CreateProjectCredential(projectId, username string, credentialRequest *JenkinsCredential) (string, error) {
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return "", restful.NewError(http.StatusServiceUnavailable, err.Error())
}
err := checkJenkinsCredentialExists(projectId, credentialRequest.Domain, credentialRequest.Id)
if err != nil {
glog.Errorf("%+v", err)
......@@ -139,6 +145,11 @@ func CreateProjectCredential(projectId, username string, credentialRequest *Jenk
func UpdateProjectCredential(projectId, credentialId string, credentialRequest *JenkinsCredential) (string, error) {
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return "", restful.NewError(http.StatusServiceUnavailable, err.Error())
}
jenkinsCredential, err := jenkinsClient.GetCredentialInFolder(credentialRequest.Domain,
credentialId,
projectId)
......@@ -228,6 +239,11 @@ func UpdateProjectCredential(projectId, credentialId string, credentialRequest *
func DeleteProjectCredential(projectId, credentialId string, credentialRequest *JenkinsCredential) (string, error) {
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return "", restful.NewError(http.StatusServiceUnavailable, err.Error())
}
dbClient := devops_mysql.OpenDatabase()
_, err := jenkinsClient.GetCredentialInFolder(credentialRequest.Domain,
credentialId,
......@@ -262,6 +278,11 @@ func DeleteProjectCredential(projectId, credentialId string, credentialRequest *
func GetProjectCredential(projectId, credentialId, domain, getContent string) (*JenkinsCredential, error) {
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
}
dbClient := devops_mysql.OpenDatabase()
jenkinsResponse, err := jenkinsClient.GetCredentialInFolder(domain,
credentialId,
......@@ -318,7 +339,7 @@ func GetProjectCredential(projectId, credentialId, domain, getContent string) (*
value, _ := selection.Attr("value")
content.Username = value
})
doc.Find("textarea[name*=privateKey]").Each(func(i int, selection *goquery.Selection) {
value := selection.Text()
content.PrivateKey = value
......@@ -332,6 +353,11 @@ func GetProjectCredential(projectId, credentialId, domain, getContent string) (*
func GetProjectCredentials(projectId, domain string) ([]*JenkinsCredential, error) {
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
}
dbClient := devops_mysql.OpenDatabase()
jenkinsCredentialResponses, err := jenkinsClient.GetCredentialsInFolder(domain, projectId)
if err != nil {
......@@ -367,6 +393,11 @@ func insertCredentialToDb(projectId, credentialId, domain, username string) erro
func checkJenkinsCredentialExists(projectId, domain, credentialId string) error {
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return restful.NewError(http.StatusServiceUnavailable, err.Error())
}
credential, err := jenkinsClient.GetCredentialInFolder(domain, credentialId, projectId)
if credential != nil {
err := fmt.Errorf("credential id [%s] has been used", credential.Id)
......
......@@ -98,7 +98,12 @@ func GetProjectMember(projectId, username string) (*DevOpsProjectMembership, err
func AddProjectMember(projectId, operator string, member *DevOpsProjectMembership) (*DevOpsProjectMembership, error) {
dbconn := devops_mysql.OpenDatabase()
jenkinsClinet := admin_jenkins.Client()
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
}
membership := &DevOpsProjectMembership{}
err := dbconn.Select(DevOpsProjectMembershipColumns...).
......@@ -118,13 +123,13 @@ func AddProjectMember(projectId, operator string, member *DevOpsProjectMembershi
return nil, restful.NewError(http.StatusInternalServerError, err.Error())
}
globalRole, err := jenkinsClinet.GetGlobalRole(JenkinsAllUserRoleName)
globalRole, err := jenkinsClient.GetGlobalRole(JenkinsAllUserRoleName)
if err != nil {
glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
}
if globalRole == nil {
_, err := jenkinsClinet.AddGlobalRole(JenkinsAllUserRoleName, gojenkins.GlobalPermissionIds{
_, err := jenkinsClient.AddGlobalRole(JenkinsAllUserRoleName, gojenkins.GlobalPermissionIds{
GlobalRead: true,
}, true)
if err != nil {
......@@ -137,7 +142,7 @@ func AddProjectMember(projectId, operator string, member *DevOpsProjectMembershi
glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
}
projectRole, err := jenkinsClinet.GetProjectRole(GetProjectRoleName(projectId, member.Role))
projectRole, err := jenkinsClient.GetProjectRole(GetProjectRoleName(projectId, member.Role))
if err != nil {
glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
......@@ -147,7 +152,7 @@ func AddProjectMember(projectId, operator string, member *DevOpsProjectMembershi
glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
}
pipelineRole, err := jenkinsClinet.GetProjectRole(GetPipelineRoleName(projectId, member.Role))
pipelineRole, err := jenkinsClient.GetProjectRole(GetPipelineRoleName(projectId, member.Role))
if err != nil {
glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
......@@ -181,7 +186,12 @@ func AddProjectMember(projectId, operator string, member *DevOpsProjectMembershi
func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMembership) (*DevOpsProjectMembership, error) {
dbconn := devops_mysql.OpenDatabase()
jenkinsClinet := admin_jenkins.Client()
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
}
oldMembership := &DevOpsProjectMembership{}
err := dbconn.Select(DevOpsProjectMembershipColumns...).
From(DevOpsProjectMembershipTableName).
......@@ -194,7 +204,7 @@ func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMember
return nil, restful.NewError(http.StatusBadRequest, err.Error())
}
oldProjectRole, err := jenkinsClinet.GetProjectRole(GetProjectRoleName(projectId, oldMembership.Role))
oldProjectRole, err := jenkinsClient.GetProjectRole(GetProjectRoleName(projectId, oldMembership.Role))
if err != nil {
glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
......@@ -204,7 +214,7 @@ func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMember
glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
}
oldPipelineRole, err := jenkinsClinet.GetProjectRole(GetPipelineRoleName(projectId, oldMembership.Role))
oldPipelineRole, err := jenkinsClient.GetProjectRole(GetPipelineRoleName(projectId, oldMembership.Role))
if err != nil {
glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
......@@ -215,7 +225,7 @@ func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMember
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
}
projectRole, err := jenkinsClinet.GetProjectRole(GetProjectRoleName(projectId, member.Role))
projectRole, err := jenkinsClient.GetProjectRole(GetProjectRoleName(projectId, member.Role))
if err != nil {
glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
......@@ -225,7 +235,7 @@ func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMember
glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
}
pipelineRole, err := jenkinsClinet.GetProjectRole(GetPipelineRoleName(projectId, member.Role))
pipelineRole, err := jenkinsClient.GetProjectRole(GetPipelineRoleName(projectId, member.Role))
if err != nil {
glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
......@@ -262,6 +272,11 @@ func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMember
func DeleteProjectMember(projectId, username string) (string, error) {
dbconn := devops_mysql.OpenDatabase()
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return "", restful.NewError(http.StatusServiceUnavailable, err.Error())
}
oldMembership := &DevOpsProjectMembership{}
err := dbconn.Select(DevOpsProjectMembershipColumns...).
From(DevOpsProjectMembershipTableName).
......
......@@ -24,6 +24,11 @@ import (
func CreateProjectPipeline(projectId string, pipeline *ProjectPipeline) (string, error) {
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return "", restful.NewError(http.StatusServiceUnavailable, err.Error())
}
switch pipeline.Type {
case NoScmPipelineType:
......@@ -89,6 +94,11 @@ func CreateProjectPipeline(projectId string, pipeline *ProjectPipeline) (string,
func DeleteProjectPipeline(projectId string, pipelineId string) (string, error) {
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return "", restful.NewError(http.StatusServiceUnavailable, err.Error())
}
_, err := jenkinsClient.DeleteJob(pipelineId, projectId)
if err != nil {
glog.Errorf("%+v", err)
......@@ -99,6 +109,11 @@ func DeleteProjectPipeline(projectId string, pipelineId string) (string, error)
func UpdateProjectPipeline(projectId, pipelineId string, pipeline *ProjectPipeline) (string, error) {
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return "", restful.NewError(http.StatusServiceUnavailable, err.Error())
}
switch pipeline.Type {
case NoScmPipelineType:
......@@ -155,7 +170,11 @@ func UpdateProjectPipeline(projectId, pipelineId string, pipeline *ProjectPipeli
func GetProjectPipeline(projectId, pipelineId string) (*ProjectPipeline, error) {
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
}
job, err := jenkinsClient.GetJob(pipelineId, projectId)
if err != nil {
glog.Errorf("%+v", err)
......@@ -205,6 +224,11 @@ func GetProjectPipeline(projectId, pipelineId string) (*ProjectPipeline, error)
func GetPipelineSonar(projectId, pipelineId string) ([]*SonarStatus, error) {
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
}
job, err := jenkinsClient.GetJob(pipelineId, projectId)
if err != nil {
glog.Errorf("%+v", err)
......@@ -238,6 +262,11 @@ func GetPipelineSonar(projectId, pipelineId string) ([]*SonarStatus, error) {
func GetMultiBranchPipelineSonar(projectId, pipelineId, branchId string) ([]*SonarStatus, error) {
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
}
job, err := jenkinsClient.GetJob(branchId, projectId, pipelineId)
if err != nil {
glog.Errorf("%+v", err)
......
......@@ -21,6 +21,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/emicklei/go-restful"
"io/ioutil"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/db"
......@@ -35,6 +36,7 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/redis"
"kubesphere.io/kubesphere/pkg/utils/k8sutil"
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
"net/http"
"regexp"
"sort"
"strconv"
......@@ -552,7 +554,11 @@ func DeleteUser(username string) error {
devopsDb := devops_mysql.OpenDatabase()
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return restful.NewError(http.StatusServiceUnavailable, err.Error())
}
_, err = devopsDb.DeleteFrom(devops.DevOpsProjectMembershipTableName).
Where(db.And(
db.Eq(devops.DevOpsProjectMembershipUsernameColumn, username),
......
......@@ -112,6 +112,11 @@ func DeleteDevOpsProject(projectId, username string) error {
return restful.NewError(http.StatusForbidden, err.Error())
}
gojenkins := admin_jenkins.Client()
if gojenkins == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return restful.NewError(http.StatusServiceUnavailable, err.Error())
}
devopsdb := devops_mysql.OpenDatabase()
_, err = gojenkins.DeleteJob(projectId)
......@@ -158,6 +163,11 @@ func DeleteDevOpsProject(projectId, username string) error {
func CreateDevopsProject(username string, workspace string, req *devops.DevOpsProject) (*devops.DevOpsProject, error) {
jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
}
devopsdb := devops_mysql.OpenDatabase()
project := devops.NewDevOpsProject(req.Name, req.Description, username, req.Extra, workspace)
_, err := jenkinsClient.CreateFolder(project.ProjectId, project.Description)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册