Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
b74d5a33
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看板
未验证
提交
b74d5a33
编写于
8月 01, 2020
作者:
K
KubeSphere CI Bot
提交者:
GitHub
8月 01, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2729 from shaowenchen/add_query_parameter_for_devops_credential
add query parameter for devops credential
上级
2dd0efb0
b82dc56e
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
43 addition
and
22 deletion
+43
-22
pkg/kapis/devops/v1alpha3/handler.go
pkg/kapis/devops/v1alpha3/handler.go
+3
-3
pkg/kapis/devops/v1alpha3/register.go
pkg/kapis/devops/v1alpha3/register.go
+6
-4
pkg/models/devops/devops.go
pkg/models/devops/devops.go
+34
-15
未找到文件。
pkg/kapis/devops/v1alpha3/handler.go
浏览文件 @
b74d5a33
...
...
@@ -25,6 +25,7 @@ import (
"k8s.io/klog"
"kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3"
"kubesphere.io/kubesphere/pkg/apiserver/query"
kubesphere
"kubesphere.io/kubesphere/pkg/client/clientset/versioned"
"kubesphere.io/kubesphere/pkg/client/informers/externalversions"
"kubesphere.io/kubesphere/pkg/models/devops"
...
...
@@ -291,9 +292,8 @@ func (h *devopsHandler) GetCredential(request *restful.Request, response *restfu
func
(
h
*
devopsHandler
)
ListCredential
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
devops
:=
request
.
PathParameter
(
"devops"
)
limit
,
offset
:=
params
.
ParsePaging
(
request
)
objs
,
err
:=
h
.
devops
.
ListCredentialObj
(
devops
,
limit
,
offset
)
query
:=
query
.
ParseQueryParameter
(
request
)
objs
,
err
:=
h
.
devops
.
ListCredentialObj
(
devops
,
query
)
if
err
!=
nil
{
klog
.
Error
(
err
)
...
...
pkg/kapis/devops/v1alpha3/register.go
浏览文件 @
b74d5a33
...
...
@@ -27,6 +27,7 @@ import (
"k8s.io/client-go/kubernetes"
"kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3"
"kubesphere.io/kubesphere/pkg/apiserver/query"
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
kubesphere
"kubesphere.io/kubesphere/pkg/client/clientset/versioned"
"kubesphere.io/kubesphere/pkg/client/informers/externalversions"
...
...
@@ -55,10 +56,11 @@ func AddToContainer(container *restful.Container, devopsClient devopsClient.Inte
ws
.
Route
(
ws
.
GET
(
"/devops/{devops}/credentials"
)
.
To
(
handler
.
ListCredential
)
.
Param
(
ws
.
PathParameter
(
"devops"
,
"devops name"
))
.
Param
(
ws
.
QueryParameter
(
params
.
PagingParam
,
"paging query, e.g. limit=100,page=1"
)
.
Required
(
false
)
.
DataFormat
(
"limit=%d,page=%d"
)
.
DefaultValue
(
"limit=10,page=1"
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterName
,
"name used to do filtering"
)
.
Required
(
false
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterPage
,
"page"
)
.
Required
(
false
)
.
DataFormat
(
"page=%d"
)
.
DefaultValue
(
"page=1"
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterLimit
,
"limit"
)
.
Required
(
false
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterAscending
,
"sort parameters, e.g. ascending=false"
)
.
Required
(
false
)
.
DefaultValue
(
"ascending=false"
))
.
Param
(
ws
.
QueryParameter
(
query
.
ParameterOrderBy
,
"sort parameters, e.g. orderBy=createTime"
))
.
Doc
(
"list the credentials of the specified devops for the current user"
)
.
Returns
(
http
.
StatusOK
,
api
.
StatusOK
,
api
.
ListResult
{
Items
:
[]
interface
{}{}})
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
[]
string
{
constants
.
DevOpsProjectTag
}))
...
...
pkg/models/devops/devops.go
浏览文件 @
b74d5a33
...
...
@@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
...
...
@@ -34,8 +35,10 @@ import (
"kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3"
devopsv1alpha3
"kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3"
tenantv1alpha1
"kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1"
"kubesphere.io/kubesphere/pkg/apiserver/query"
kubesphere
"kubesphere.io/kubesphere/pkg/client/clientset/versioned"
"kubesphere.io/kubesphere/pkg/client/informers/externalversions"
resourcesV1alpha3
"kubesphere.io/kubesphere/pkg/models/resources/v1alpha3"
"kubesphere.io/kubesphere/pkg/simple/client/devops"
"net/http"
"sync"
...
...
@@ -62,7 +65,7 @@ type DevopsOperator interface {
GetCredentialObj
(
projectName
string
,
secretName
string
)
(
*
v1
.
Secret
,
error
)
DeleteCredentialObj
(
projectName
string
,
secretName
string
)
error
UpdateCredentialObj
(
projectName
string
,
secret
*
v1
.
Secret
)
(
*
v1
.
Secret
,
error
)
ListCredentialObj
(
projectName
string
,
limit
,
offset
int
)
(
api
.
ListResult
,
error
)
ListCredentialObj
(
projectName
string
,
query
*
query
.
Query
)
(
api
.
ListResult
,
error
)
GetPipeline
(
projectName
,
pipelineName
string
,
req
*
http
.
Request
)
(
*
devops
.
Pipeline
,
error
)
ListPipelines
(
req
*
http
.
Request
)
(
*
devops
.
PipelineList
,
error
)
...
...
@@ -301,19 +304,16 @@ func (d devopsOperator) UpdateCredentialObj(projectName string, secret *v1.Secre
return
d
.
k8sclient
.
CoreV1
()
.
Secrets
(
projectObj
.
Status
.
AdminNamespace
)
.
Update
(
secret
)
}
func
(
d
devopsOperator
)
ListCredentialObj
(
projectName
string
,
limit
,
offset
int
)
(
api
.
ListResult
,
error
)
{
func
(
d
devopsOperator
)
ListCredentialObj
(
projectName
string
,
query
*
query
.
Query
)
(
api
.
ListResult
,
error
)
{
projectObj
,
err
:=
d
.
ksInformers
.
Devops
()
.
V1alpha3
()
.
DevOpsProjects
()
.
Lister
()
.
Get
(
projectName
)
if
err
!=
nil
{
return
api
.
ListResult
{},
err
}
credentialList
,
err
:=
d
.
k8sInformers
.
Core
()
.
V1
()
.
Secrets
()
.
Lister
()
.
Secrets
(
projectObj
.
Status
.
AdminNamespace
)
.
List
(
labels
.
Everything
())
credentialObjList
,
err
:=
d
.
k8sInformers
.
Core
()
.
V1
()
.
Secrets
()
.
Lister
()
.
Secrets
(
projectObj
.
Status
.
AdminNamespace
)
.
List
(
query
.
Selector
())
if
err
!=
nil
{
return
api
.
ListResult
{},
err
}
items
:=
make
([]
interface
{},
0
)
var
result
[]
interface
{}
var
result
[]
runtime
.
Object
credentialTypeList
:=
[]
v1
.
SecretType
{
v1alpha3
.
SecretTypeBasicAuth
,
...
...
@@ -321,22 +321,41 @@ func (d devopsOperator) ListCredentialObj(projectName string, limit, offset int)
v1alpha3
.
SecretTypeSecretText
,
v1alpha3
.
SecretTypeKubeConfig
,
}
for
_
,
credential
:=
range
credentialList
{
for
_
,
credential
:=
range
credential
Obj
List
{
for
_
,
credentialType
:=
range
credentialTypeList
{
if
credential
.
Type
==
credentialType
{
result
=
append
(
result
,
*
credential
)
result
=
append
(
result
,
credential
)
}
}
}
if
limit
==
-
1
||
limit
+
offset
>
len
(
result
)
{
limit
=
len
(
result
)
-
offset
return
*
resourcesV1alpha3
.
DefaultList
(
result
,
query
,
d
.
compareCredentialObj
,
d
.
filterCredentialObj
),
nil
}
func
(
d
devopsOperator
)
compareCredentialObj
(
left
runtime
.
Object
,
right
runtime
.
Object
,
field
query
.
Field
)
bool
{
leftObj
,
ok
:=
left
.
(
*
v1
.
Secret
)
if
!
ok
{
return
false
}
items
=
result
[
offset
:
offset
+
limit
]
if
items
==
nil
{
items
=
[]
interface
{}{}
rightObj
,
ok
:=
right
.
(
*
v1
.
Secret
)
if
!
ok
{
return
false
}
return
api
.
ListResult
{
TotalItems
:
len
(
result
),
Items
:
items
},
nil
return
resourcesV1alpha3
.
DefaultObjectMetaCompare
(
leftObj
.
ObjectMeta
,
rightObj
.
ObjectMeta
,
field
)
}
func
(
d
devopsOperator
)
filterCredentialObj
(
object
runtime
.
Object
,
filter
query
.
Filter
)
bool
{
secret
,
ok
:=
object
.
(
*
v1
.
Secret
)
if
!
ok
{
return
false
}
return
resourcesV1alpha3
.
DefaultObjectMetaFilter
(
secret
.
ObjectMeta
,
filter
)
}
// others
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录