Skip to content

Commit 0dc4fb3

Browse files
fix anonymous subject (#161)
1 parent bbc3ca8 commit 0dc4fb3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

internal/audit/audit_event.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"go.uber.org/zap"
88
"google.golang.org/protobuf/encoding/protojson"
99
"google.golang.org/protobuf/proto"
10-
"strings"
1110
"time"
1211
"ydbcp/internal/server/grpcinfo"
1312
"ydbcp/internal/util/xlog"
@@ -84,7 +83,7 @@ func (e *Event) MarshalJSON() ([]byte, error) {
8483
Component: e.Component,
8584
MethodName: e.MethodName,
8685
ContainerID: e.ContainerID,
87-
Subject: strings.Join([]string{e.Subject, "as"}, "@"),
86+
Subject: formatSubject(e.Subject),
8887
SanitizedToken: e.SanitizedToken,
8988
GRPCRequest: marshalProtoMessage(e.GRPCRequest),
9089
Status: e.Status,
@@ -130,6 +129,15 @@ func getStatus(inProgress bool, err error) (string, string) {
130129
return status, reason
131130
}
132131

132+
func formatSubject(subject string) string {
133+
switch subject {
134+
case "", "{none}":
135+
return "{none}"
136+
default:
137+
return subject + "@as"
138+
}
139+
}
140+
133141
func GRPCCallAuditEvent(
134142
ctx context.Context,
135143
methodName string,

0 commit comments

Comments
 (0)