1. refactor kubesphere dependency service client creation, we can disable dependency by config 2. dependencies can be configured by configuration file 3. refactor cmd package using cobra.Command, so we can use hypersphere to invoke command sepearately. Later we only need to build one image to contains all kubesphere core components. One command to rule them all! 4. live reloading configuration currently not implemented
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package sonarqube
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/kubesphere/sonargo/sonar"
|
|
"k8s.io/klog"
|
|
"strings"
|
|
)
|
|
|
|
type SonarQubeClient struct {
|
|
client *sonargo.Client
|
|
}
|
|
|
|
func NewSonarQubeClient(options *SonarQubeOptions) (*SonarQubeClient, error) {
|
|
var endpoint string
|
|
|
|
if strings.HasSuffix(options.Host, "/") {
|
|
endpoint = fmt.Sprintf("%sapi/", options.Host)
|
|
} else {
|
|
endpoint = fmt.Sprintf("%s/api/", options.Host)
|
|
}
|
|
|
|
sonar, err := sonargo.NewClientWithToken(endpoint, options.Token)
|
|
if err != nil {
|
|
klog.Errorf("failed to connect to sonarqube service, %+v", err)
|
|
return nil, err
|
|
}
|
|
|
|
return &SonarQubeClient{client: sonar}, err
|
|
}
|
|
|
|
func NewSonarQubeClientOrDie(options *SonarQubeOptions) *SonarQubeClient {
|
|
var endpoint string
|
|
|
|
if strings.HasSuffix(options.Host, "/") {
|
|
endpoint = fmt.Sprintf("%sapi/", options.Host)
|
|
} else {
|
|
endpoint = fmt.Sprintf("%s/api/", options.Host)
|
|
}
|
|
|
|
sonar, err := sonargo.NewClientWithToken(endpoint, options.Token)
|
|
if err != nil {
|
|
klog.Errorf("failed to connect to sonarqube service, %+v", err)
|
|
panic(err)
|
|
}
|
|
|
|
return &SonarQubeClient{client: sonar}
|
|
}
|
|
|
|
// return sonarqube client
|
|
// Also we can wrap some methods to avoid direct use sonar client
|
|
func (s *SonarQubeClient) SonarQube() *sonargo.Client {
|
|
return s.client
|
|
}
|