sonar handler init

This commit is contained in:
runzexia
2020-04-01 15:21:15 +08:00
parent 9ec99d1a63
commit c80a17f4b4
4 changed files with 11 additions and 10 deletions

View File

@@ -134,6 +134,14 @@ func (s *ServerRunOptions) NewAPIServer(stopCh <-chan struct{}) (*apiserver.APIS
apiServer.DevopsClient = devopsClient
}
if s.SonarQubeOptions.Host != "" {
sonarClient, err := sonarqube.NewSonarQubeClient(s.SonarQubeOptions)
if err != nil {
return nil, err
}
apiServer.SonarClient = sonarqube.NewSonar(sonarClient.SonarQube())
}
if s.LdapOptions.Host != "" {
if s.LdapOptions.Host == fakeInterface && s.DebugMode {
apiServer.LdapClient = ldap.NewSimpleLdap()

View File

@@ -31,10 +31,9 @@ func NewProjectPipelineHandler(devopsClient devopsClient.Interface, dbClient *my
}
}
func NewPipelineSonarHandler(devopsClient devopsClient.Interface, dbClient *mysql.Database, sonarClient sonarqube.SonarInterface) PipelineSonarHandler {
func NewPipelineSonarHandler(devopsClient devopsClient.Interface, sonarClient sonarqube.SonarInterface) PipelineSonarHandler {
return PipelineSonarHandler{
pipelineSonarGetter: devops.NewPipelineSonarGetter(devopsClient, sonarClient),
projectOperator: devops.NewProjectOperator(dbClient),
}
}

View File

@@ -690,9 +690,9 @@ func AddPipelineToWebService(webservice *restful.WebService, devopsClient devops
}
func AddSonarToWebService(webservice *restful.WebService, devopsClient devops.Interface, dbClient *mysql.Database, sonarClient sonarqube.SonarInterface) error {
sonarEnable := devopsClient != nil && dbClient != nil && sonarClient != nil
sonarEnable := devopsClient != nil && sonarClient != nil
if sonarEnable {
sonarHandler := NewPipelineSonarHandler(devopsClient, dbClient, sonarClient)
sonarHandler := NewPipelineSonarHandler(devopsClient, 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/").

View File

@@ -14,18 +14,12 @@ limitations under the License.
package jenkins
import (
"k8s.io/klog"
"kubesphere.io/kubesphere/pkg/simple/client/devops"
)
func NewDevopsClient(options *Options) (devops.Interface, error) {
jenkins := CreateJenkins(nil, options.Host, options.MaxConnections, options.Username, options.Password)
jenkins, err := jenkins.Init()
if err != nil {
klog.Errorf("failed to connecto to jenkins role, %+v", err)
return nil, err
}
return jenkins, nil
}