Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
fcea3477
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
未验证
提交
fcea3477
编写于
7月 16, 2020
作者:
K
KubeSphere CI Bot
提交者:
GitHub
7月 16, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2368 from shaowenchen/add_dowload
using /v1alpha2/jenkins replace /jenkins.kubesphere.io api
上级
f04135a8
6090874c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
68 addition
and
25 deletion
+68
-25
pkg/apiserver/apiserver.go
pkg/apiserver/apiserver.go
+2
-1
pkg/kapis/devops/v1alpha2/register.go
pkg/kapis/devops/v1alpha2/register.go
+40
-2
pkg/simple/client/devops/jenkins/pure_request.go
pkg/simple/client/devops/jenkins/pure_request.go
+1
-22
pkg/simple/client/devops/jenkins/request.go
pkg/simple/client/devops/jenkins/request.go
+25
-0
未找到文件。
pkg/apiserver/apiserver.go
浏览文件 @
fcea3477
...
...
@@ -195,7 +195,8 @@ func (s *APIServer) installKubeSphereAPIs() {
s
.
DevopsClient
,
s
.
SonarClient
,
s
.
KubernetesClient
.
KubeSphere
(),
s
.
S3Client
))
s
.
S3Client
,
s
.
Config
.
DevopsOptions
.
Host
))
urlruntime
.
Must
(
devopsv1alpha3
.
AddToContainer
(
s
.
container
,
s
.
DevopsClient
,
s
.
KubernetesClient
.
Kubernetes
(),
...
...
pkg/kapis/devops/v1alpha2/register.go
浏览文件 @
fcea3477
...
...
@@ -17,20 +17,25 @@ limitations under the License.
package
v1alpha2
import
(
"fmt"
"github.com/emicklei/go-restful"
"github.com/emicklei/go-restful-openapi"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/proxy"
"k8s.io/klog"
devopsv1alpha1
"kubesphere.io/kubesphere/pkg/apis/devops/v1alpha1"
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
"kubesphere.io/kubesphere/pkg/client/clientset/versioned"
"kubesphere.io/kubesphere/pkg/client/informers/externalversions"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/simple/client/devops/jenkins"
"kubesphere.io/kubesphere/pkg/simple/client/s3"
"kubesphere.io/kubesphere/pkg/simple/client/sonarqube"
"net/url"
"strings"
//"kubesphere.io/kubesphere/pkg/models/devops"
"kubesphere.io/kubesphere/pkg/simple/client/devops"
"net/http"
)
...
...
@@ -41,7 +46,7 @@ const (
var
GroupVersion
=
schema
.
GroupVersion
{
Group
:
GroupName
,
Version
:
"v1alpha2"
}
func
AddToContainer
(
container
*
restful
.
Container
,
ksInformers
externalversions
.
SharedInformerFactory
,
devopsClient
devops
.
Interface
,
sonarqubeClient
sonarqube
.
SonarInterface
,
ksClient
versioned
.
Interface
,
s3Client
s3
.
Interface
)
error
{
func
AddToContainer
(
container
*
restful
.
Container
,
ksInformers
externalversions
.
SharedInformerFactory
,
devopsClient
devops
.
Interface
,
sonarqubeClient
sonarqube
.
SonarInterface
,
ksClient
versioned
.
Interface
,
s3Client
s3
.
Interface
,
endpoint
string
)
error
{
ws
:=
runtime
.
NewWebService
(
GroupVersion
)
err
:=
AddPipelineToWebService
(
ws
,
devopsClient
)
...
...
@@ -59,6 +64,11 @@ func AddToContainer(container *restful.Container, ksInformers externalversions.S
return
err
}
err
=
AddJenkinsToContainer
(
ws
,
devopsClient
,
endpoint
)
if
err
!=
nil
{
return
err
}
container
.
Add
(
ws
)
return
nil
...
...
@@ -685,3 +695,31 @@ func AddS2IToWebService(webservice *restful.WebService, ksClient versioned.Inter
}
return
nil
}
func
AddJenkinsToContainer
(
webservice
*
restful
.
WebService
,
devopsClient
devops
.
Interface
,
endpoint
string
)
error
{
if
devopsClient
==
nil
{
return
nil
}
parse
,
err
:=
url
.
Parse
(
endpoint
)
if
err
!=
nil
{
return
err
}
parse
.
Path
=
strings
.
Trim
(
parse
.
Path
,
"/"
)
webservice
.
Route
(
webservice
.
GET
(
"/jenkins/{path:*}"
)
.
To
(
func
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
u
:=
request
.
Request
.
URL
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/jenkins"
,
GroupVersion
.
Group
,
GroupVersion
.
Version
),
""
,
1
)
httpProxy
:=
proxy
.
NewUpgradeAwareHandler
(
u
,
http
.
DefaultTransport
,
false
,
false
,
&
errorResponder
{})
httpProxy
.
ServeHTTP
(
response
,
request
.
Request
)
})
.
Returns
(
http
.
StatusOK
,
RespOK
,
nil
))
return
nil
}
type
errorResponder
struct
{}
func
(
e
*
errorResponder
)
Error
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
,
err
error
)
{
klog
.
Error
(
err
)
}
pkg/simple/client/devops/jenkins/pure_request.go
浏览文件 @
fcea3477
package
jenkins
import
(
"encoding/base64"
"fmt"
"github.com/dgrijalva/jwt-go"
"k8s.io/klog"
authtoken
"kubesphere.io/kubesphere/pkg/apiserver/authentication/token"
"kubesphere.io/kubesphere/pkg/simple/client/devops"
"net/http"
"net/url"
"strings"
"time"
)
...
...
@@ -32,23 +27,7 @@ func (j *Jenkins) SendPureRequestWithHeaderResp(path string, httpParameters *dev
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
))
}
SetBasicBearTokenHeader
(
&
header
)
newRequest
:=
&
http
.
Request
{
Method
:
httpParameters
.
Method
,
...
...
pkg/simple/client/devops/jenkins/request.go
浏览文件 @
fcea3477
...
...
@@ -16,11 +16,14 @@ package jenkins
import
(
"bytes"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"github.com/dgrijalva/jwt-go"
"io"
"io/ioutil"
authtoken
"kubesphere.io/kubesphere/pkg/apiserver/authentication/token"
"kubesphere.io/kubesphere/pkg/simple/client/devops"
"mime/multipart"
"net/http"
...
...
@@ -40,6 +43,28 @@ type APIRequest struct {
Suffix
string
}
// set basic token for jenkins auth
func
SetBasicBearTokenHeader
(
header
*
http
.
Header
)
error
{
bearTokenArray
:=
strings
.
Split
(
header
.
Get
(
"Authorization"
),
" "
)
bearFlag
:=
bearTokenArray
[
0
]
var
err
error
if
strings
.
ToLower
(
bearFlag
)
==
"bearer"
{
bearToken
:=
bearTokenArray
[
1
]
if
err
!=
nil
{
return
err
}
claim
:=
authtoken
.
Claims
{}
parser
:=
jwt
.
Parser
{}
_
,
_
,
err
=
parser
.
ParseUnverified
(
bearToken
,
&
claim
)
if
err
!=
nil
{
return
err
}
creds
:=
base64
.
StdEncoding
.
EncodeToString
([]
byte
(
fmt
.
Sprintf
(
"%s:%s"
,
claim
.
Username
,
bearToken
)))
header
.
Set
(
"Authorization"
,
fmt
.
Sprintf
(
"Basic %s"
,
creds
))
}
return
nil
}
func
(
ar
*
APIRequest
)
SetHeader
(
key
string
,
value
string
)
*
APIRequest
{
ar
.
Headers
.
Set
(
key
,
value
)
return
ar
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录