Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
b5392b97
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看板
提交
b5392b97
编写于
7月 28, 2020
作者:
W
wanjunlei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add ns and ws query parameter to es query body
Signed-off-by:
N
wanjunlei
<
wanjunlei@yunify.com
>
上级
b51a5c22
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
73 addition
and
35 deletion
+73
-35
pkg/models/auditing/events.go
pkg/models/auditing/events.go
+20
-16
pkg/models/tenant/tenant.go
pkg/models/tenant/tenant.go
+1
-1
pkg/simple/client/auditing/elasticsearch/elasticsearch.go
pkg/simple/client/auditing/elasticsearch/elasticsearch.go
+32
-2
pkg/simple/client/auditing/interface.go
pkg/simple/client/auditing/interface.go
+20
-16
未找到文件。
pkg/models/auditing/events.go
浏览文件 @
b5392b97
...
...
@@ -38,19 +38,23 @@ func NewEventsOperator(client auditing.Client) Interface {
func
(
eo
*
eventsOperator
)
Events
(
queryParam
*
v1alpha1
.
Query
,
MutateFilterFunc
func
(
*
auditing
.
Filter
))
(
*
v1alpha1
.
APIResponse
,
error
)
{
filter
:=
&
auditing
.
Filter
{
ObjectRefNames
:
stringutils
.
Split
(
queryParam
.
ObjectRefNameFilter
,
","
),
ObjectRefNameFuzzy
:
stringutils
.
Split
(
queryParam
.
ObjectRefNameSearch
,
","
),
Levels
:
stringutils
.
Split
(
queryParam
.
LevelFilter
,
","
),
Verbs
:
stringutils
.
Split
(
queryParam
.
VerbFilter
,
","
),
Users
:
stringutils
.
Split
(
queryParam
.
UserFilter
,
","
),
UserFuzzy
:
stringutils
.
Split
(
queryParam
.
UserSearch
,
","
),
GroupFuzzy
:
stringutils
.
Split
(
queryParam
.
GroupSearch
,
","
),
SourceIpFuzzy
:
stringutils
.
Split
(
queryParam
.
SourceIpSearch
,
","
),
ObjectRefResources
:
stringutils
.
Split
(
queryParam
.
ObjectRefResourceFilter
,
","
),
ObjectRefSubresources
:
stringutils
.
Split
(
queryParam
.
ObjectRefSubresourceFilter
,
","
),
ResponseStatus
:
stringutils
.
Split
(
queryParam
.
ResponseStatusFilter
,
","
),
StartTime
:
queryParam
.
StartTime
,
EndTime
:
queryParam
.
EndTime
,
ObjectRefNamespaces
:
stringutils
.
Split
(
queryParam
.
ObjectRefNamespaceFilter
,
","
),
ObjectRefNamespaceFuzzy
:
stringutils
.
Split
(
queryParam
.
ObjectRefNamespaceSearch
,
","
),
Workspaces
:
stringutils
.
Split
(
queryParam
.
WorkspaceFilter
,
","
),
WorkspaceFuzzy
:
stringutils
.
Split
(
queryParam
.
WorkspaceSearch
,
","
),
ObjectRefNames
:
stringutils
.
Split
(
queryParam
.
ObjectRefNameFilter
,
","
),
ObjectRefNameFuzzy
:
stringutils
.
Split
(
queryParam
.
ObjectRefNameSearch
,
","
),
Levels
:
stringutils
.
Split
(
queryParam
.
LevelFilter
,
","
),
Verbs
:
stringutils
.
Split
(
queryParam
.
VerbFilter
,
","
),
Users
:
stringutils
.
Split
(
queryParam
.
UserFilter
,
","
),
UserFuzzy
:
stringutils
.
Split
(
queryParam
.
UserSearch
,
","
),
GroupFuzzy
:
stringutils
.
Split
(
queryParam
.
GroupSearch
,
","
),
SourceIpFuzzy
:
stringutils
.
Split
(
queryParam
.
SourceIpSearch
,
","
),
ObjectRefResources
:
stringutils
.
Split
(
queryParam
.
ObjectRefResourceFilter
,
","
),
ObjectRefSubresources
:
stringutils
.
Split
(
queryParam
.
ObjectRefSubresourceFilter
,
","
),
ResponseStatus
:
stringutils
.
Split
(
queryParam
.
ResponseStatusFilter
,
","
),
StartTime
:
queryParam
.
StartTime
,
EndTime
:
queryParam
.
EndTime
,
}
if
MutateFilterFunc
!=
nil
{
MutateFilterFunc
(
filter
)
...
...
@@ -70,19 +74,19 @@ func (eo *eventsOperator) Events(queryParam *v1alpha1.Query,
var
err
error
switch
queryParam
.
Operation
{
case
"histogram"
:
if
len
(
filter
.
ObjectRefNamespaceMap
)
==
0
&&
len
(
filter
.
ObjectRef
WorkspaceMap
)
==
0
{
if
len
(
filter
.
ObjectRefNamespaceMap
)
==
0
&&
len
(
filter
.
WorkspaceMap
)
==
0
{
ar
.
Histogram
=
&
auditing
.
Histogram
{}
}
else
{
ar
.
Histogram
,
err
=
eo
.
client
.
CountOverTime
(
filter
,
queryParam
.
Interval
)
}
case
"statistics"
:
if
len
(
filter
.
ObjectRefNamespaceMap
)
==
0
&&
len
(
filter
.
ObjectRef
WorkspaceMap
)
==
0
{
if
len
(
filter
.
ObjectRefNamespaceMap
)
==
0
&&
len
(
filter
.
WorkspaceMap
)
==
0
{
ar
.
Statistics
=
&
auditing
.
Statistics
{}
}
else
{
ar
.
Statistics
,
err
=
eo
.
client
.
StatisticsOnResources
(
filter
)
}
default
:
if
len
(
filter
.
ObjectRefNamespaceMap
)
==
0
&&
len
(
filter
.
ObjectRef
WorkspaceMap
)
==
0
{
if
len
(
filter
.
ObjectRefNamespaceMap
)
==
0
&&
len
(
filter
.
WorkspaceMap
)
==
0
{
ar
.
Events
=
&
auditing
.
Events
{}
}
else
{
ar
.
Events
,
err
=
eo
.
client
.
SearchAuditingEvent
(
filter
,
queryParam
.
From
,
queryParam
.
Size
,
queryParam
.
Sort
)
...
...
pkg/models/tenant/tenant.go
浏览文件 @
b5392b97
...
...
@@ -922,7 +922,7 @@ func (t *tenantOperator) Auditing(user user.Info, queryParam *auditingv1alpha1.Q
return
t
.
auditing
.
Events
(
queryParam
,
func
(
filter
*
auditingclient
.
Filter
)
{
filter
.
ObjectRefNamespaceMap
=
namespaceCreateTimeMap
filter
.
ObjectRef
WorkspaceMap
=
workspaceCreateTimeMap
filter
.
WorkspaceMap
=
workspaceCreateTimeMap
})
}
...
...
pkg/simple/client/auditing/elasticsearch/elasticsearch.go
浏览文件 @
b5392b97
...
...
@@ -305,7 +305,7 @@ func parseToQueryPart(f *auditing.Filter) interface{} {
"bool"
:
&
b
,
}
if
len
(
f
.
ObjectRefNamespaceMap
)
>
0
||
len
(
f
.
ObjectRef
WorkspaceMap
)
>
0
{
if
len
(
f
.
ObjectRefNamespaceMap
)
>
0
||
len
(
f
.
WorkspaceMap
)
>
0
{
bi
:=
BoolBody
{
MinimumShouldMatch
:
&
mini
}
for
k
,
v
:=
range
f
.
ObjectRefNamespaceMap
{
bi
.
Should
=
append
(
bi
.
Should
,
map
[
string
]
interface
{}{
...
...
@@ -323,7 +323,7 @@ func parseToQueryPart(f *auditing.Filter) interface{} {
})
}
for
k
,
v
:=
range
f
.
ObjectRef
WorkspaceMap
{
for
k
,
v
:=
range
f
.
WorkspaceMap
{
bi
.
Should
=
append
(
bi
.
Should
,
map
[
string
]
interface
{}{
"bool"
:
&
BoolBody
{
Filter
:
[]
map
[
string
]
interface
{}{{
...
...
@@ -360,6 +360,36 @@ func parseToQueryPart(f *auditing.Filter) interface{} {
return
&
bi
}
if
len
(
f
.
ObjectRefNamespaces
)
>
0
{
if
bi
:=
shouldBoolbody
(
"match_phrase_prefix"
,
"ObjectRef.Namespace.keyword"
,
f
.
ObjectRefNamespaces
,
nil
);
bi
!=
nil
{
b
.
Filter
=
append
(
b
.
Filter
,
map
[
string
]
interface
{}{
"bool"
:
bi
})
}
}
if
len
(
f
.
ObjectRefNamespaceFuzzy
)
>
0
{
if
bi
:=
shouldBoolbody
(
"wildcard"
,
"ObjectRef.Namespace"
,
f
.
ObjectRefNamespaceFuzzy
,
func
(
s
string
)
string
{
return
fmt
.
Sprintf
(
"*"
+
s
+
"*"
)
});
bi
!=
nil
{
b
.
Filter
=
append
(
b
.
Filter
,
map
[
string
]
interface
{}{
"bool"
:
bi
})
}
}
if
len
(
f
.
Workspaces
)
>
0
{
if
bi
:=
shouldBoolbody
(
"match_phrase_prefix"
,
"Workspace.keyword"
,
f
.
Workspaces
,
nil
);
bi
!=
nil
{
b
.
Filter
=
append
(
b
.
Filter
,
map
[
string
]
interface
{}{
"bool"
:
bi
})
}
}
if
len
(
f
.
WorkspaceFuzzy
)
>
0
{
if
bi
:=
shouldBoolbody
(
"wildcard"
,
"Workspace"
,
f
.
WorkspaceFuzzy
,
func
(
s
string
)
string
{
return
fmt
.
Sprintf
(
"*"
+
s
+
"*"
)
});
bi
!=
nil
{
b
.
Filter
=
append
(
b
.
Filter
,
map
[
string
]
interface
{}{
"bool"
:
bi
})
}
}
if
len
(
f
.
ObjectRefNames
)
>
0
{
if
bi
:=
shouldBoolbody
(
"match_phrase_prefix"
,
"ObjectRef.Name.keyword"
,
f
.
ObjectRefNames
,
nil
);
bi
!=
nil
{
...
...
pkg/simple/client/auditing/interface.go
浏览文件 @
b5392b97
...
...
@@ -27,22 +27,26 @@ type Client interface {
}
type
Filter
struct
{
ObjectRefNamespaceMap
map
[
string
]
time
.
Time
ObjectRefWorkspaceMap
map
[
string
]
time
.
Time
ObjectRefNames
[]
string
ObjectRefNameFuzzy
[]
string
Levels
[]
string
Verbs
[]
string
Users
[]
string
UserFuzzy
[]
string
GroupFuzzy
[]
string
SourceIpFuzzy
[]
string
ObjectRefResources
[]
string
ObjectRefSubresources
[]
string
ResponseCodes
[]
int32
ResponseStatus
[]
string
StartTime
*
time
.
Time
EndTime
*
time
.
Time
ObjectRefNamespaceMap
map
[
string
]
time
.
Time
WorkspaceMap
map
[
string
]
time
.
Time
ObjectRefNamespaces
[]
string
ObjectRefNamespaceFuzzy
[]
string
Workspaces
[]
string
WorkspaceFuzzy
[]
string
ObjectRefNames
[]
string
ObjectRefNameFuzzy
[]
string
Levels
[]
string
Verbs
[]
string
Users
[]
string
UserFuzzy
[]
string
GroupFuzzy
[]
string
SourceIpFuzzy
[]
string
ObjectRefResources
[]
string
ObjectRefSubresources
[]
string
ResponseCodes
[]
int32
ResponseStatus
[]
string
StartTime
*
time
.
Time
EndTime
*
time
.
Time
}
type
Event
map
[
string
]
interface
{}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录