@@ -79,7 +79,7 @@ const (
|
|||||||
|
|
||||||
type NoScmPipeline struct {
|
type NoScmPipeline struct {
|
||||||
Name string `json:"name" description:"name of pipeline"`
|
Name string `json:"name" description:"name of pipeline"`
|
||||||
Description string `json:"descriptio,omitempty" description:"description of pipeline"`
|
Description string `json:"description,omitempty" description:"description of pipeline"`
|
||||||
Discarder *DiscarderProperty `json:"discarder,omitempty" description:"Discarder of pipeline, managing when to drop a pipeline"`
|
Discarder *DiscarderProperty `json:"discarder,omitempty" description:"Discarder of pipeline, managing when to drop a pipeline"`
|
||||||
Parameters []Parameter `json:"parameters,omitempty" description:"Parameters define of pipeline,user could pass param when run pipeline"`
|
Parameters []Parameter `json:"parameters,omitempty" description:"Parameters define of pipeline,user could pass param when run pipeline"`
|
||||||
DisableConcurrent bool `json:"disable_concurrent,omitempty" mapstructure:"disable_concurrent" description:"Whether to prohibit the pipeline from running in parallel"`
|
DisableConcurrent bool `json:"disable_concurrent,omitempty" mapstructure:"disable_concurrent" description:"Whether to prohibit the pipeline from running in parallel"`
|
||||||
@@ -90,7 +90,7 @@ type NoScmPipeline struct {
|
|||||||
|
|
||||||
type MultiBranchPipeline struct {
|
type MultiBranchPipeline struct {
|
||||||
Name string `json:"name" description:"name of pipeline"`
|
Name string `json:"name" description:"name of pipeline"`
|
||||||
Description string `json:"descriptio,omitempty" description:"description of pipeline"`
|
Description string `json:"description,omitempty" description:"description of pipeline"`
|
||||||
Discarder *DiscarderProperty `json:"discarder,omitempty" description:"Discarder of pipeline, managing when to drop a pipeline"`
|
Discarder *DiscarderProperty `json:"discarder,omitempty" description:"Discarder of pipeline, managing when to drop a pipeline"`
|
||||||
TimerTrigger *TimerTrigger `json:"timer_trigger,omitempty" mapstructure:"timer_trigger" description:"Timer to trigger pipeline run"`
|
TimerTrigger *TimerTrigger `json:"timer_trigger,omitempty" mapstructure:"timer_trigger" description:"Timer to trigger pipeline run"`
|
||||||
SourceType string `json:"source_type" description:"type of scm, such as github/git/svn"`
|
SourceType string `json:"source_type" description:"type of scm, such as github/git/svn"`
|
||||||
|
|||||||
@@ -532,8 +532,8 @@ func AddPipelineToWebService(webservice *restful.WebService, devopsClient devops
|
|||||||
Param(webservice.QueryParameter("pageSize", "the item count of one page.").
|
Param(webservice.QueryParameter("pageSize", "the item count of one page.").
|
||||||
Required(true).
|
Required(true).
|
||||||
DataFormat("pageSize=%d")).
|
DataFormat("pageSize=%d")).
|
||||||
Returns(http.StatusOK, RespOK, []devops.OrgRepo{}).
|
Returns(http.StatusOK, RespOK, devops.OrgRepo{}).
|
||||||
Writes([]devops.OrgRepo{}))
|
Writes(devops.OrgRepo{}))
|
||||||
|
|
||||||
// match "/blue/rest/organizations/jenkins/scm/%s/servers/" create bitbucket server
|
// match "/blue/rest/organizations/jenkins/scm/%s/servers/" create bitbucket server
|
||||||
webservice.Route(webservice.POST("/scms/{scm}/servers").
|
webservice.Route(webservice.POST("/scms/{scm}/servers").
|
||||||
|
|||||||
@@ -269,11 +269,10 @@ func (r *resourceHandler) handleUpdateRouter(request *restful.Request, response
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *resourceHandler) handleVerifyGitCredential(request *restful.Request, response *restful.Response) {
|
func (r *resourceHandler) handleVerifyGitCredential(request *restful.Request, response *restful.Response) {
|
||||||
|
|
||||||
var credential api.GitCredential
|
var credential api.GitCredential
|
||||||
err := request.ReadEntity(&credential)
|
err := request.ReadEntity(&credential)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.HandleBadRequest(response, nil, err)
|
response.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var namespace, secretName string
|
var namespace, secretName string
|
||||||
@@ -283,11 +282,10 @@ func (r *resourceHandler) handleVerifyGitCredential(request *restful.Request, re
|
|||||||
}
|
}
|
||||||
err = r.gitVerifier.VerifyGitCredential(credential.RemoteUrl, namespace, secretName)
|
err = r.gitVerifier.VerifyGitCredential(credential.RemoteUrl, namespace, secretName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.HandleBadRequest(response, nil, err)
|
response.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
response.WriteAsJson(errors.None)
|
||||||
response.WriteHeader(http.StatusOK)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *resourceHandler) handleVerifyRegistryCredential(request *restful.Request, response *restful.Response) {
|
func (r *resourceHandler) handleVerifyRegistryCredential(request *restful.Request, response *restful.Response) {
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ type DevopsOperator interface {
|
|||||||
|
|
||||||
GetSCMServers(scmId string, req *http.Request) ([]devops.SCMServer, error)
|
GetSCMServers(scmId string, req *http.Request) ([]devops.SCMServer, error)
|
||||||
GetSCMOrg(scmId string, req *http.Request) ([]devops.SCMOrg, error)
|
GetSCMOrg(scmId string, req *http.Request) ([]devops.SCMOrg, error)
|
||||||
GetOrgRepo(scmId, organizationId string, req *http.Request) ([]devops.OrgRepo, error)
|
GetOrgRepo(scmId, organizationId string, req *http.Request) (devops.OrgRepo, error)
|
||||||
CreateSCMServers(scmId string, req *http.Request) (*devops.SCMServer, error)
|
CreateSCMServers(scmId string, req *http.Request) (*devops.SCMServer, error)
|
||||||
Validate(scmId string, req *http.Request) (*devops.Validates, error)
|
Validate(scmId string, req *http.Request) (*devops.Validates, error)
|
||||||
|
|
||||||
@@ -672,12 +672,12 @@ func (d devopsOperator) GetSCMOrg(scmId string, req *http.Request) ([]devops.SCM
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d devopsOperator) GetOrgRepo(scmId, organizationId string, req *http.Request) ([]devops.OrgRepo, error) {
|
func (d devopsOperator) GetOrgRepo(scmId, organizationId string, req *http.Request) (devops.OrgRepo, error) {
|
||||||
|
|
||||||
res, err := d.devopsClient.GetOrgRepo(scmId, organizationId, convertToHttpParameters(req))
|
res, err := d.devopsClient.GetOrgRepo(scmId, organizationId, convertToHttpParameters(req))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(err)
|
klog.Error(err)
|
||||||
return nil, err
|
return devops.OrgRepo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, err
|
return res, err
|
||||||
|
|||||||
@@ -254,8 +254,8 @@ func (d *Devops) GetSCMServers(scmId string, httpParameters *devops.HttpParamete
|
|||||||
func (d *Devops) GetSCMOrg(scmId string, httpParameters *devops.HttpParameters) ([]devops.SCMOrg, error) {
|
func (d *Devops) GetSCMOrg(scmId string, httpParameters *devops.HttpParameters) ([]devops.SCMOrg, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
func (d *Devops) GetOrgRepo(scmId, organizationId string, httpParameters *devops.HttpParameters) ([]devops.OrgRepo, error) {
|
func (d *Devops) GetOrgRepo(scmId, organizationId string, httpParameters *devops.HttpParameters) (devops.OrgRepo, error) {
|
||||||
return nil, nil
|
return devops.OrgRepo{}, nil
|
||||||
}
|
}
|
||||||
func (d *Devops) CreateSCMServers(scmId string, httpParameters *devops.HttpParameters) (*devops.SCMServer, error) {
|
func (d *Devops) CreateSCMServers(scmId string, httpParameters *devops.HttpParameters) (*devops.SCMServer, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|||||||
@@ -658,7 +658,7 @@ func (j *Jenkins) GetSCMServers(scmId string, httpParameters *devops.HttpParamet
|
|||||||
PipelineOjb := &Pipeline{
|
PipelineOjb := &Pipeline{
|
||||||
HttpParameters: httpParameters,
|
HttpParameters: httpParameters,
|
||||||
Jenkins: j,
|
Jenkins: j,
|
||||||
Path: GetSCMServersUrl,
|
Path: fmt.Sprintf(GetSCMServersUrl, scmId),
|
||||||
}
|
}
|
||||||
res, err := PipelineOjb.GetSCMServers()
|
res, err := PipelineOjb.GetSCMServers()
|
||||||
return res, err
|
return res, err
|
||||||
@@ -674,7 +674,7 @@ func (j *Jenkins) GetSCMOrg(scmId string, httpParameters *devops.HttpParameters)
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Jenkins) GetOrgRepo(scmId, organizationId string, httpParameters *devops.HttpParameters) ([]devops.OrgRepo, error) {
|
func (j *Jenkins) GetOrgRepo(scmId, organizationId string, httpParameters *devops.HttpParameters) (devops.OrgRepo, error) {
|
||||||
PipelineOjb := &Pipeline{
|
PipelineOjb := &Pipeline{
|
||||||
HttpParameters: httpParameters,
|
HttpParameters: httpParameters,
|
||||||
Jenkins: j,
|
Jenkins: j,
|
||||||
|
|||||||
@@ -523,16 +523,16 @@ func (p *Pipeline) GetSCMOrg() ([]devops.SCMOrg, error) {
|
|||||||
return SCMOrg, err
|
return SCMOrg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pipeline) GetOrgRepo() ([]devops.OrgRepo, error) {
|
func (p *Pipeline) GetOrgRepo() (devops.OrgRepo, error) {
|
||||||
res, err := p.Jenkins.SendPureRequest(p.Path, p.HttpParameters)
|
res, err := p.Jenkins.SendPureRequest(p.Path, p.HttpParameters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(err)
|
klog.Error(err)
|
||||||
}
|
}
|
||||||
var OrgRepo []devops.OrgRepo
|
var OrgRepo devops.OrgRepo
|
||||||
err = json.Unmarshal(res, &OrgRepo)
|
err = json.Unmarshal(res, &OrgRepo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(err)
|
klog.Error(err)
|
||||||
return nil, err
|
return devops.OrgRepo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return OrgRepo, err
|
return OrgRepo, err
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
package jenkins
|
package jenkins
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
|
"github.com/dgrijalva/jwt-go"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
|
authtoken "kubesphere.io/kubesphere/pkg/apiserver/authentication/token"
|
||||||
"kubesphere.io/kubesphere/pkg/simple/client/devops"
|
"kubesphere.io/kubesphere/pkg/simple/client/devops"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,6 +20,8 @@ func (j *Jenkins) SendPureRequest(path string, httpParameters *devops.HttpParame
|
|||||||
return resBody, err
|
return resBody, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// provider request header to call jenkins api.
|
||||||
|
// transfer bearer token to basic token for inner Oauth and Jeknins
|
||||||
func (j *Jenkins) SendPureRequestWithHeaderResp(path string, httpParameters *devops.HttpParameters) ([]byte, http.Header, error) {
|
func (j *Jenkins) SendPureRequestWithHeaderResp(path string, httpParameters *devops.HttpParameters) ([]byte, http.Header, error) {
|
||||||
Url, err := url.Parse(j.Server + path)
|
Url, err := url.Parse(j.Server + path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -24,10 +31,29 @@ func (j *Jenkins) SendPureRequestWithHeaderResp(path string, httpParameters *dev
|
|||||||
|
|
||||||
client := &http.Client{Timeout: 30 * time.Second}
|
client := &http.Client{Timeout: 30 * time.Second}
|
||||||
|
|
||||||
|
header := httpParameters.Header
|
||||||
|
bearTokenArray := strings.Split(header.Get("Authorization"), " ")
|
||||||
|
bearFlag := bearTokenArray[0]
|
||||||
|
if strings.ToLower(bearFlag) == "bearer" {
|
||||||
|
bearToken := bearTokenArray[1]
|
||||||
|
if err != nil {
|
||||||
|
klog.Error(err)
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
claim := authtoken.Claims{}
|
||||||
|
parser := jwt.Parser{}
|
||||||
|
_, _, err = parser.ParseUnverified(bearToken, &claim)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
creds := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", claim.Username, bearToken)))
|
||||||
|
header.Set("Authorization", fmt.Sprintf("Basic %s", creds))
|
||||||
|
}
|
||||||
|
|
||||||
newRequest := &http.Request{
|
newRequest := &http.Request{
|
||||||
Method: httpParameters.Method,
|
Method: httpParameters.Method,
|
||||||
URL: Url,
|
URL: Url,
|
||||||
Header: httpParameters.Header,
|
Header: header,
|
||||||
Body: httpParameters.Body,
|
Body: httpParameters.Body,
|
||||||
Form: httpParameters.Form,
|
Form: httpParameters.Form,
|
||||||
PostForm: httpParameters.PostForm,
|
PostForm: httpParameters.PostForm,
|
||||||
|
|||||||
@@ -1107,7 +1107,7 @@ type PipelineOperator interface {
|
|||||||
// SCM operator interface
|
// SCM operator interface
|
||||||
GetSCMServers(scmId string, httpParameters *HttpParameters) ([]SCMServer, error)
|
GetSCMServers(scmId string, httpParameters *HttpParameters) ([]SCMServer, error)
|
||||||
GetSCMOrg(scmId string, httpParameters *HttpParameters) ([]SCMOrg, error)
|
GetSCMOrg(scmId string, httpParameters *HttpParameters) ([]SCMOrg, error)
|
||||||
GetOrgRepo(scmId, organizationId string, httpParameters *HttpParameters) ([]OrgRepo, error)
|
GetOrgRepo(scmId, organizationId string, httpParameters *HttpParameters) (OrgRepo, error)
|
||||||
CreateSCMServers(scmId string, httpParameters *HttpParameters) (*SCMServer, error)
|
CreateSCMServers(scmId string, httpParameters *HttpParameters) (*SCMServer, error)
|
||||||
Validate(scmId string, httpParameters *HttpParameters) (*Validates, error)
|
Validate(scmId string, httpParameters *HttpParameters) (*Validates, error)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user