Merge pull request #3294 from LinuxSuRen/fix-jenkins-api-proxy
Add support to proxy Jenkins API with POST method
This commit is contained in:
@@ -704,20 +704,29 @@ func AddJenkinsToContainer(webservice *restful.WebService, devopsClient devops.I
|
|||||||
}).
|
}).
|
||||||
Returns(http.StatusOK, RespOK, nil).
|
Returns(http.StatusOK, RespOK, nil).
|
||||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsJenkinsTag}))
|
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsJenkinsTag}))
|
||||||
|
|
||||||
|
handlerWithDevOps := func(request *restful.Request, response *restful.Response) {
|
||||||
|
u := request.Request.URL
|
||||||
|
devops := request.PathParameter("devops")
|
||||||
|
u.Host = parse.Host
|
||||||
|
u.Scheme = parse.Scheme
|
||||||
|
jenkins.SetBasicBearTokenHeader(&request.Request.Header)
|
||||||
|
u.Path = strings.Replace(request.Request.URL.Path, fmt.Sprintf("/kapis/%s/%s/devops/%s/jenkins",
|
||||||
|
GroupVersion.Group, GroupVersion.Version, devops), "", 1)
|
||||||
|
httpProxy := proxy.NewUpgradeAwareHandler(u, http.DefaultTransport, false, false, &errorResponder{})
|
||||||
|
httpProxy.ServeHTTP(response, request.Request)
|
||||||
|
}
|
||||||
|
// some Jenkins API against with POST method
|
||||||
webservice.Route(webservice.GET("/devops/{devops}/jenkins/{path:*}").
|
webservice.Route(webservice.GET("/devops/{devops}/jenkins/{path:*}").
|
||||||
Param(webservice.PathParameter("path", "Path stands for any suffix path.")).
|
Param(webservice.PathParameter("path", "Path stands for any suffix path.")).
|
||||||
Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
|
Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
|
||||||
To(func(request *restful.Request, response *restful.Response) {
|
To(handlerWithDevOps).
|
||||||
u := request.Request.URL
|
Returns(http.StatusOK, RespOK, nil).
|
||||||
devops := request.PathParameter("devops")
|
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsJenkinsTag}))
|
||||||
u.Host = parse.Host
|
webservice.Route(webservice.POST("/devops/{devops}/jenkins/{path:*}").
|
||||||
u.Scheme = parse.Scheme
|
Param(webservice.PathParameter("path", "Path stands for any suffix path.")).
|
||||||
jenkins.SetBasicBearTokenHeader(&request.Request.Header)
|
Param(webservice.PathParameter("devops", "DevOps project's ID, e.g. project-RRRRAzLBlLEm")).
|
||||||
u.Path = strings.Replace(request.Request.URL.Path, fmt.Sprintf("/kapis/%s/%s/devops/%s/jenkins",
|
To(handlerWithDevOps).
|
||||||
GroupVersion.Group, GroupVersion.Version, devops), "", 1)
|
|
||||||
httpProxy := proxy.NewUpgradeAwareHandler(u, http.DefaultTransport, false, false, &errorResponder{})
|
|
||||||
httpProxy.ServeHTTP(response, request.Request)
|
|
||||||
}).
|
|
||||||
Returns(http.StatusOK, RespOK, nil).
|
Returns(http.StatusOK, RespOK, nil).
|
||||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsJenkinsTag}))
|
Metadata(restfulspec.KeyOpenAPITags, []string{constants.DevOpsJenkinsTag}))
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user