Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
92e7349c
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看板
提交
92e7349c
编写于
12月 02, 2020
作者:
LinuxSuRen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix an issue which the pipeline owner cannot approve his pipeline
Signed-off-by:
rick
<
rick@jenkins-zh.cn
>
上级
8451c182
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
23 addition
and
9 deletion
+23
-9
go.mod
go.mod
+2
-0
pkg/kapis/devops/v1alpha2/devops.go
pkg/kapis/devops/v1alpha2/devops.go
+16
-4
pkg/kapis/devops/v1alpha2/handler.go
pkg/kapis/devops/v1alpha2/handler.go
+2
-2
pkg/kapis/devops/v1alpha2/register.go
pkg/kapis/devops/v1alpha2/register.go
+3
-3
未找到文件。
go.mod
浏览文件 @
92e7349c
...
@@ -51,6 +51,7 @@ require (
...
@@ -51,6 +51,7 @@ require (
github.com/kubernetes-csi/external-snapshotter/v2
v2.1.0
github.com/kubernetes-csi/external-snapshotter/v2
v2.1.0
github.com/kubesphere/sonargo
v0.0.2
github.com/kubesphere/sonargo
v0.0.2
github.com/lib/pq
v1.2.0 // indirect
github.com/lib/pq
v1.2.0 // indirect
github.com/mitchellh/mapstructure
v1.2.2
github.com/onsi/ginkgo
v1.12.0
github.com/onsi/ginkgo
v1.12.0
github.com/onsi/gomega
v1.9.0
github.com/onsi/gomega
v1.9.0
github.com/open-policy-agent/opa
v0.18.0
github.com/open-policy-agent/opa
v0.18.0
...
@@ -80,6 +81,7 @@ require (
...
@@ -80,6 +81,7 @@ require (
gopkg.in/src-d/go-git.v4
v4.11.0
gopkg.in/src-d/go-git.v4
v4.11.0
gopkg.in/yaml.v2
v2.3.0
gopkg.in/yaml.v2
v2.3.0
gopkg.in/yaml.v3
v3.0.0-20200313102051-9f266ea9e77c
gopkg.in/yaml.v3
v3.0.0-20200313102051-9f266ea9e77c
gotest.tools
v2.2.0+incompatible
istio.io/api
v0.0.0-20191111210003-35e06ef8d838
istio.io/api
v0.0.0-20191111210003-35e06ef8d838
istio.io/client-go
v0.0.0-20191113122552-9bd0ba57c3d2
istio.io/client-go
v0.0.0-20191113122552-9bd0ba57c3d2
k8s.io/api
v0.17.5
k8s.io/api
v0.17.5
...
...
pkg/kapis/devops/v1alpha2/devops.go
浏览文件 @
92e7349c
...
@@ -26,6 +26,7 @@ import (
...
@@ -26,6 +26,7 @@ import (
"kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/api"
iamv1alpha2
"kubesphere.io/kubesphere/pkg/apis/iam/v1alpha2"
iamv1alpha2
"kubesphere.io/kubesphere/pkg/apis/iam/v1alpha2"
"kubesphere.io/kubesphere/pkg/apiserver/request"
"kubesphere.io/kubesphere/pkg/apiserver/request"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/models/devops"
"kubesphere.io/kubesphere/pkg/models/devops"
clientDevOps
"kubesphere.io/kubesphere/pkg/simple/client/devops"
clientDevOps
"kubesphere.io/kubesphere/pkg/simple/client/devops"
"net/http"
"net/http"
...
@@ -229,6 +230,17 @@ func (h *ProjectPipelineHandler) approvableCheck(nodes []clientDevOps.NodesDetai
...
@@ -229,6 +230,17 @@ func (h *ProjectPipelineHandler) approvableCheck(nodes []clientDevOps.NodesDetai
}
}
}
}
func
(
h
*
ProjectPipelineHandler
)
createdBy
(
projectName
string
,
pipelineName
string
,
currentUserName
string
)
bool
{
if
pipeline
,
err
:=
h
.
devopsOperator
.
GetPipelineObj
(
projectName
,
pipelineName
);
err
==
nil
{
if
creator
,
ok
:=
pipeline
.
Annotations
[
constants
.
CreatorAnnotationKey
];
ok
{
return
creator
==
currentUserName
}
}
else
{
log
.
Error
(
fmt
.
Sprintf
(
"cannot get pipeline %s/%s, error %#v"
,
projectName
,
pipelineName
,
err
))
}
return
false
}
func
(
h
*
ProjectPipelineHandler
)
getCurrentUser
(
req
*
restful
.
Request
)
(
username
,
roleName
string
)
{
func
(
h
*
ProjectPipelineHandler
)
getCurrentUser
(
req
*
restful
.
Request
)
(
username
,
roleName
string
)
{
var
userInfo
user
.
Info
var
userInfo
user
.
Info
var
ok
bool
var
ok
bool
...
@@ -247,8 +259,10 @@ func (h *ProjectPipelineHandler) getCurrentUser(req *restful.Request) (username,
...
@@ -247,8 +259,10 @@ func (h *ProjectPipelineHandler) getCurrentUser(req *restful.Request) (username,
func
(
h
*
ProjectPipelineHandler
)
hasSubmitPermission
(
req
*
restful
.
Request
)
(
hasPermit
bool
,
err
error
)
{
func
(
h
*
ProjectPipelineHandler
)
hasSubmitPermission
(
req
*
restful
.
Request
)
(
hasPermit
bool
,
err
error
)
{
currentUserName
,
roleName
:=
h
.
getCurrentUser
(
req
)
currentUserName
,
roleName
:=
h
.
getCurrentUser
(
req
)
// check if current user belong to the admin group, grant it if it's true
projectName
:=
req
.
PathParameter
(
"devops"
)
if
roleName
==
iamv1alpha2
.
PlatformAdmin
{
pipelineName
:=
req
.
PathParameter
(
"pipeline"
)
// check if current user belong to the admin group or he's the owner, grant it if it's true
if
roleName
==
iamv1alpha2
.
PlatformAdmin
||
h
.
createdBy
(
projectName
,
pipelineName
,
currentUserName
)
{
hasPermit
=
true
hasPermit
=
true
return
return
}
}
...
@@ -261,8 +275,6 @@ func (h *ProjectPipelineHandler) hasSubmitPermission(req *restful.Request) (hasP
...
@@ -261,8 +275,6 @@ func (h *ProjectPipelineHandler) hasSubmitPermission(req *restful.Request) (hasP
PostForm
:
req
.
Request
.
PostForm
,
PostForm
:
req
.
Request
.
PostForm
,
}
}
projectName
:=
req
.
PathParameter
(
"devops"
)
pipelineName
:=
req
.
PathParameter
(
"pipeline"
)
runId
:=
req
.
PathParameter
(
"run"
)
runId
:=
req
.
PathParameter
(
"run"
)
nodeId
:=
req
.
PathParameter
(
"node"
)
nodeId
:=
req
.
PathParameter
(
"node"
)
stepId
:=
req
.
PathParameter
(
"step"
)
stepId
:=
req
.
PathParameter
(
"step"
)
...
...
pkg/kapis/devops/v1alpha2/handler.go
浏览文件 @
92e7349c
...
@@ -36,9 +36,9 @@ type PipelineSonarHandler struct {
...
@@ -36,9 +36,9 @@ type PipelineSonarHandler struct {
pipelineSonarGetter
devops
.
PipelineSonarGetter
pipelineSonarGetter
devops
.
PipelineSonarGetter
}
}
func
NewProjectPipelineHandler
(
devopsClient
devopsClient
.
Interface
,
amInterface
am
.
AccessManagementInterface
)
ProjectPipelineHandler
{
func
NewProjectPipelineHandler
(
devopsClient
devopsClient
.
Interface
,
ksInformers
externalversions
.
SharedInformerFactory
,
amInterface
am
.
AccessManagementInterface
)
ProjectPipelineHandler
{
return
ProjectPipelineHandler
{
return
ProjectPipelineHandler
{
devopsOperator
:
devops
.
NewDevopsOperator
(
devopsClient
,
nil
,
nil
,
nil
,
nil
),
devopsOperator
:
devops
.
NewDevopsOperator
(
devopsClient
,
nil
,
nil
,
ksInformers
,
nil
),
projectCredentialGetter
:
devops
.
NewProjectCredentialOperator
(
devopsClient
),
projectCredentialGetter
:
devops
.
NewProjectCredentialOperator
(
devopsClient
),
amInterface
:
amInterface
,
amInterface
:
amInterface
,
}
}
...
...
pkg/kapis/devops/v1alpha2/register.go
浏览文件 @
92e7349c
...
@@ -50,7 +50,7 @@ var GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"}
...
@@ -50,7 +50,7 @@ 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
,
endpoint
string
,
amInterface
am
.
AccessManagementInterface
)
error
{
func
AddToContainer
(
container
*
restful
.
Container
,
ksInformers
externalversions
.
SharedInformerFactory
,
devopsClient
devops
.
Interface
,
sonarqubeClient
sonarqube
.
SonarInterface
,
ksClient
versioned
.
Interface
,
s3Client
s3
.
Interface
,
endpoint
string
,
amInterface
am
.
AccessManagementInterface
)
error
{
ws
:=
runtime
.
NewWebService
(
GroupVersion
)
ws
:=
runtime
.
NewWebService
(
GroupVersion
)
err
:=
AddPipelineToWebService
(
ws
,
devopsClient
,
amInterface
)
err
:=
AddPipelineToWebService
(
ws
,
devopsClient
,
ksInformers
,
amInterface
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -75,12 +75,12 @@ func AddToContainer(container *restful.Container, ksInformers externalversions.S
...
@@ -75,12 +75,12 @@ func AddToContainer(container *restful.Container, ksInformers externalversions.S
return
nil
return
nil
}
}
func
AddPipelineToWebService
(
webservice
*
restful
.
WebService
,
devopsClient
devops
.
Interface
,
amInterface
am
.
AccessManagementInterface
)
error
{
func
AddPipelineToWebService
(
webservice
*
restful
.
WebService
,
devopsClient
devops
.
Interface
,
ksInformers
externalversions
.
SharedInformerFactory
,
amInterface
am
.
AccessManagementInterface
)
error
{
projectPipelineEnable
:=
devopsClient
!=
nil
projectPipelineEnable
:=
devopsClient
!=
nil
if
projectPipelineEnable
{
if
projectPipelineEnable
{
projectPipelineHandler
:=
NewProjectPipelineHandler
(
devopsClient
,
amInterface
)
projectPipelineHandler
:=
NewProjectPipelineHandler
(
devopsClient
,
ksInformers
,
amInterface
)
webservice
.
Route
(
webservice
.
GET
(
"/devops/{devops}/credentials/{credential}/usage"
)
.
webservice
.
Route
(
webservice
.
GET
(
"/devops/{devops}/credentials/{credential}/usage"
)
.
To
(
projectPipelineHandler
.
GetProjectCredentialUsage
)
.
To
(
projectPipelineHandler
.
GetProjectCredentialUsage
)
.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录