Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
13ffbe89
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看板
未验证
提交
13ffbe89
编写于
7月 30, 2020
作者:
H
hongming
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix tenant resource list API
Signed-off-by:
N
hongming
<
talonwan@yunify.com
>
上级
b71ce477
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
52 addition
and
24 deletion
+52
-24
pkg/kapis/tenant/v1alpha2/handler.go
pkg/kapis/tenant/v1alpha2/handler.go
+36
-24
pkg/kapis/tenant/v1alpha2/register.go
pkg/kapis/tenant/v1alpha2/register.go
+16
-0
未找到文件。
pkg/kapis/tenant/v1alpha2/handler.go
浏览文件 @
13ffbe89
...
...
@@ -5,6 +5,7 @@ import (
"github.com/emicklei/go-restful"
corev1
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/client-go/kubernetes"
"k8s.io/klog"
"kubesphere.io/kubesphere/pkg/api"
...
...
@@ -56,9 +57,10 @@ func (h *tenantHandler) ListWorkspaces(req *restful.Request, resp *restful.Respo
}
func
(
h
*
tenantHandler
)
ListFederatedNamespaces
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
user
,
ok
:=
request
.
UserFrom
(
req
.
Request
.
Context
()
)
workspace
:=
req
.
PathParameter
(
"workspace"
)
queryParam
:=
query
.
ParseQueryParameter
(
req
)
workspaceMember
,
ok
:=
request
.
UserFrom
(
req
.
Request
.
Context
())
if
!
ok
{
err
:=
fmt
.
Errorf
(
"cannot obtain user info"
)
klog
.
Errorln
(
err
)
...
...
@@ -66,10 +68,7 @@ func (h *tenantHandler) ListFederatedNamespaces(req *restful.Request, resp *rest
return
}
workspace
:=
req
.
PathParameter
(
"workspace"
)
result
,
err
:=
h
.
tenant
.
ListFederatedNamespaces
(
user
,
workspace
,
queryParam
)
result
,
err
:=
h
.
tenant
.
ListFederatedNamespaces
(
workspaceMember
,
workspace
,
queryParam
)
if
err
!=
nil
{
api
.
HandleInternalError
(
resp
,
nil
,
err
)
return
...
...
@@ -79,20 +78,26 @@ func (h *tenantHandler) ListFederatedNamespaces(req *restful.Request, resp *rest
}
func
(
h
*
tenantHandler
)
ListNamespaces
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
user
,
ok
:=
request
.
UserFrom
(
req
.
Request
.
Context
()
)
workspace
:=
req
.
PathParameter
(
"workspace"
)
queryParam
:=
query
.
ParseQueryParameter
(
req
)
if
!
ok
{
err
:=
fmt
.
Errorf
(
"cannot obtain user info"
)
klog
.
Errorln
(
err
)
api
.
HandleForbidden
(
resp
,
nil
,
err
)
return
var
workspaceMember
user
.
Info
if
username
:=
req
.
PathParameter
(
"workspacemember"
);
username
!=
""
{
workspaceMember
=
&
user
.
DefaultInfo
{
Name
:
username
,
}
}
else
{
requestUser
,
ok
:=
request
.
UserFrom
(
req
.
Request
.
Context
())
if
!
ok
{
err
:=
fmt
.
Errorf
(
"cannot obtain user info"
)
klog
.
Errorln
(
err
)
api
.
HandleForbidden
(
resp
,
nil
,
err
)
return
}
workspaceMember
=
requestUser
}
workspace
:=
req
.
PathParameter
(
"workspace"
)
result
,
err
:=
h
.
tenant
.
ListNamespaces
(
user
,
workspace
,
queryParam
)
result
,
err
:=
h
.
tenant
.
ListNamespaces
(
workspaceMember
,
workspace
,
queryParam
)
if
err
!=
nil
{
api
.
HandleInternalError
(
resp
,
nil
,
err
)
return
...
...
@@ -102,19 +107,26 @@ func (h *tenantHandler) ListNamespaces(req *restful.Request, resp *restful.Respo
}
func
(
h
*
tenantHandler
)
ListDevOpsProjects
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
user
,
ok
:=
request
.
UserFrom
(
req
.
Request
.
Context
()
)
workspace
:=
req
.
PathParameter
(
"workspace"
)
queryParam
:=
query
.
ParseQueryParameter
(
req
)
if
!
ok
{
err
:=
fmt
.
Errorf
(
"cannot obtain user info"
)
klog
.
Errorln
(
err
)
api
.
HandleForbidden
(
resp
,
nil
,
err
)
return
var
workspaceMember
user
.
Info
if
username
:=
req
.
PathParameter
(
"workspacemember"
);
username
!=
""
{
workspaceMember
=
&
user
.
DefaultInfo
{
Name
:
username
,
}
}
else
{
requestUser
,
ok
:=
request
.
UserFrom
(
req
.
Request
.
Context
())
if
!
ok
{
err
:=
fmt
.
Errorf
(
"cannot obtain user info"
)
klog
.
Errorln
(
err
)
api
.
HandleForbidden
(
resp
,
nil
,
err
)
return
}
workspaceMember
=
requestUser
}
workspace
:=
req
.
PathParameter
(
"workspace"
)
result
,
err
:=
h
.
tenant
.
ListDevOpsProjects
(
user
,
workspace
,
queryParam
)
result
,
err
:=
h
.
tenant
.
ListDevOpsProjects
(
workspaceMember
,
workspace
,
queryParam
)
if
err
!=
nil
{
api
.
HandleInternalError
(
resp
,
nil
,
err
)
...
...
pkg/kapis/tenant/v1alpha2/register.go
浏览文件 @
13ffbe89
...
...
@@ -130,6 +130,14 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, k8s
Doc
(
"List the devops projects of the specified workspace for the current user"
)
.
Returns
(
http
.
StatusOK
,
api
.
StatusOK
,
api
.
ListResult
{})
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
[]
string
{
constants
.
TenantResourcesTag
}))
ws
.
Route
(
ws
.
GET
(
"/workspaces/{workspace}/workspacemembers/{workspacemember}/devops"
)
.
To
(
handler
.
ListDevOpsProjects
)
.
Param
(
ws
.
PathParameter
(
"workspace"
,
"workspace name"
))
.
Param
(
ws
.
PathParameter
(
"workspacemember"
,
"workspacemember username"
))
.
Doc
(
"List the devops projects of specified workspace for the workspace member"
)
.
Reads
(
corev1
.
Namespace
{})
.
Returns
(
http
.
StatusOK
,
api
.
StatusOK
,
corev1
.
Namespace
{})
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
[]
string
{
constants
.
TenantResourcesTag
}))
ws
.
Route
(
ws
.
GET
(
"/workspaces/{workspace}/namespaces/{namespace}"
)
.
To
(
handler
.
DescribeNamespace
)
.
Param
(
ws
.
PathParameter
(
"workspace"
,
"workspace name"
))
.
...
...
@@ -149,6 +157,14 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, k8s
Reads
(
corev1
.
Namespace
{})
.
Returns
(
http
.
StatusOK
,
api
.
StatusOK
,
corev1
.
Namespace
{})
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
[]
string
{
constants
.
TenantResourcesTag
}))
ws
.
Route
(
ws
.
GET
(
"/workspaces/{workspace}/workspacemembers/{workspacemember}/namespaces"
)
.
To
(
handler
.
ListNamespaces
)
.
Param
(
ws
.
PathParameter
(
"workspace"
,
"workspace name"
))
.
Param
(
ws
.
PathParameter
(
"workspacemember"
,
"workspacemember username"
))
.
Doc
(
"List the namespaces of the specified workspace for the workspace member"
)
.
Reads
(
corev1
.
Namespace
{})
.
Returns
(
http
.
StatusOK
,
api
.
StatusOK
,
corev1
.
Namespace
{})
.
Metadata
(
restfulspec
.
KeyOpenAPITags
,
[]
string
{
constants
.
TenantResourcesTag
}))
ws
.
Route
(
ws
.
PUT
(
"/workspaces/{workspace}/namespaces/{namespace}"
)
.
To
(
handler
.
UpdateNamespace
)
.
Param
(
ws
.
PathParameter
(
"workspace"
,
"workspace name"
))
.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录