Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
KubeCube
Commits
182540fb
Commit
182540fb
authored
3 years ago
by
赵嘉慧
Committed by
zhujf1989
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
fix audit event name
parent
aeb5622a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/apiserver/middlewares/audit/audit.go
+3
-3
pkg/apiserver/middlewares/audit/audit.go
pkg/apiserver/middlewares/audit/audit_test.go
+5
-14
pkg/apiserver/middlewares/audit/audit_test.go
with
8 additions
and
17 deletions
+8
-17
pkg/apiserver/middlewares/audit/audit.go
+
3
-
3
View file @
182540fb
...
...
@@ -221,11 +221,11 @@ func getEventName(c *gin.Context, e Event) *Event {
break
}
}
e
.
EventName
=
methodStr
+
objectType
objectType
=
objectType
[
:
len
(
objectType
)
-
1
]
e
.
EventName
=
methodStr
+
strings
.
Title
(
objectType
)
e
.
Description
=
e
.
Description
+
audit
.
ResourceType
[
objectType
]
e
.
ResourceReports
=
[]
Resource
{{
ResourceType
:
objectType
[
:
len
(
objectType
)
-
1
]
,
ResourceType
:
objectType
,
ResourceName
:
objectName
,
}}
return
&
e
...
...
This diff is collapsed.
Click to expand it.
pkg/apiserver/middlewares/audit/audit_test.go
+
5
-
14
View file @
182540fb
...
...
@@ -69,36 +69,27 @@ func TestSendEvent(t *testing.T) {
}
func
TestGetEventName
(
t
*
testing
.
T
)
{
// check post method
e
:=
&
Event
{}
router
:=
gin
.
New
()
// check get method
router
.
GET
(
"/api/v1/cube/proxy/clusters/:cluster/apis/apps/v1/namespaces/:namespace/statefulsets/:name"
,
func
(
c
*
gin
.
Context
)
{
e
=
getEventName
(
c
,
*
e
)
return
})
_
=
performRequest
(
router
,
http
.
MethodGet
,
"/api/v1/cube/proxy/clusters/pivot-cluster/apis/apps/v1/namespaces/dev/statefulsets/stsA"
,
[]
byte
(
""
))
if
e
.
EventName
!=
"[KubeCube] query statefulsets"
{
t
.
Fail
()
}
// check post method
router
.
POST
(
"/api/v1/cube/proxy/clusters/:cluster/api/v1/namespaces/:namespace/services"
,
func
(
c
*
gin
.
Context
)
{
e
=
getEventName
(
c
,
*
e
)
return
})
_
=
performRequest
(
router
,
http
.
MethodPost
,
"/api/v1/cube/proxy/clusters/pivot-cluster/api/v1/namespaces/dev/services"
,
[]
byte
(
""
))
if
e
.
EventName
!=
"
[KubeCube]
create
s
ervice
s
"
{
if
e
.
EventName
!=
"create
S
ervice"
{
t
.
Fail
()
}
// check put method
e
=
&
Event
{}
router
=
gin
.
New
()
router
.
PUT
(
"/api/v1/cube/proxy/clusters/:cluster/api/v1/namespaces/:namespace/secrets/:name"
,
func
(
c
*
gin
.
Context
)
{
e
=
getEventName
(
c
,
*
e
)
return
})
_
=
performRequest
(
router
,
http
.
MethodPut
,
"/api/v1/cube/proxy/clusters/pivot-cluster/api/v1/namespaces/dev/secrets/secretA"
,
[]
byte
(
""
))
if
e
.
EventName
!=
"
[KubeCube]
update
s
ecret
s
"
{
if
e
.
EventName
!=
"update
S
ecret"
{
t
.
Fail
()
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help