提交 37346150 编写于 作者: W wanjunlei

resolve conversation

上级 7393ef91
......@@ -112,24 +112,18 @@ func (b *Backend) worker() {
func (b *Backend) eventToBytes(event *v1alpha1.EventList) ([]byte, error) {
if bs, err := json.Marshal(event); err == nil {
return bs, nil
}
// Normally, the serialization failure is caused by the failure of RequestObject or ResponseObject serialization.
// To ensure the integrity of the auditing event to the greatest extent,
// it is necessary to delete RequestObject or ResponseObject and and then try to serialize again.
if event.Items[0].RequestObject != nil {
if _, err := json.Marshal(event.Items[0].RequestObject); err != nil {
event.Items[0].RequestObject = nil
}
}
if event.Items[0].ResponseObject != nil {
if _, err := json.Marshal(event.Items[0].ResponseObject); err != nil {
bs, err := json.Marshal(event)
if err != nil {
// Normally, the serialization failure is caused by the failure of ResponseObject serialization.
// To ensure the integrity of the auditing event to the greatest extent,
// it is necessary to delete ResponseObject and and then try to serialize again.
if event.Items[0].ResponseObject != nil {
event.Items[0].ResponseObject = nil
return json.Marshal(event)
}
return nil, err
}
return json.Marshal(event)
return bs, err
}
......@@ -20,7 +20,6 @@ import (
"github.com/emicklei/go-restful"
log "k8s.io/klog"
"kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/apiserver/request"
"kubesphere.io/kubesphere/pkg/models/devops"
"net/http"
"strings"
......@@ -93,12 +92,6 @@ func (h *ProjectPipelineHandler) StopPipeline(req *restful.Request, resp *restfu
return
}
if event := request.AuditEventFrom(req.Request.Context()); event != nil {
event.ObjectRef.Resource = "pipelines.runs"
event.ObjectRef.Name = pipelineName + "." + runId
event.Verb = "stop"
}
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.WriteAsJson(res)
}
......@@ -114,12 +107,6 @@ func (h *ProjectPipelineHandler) ReplayPipeline(req *restful.Request, resp *rest
return
}
if event := request.AuditEventFrom(req.Request.Context()); event != nil {
event.ObjectRef.Resource = "pipelines.runs"
event.ObjectRef.Name = pipelineName + "." + runId
event.Verb = "replay"
}
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.WriteAsJson(res)
}
......@@ -134,11 +121,6 @@ func (h *ProjectPipelineHandler) RunPipeline(req *restful.Request, resp *restful
return
}
if event := request.AuditEventFrom(req.Request.Context()); event != nil {
event.ObjectRef.Resource = "pipelines.runs"
event.ObjectRef.Name = pipelineName + "." + res.ID
}
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.WriteAsJson(res)
}
......@@ -233,11 +215,6 @@ func (h *ProjectPipelineHandler) SubmitInputStep(req *restful.Request, resp *res
return
}
if event := request.AuditEventFrom(req.Request.Context()); event != nil {
event.ObjectRef.Resource = "pipelines.runs.nodes.step"
event.ObjectRef.Name = pipelineName + "." + runId + "." + nodeId + "." + stepId
}
resp.Write(res)
}
......@@ -297,12 +274,6 @@ func (h *ProjectPipelineHandler) StopBranchPipeline(req *restful.Request, resp *
return
}
if event := request.AuditEventFrom(req.Request.Context()); event != nil {
event.ObjectRef.Resource = "pipelines.branches.runs"
event.ObjectRef.Name = pipelineName + "." + branchName + "." + runId
event.Verb = "stop"
}
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.WriteAsJson(res)
}
......@@ -319,12 +290,6 @@ func (h *ProjectPipelineHandler) ReplayBranchPipeline(req *restful.Request, resp
return
}
if event := request.AuditEventFrom(req.Request.Context()); event != nil {
event.ObjectRef.Resource = "pipelines.branches.runs"
event.ObjectRef.Name = pipelineName + "." + branchName + "." + runId
event.Verb = "replay"
}
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.WriteAsJson(res)
}
......@@ -340,11 +305,6 @@ func (h *ProjectPipelineHandler) RunBranchPipeline(req *restful.Request, resp *r
return
}
if event := request.AuditEventFrom(req.Request.Context()); event != nil {
event.ObjectRef.Resource = "pipelines.branches.runs"
event.ObjectRef.Name = pipelineName + "." + branchName + "." + res.ID
}
resp.Header().Set(restful.HEADER_ContentType, restful.MIME_JSON)
resp.WriteAsJson(res)
}
......@@ -447,11 +407,6 @@ func (h *ProjectPipelineHandler) SubmitBranchInputStep(req *restful.Request, res
return
}
if event := request.AuditEventFrom(req.Request.Context()); event != nil {
event.ObjectRef.Resource = "pipelines.branches.runs.nodes.steps"
event.ObjectRef.Name = pipelineName + "." + branchName + "." + runId + "." + nodeId + "." + stepId
}
resp.Write(res)
}
......
......@@ -10,7 +10,6 @@ import (
iamv1alpha2 "kubesphere.io/kubesphere/pkg/apis/iam/v1alpha2"
authoptions "kubesphere.io/kubesphere/pkg/apiserver/authentication/options"
"kubesphere.io/kubesphere/pkg/apiserver/query"
requestinfo "kubesphere.io/kubesphere/pkg/apiserver/request"
"kubesphere.io/kubesphere/pkg/models/iam/am"
"kubesphere.io/kubesphere/pkg/models/iam/im"
servererr "kubesphere.io/kubesphere/pkg/server/errors"
......@@ -822,14 +821,6 @@ func (h *iamHandler) CreateWorkspaceMembers(request *restful.Request, response *
}
}
if event := requestinfo.AuditEventFrom(request.Request.Context()); event != nil {
name := ""
for _, member := range members {
name += member.Username + ", "
}
name = strings.TrimSuffix(name, ", ")
event.ObjectRef.Name = name
}
response.WriteEntity(members)
}
......@@ -908,14 +899,6 @@ func (h *iamHandler) CreateNamespaceMembers(request *restful.Request, response *
}
}
if event := requestinfo.AuditEventFrom(request.Request.Context()); event != nil {
name := ""
for _, member := range members {
name += member.Username + ", "
}
name = strings.TrimSuffix(name, ", ")
event.ObjectRef.Name = name
}
response.WriteEntity(members)
}
......@@ -997,14 +980,6 @@ func (h *iamHandler) CreateClusterMembers(request *restful.Request, response *re
}
}
if event := requestinfo.AuditEventFrom(request.Request.Context()); event != nil {
name := ""
for _, member := range members {
name += member.Username + ", "
}
name = strings.TrimSuffix(name, ", ")
event.ObjectRef.Name = name
}
response.WriteEntity(members)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册