@@ -28,17 +28,27 @@ import (
2828
2929var grpcLogger = grpclog .Component ("authz-audit" )
3030
31+ type StdoutEvent struct {
32+ FullMethodName string `json:"fullMethodName"`
33+ Principal string `json:"principal"`
34+ PolicyName string `json:"policyName"`
35+ MatchedRule string `json:"matchedRule"`
36+ Authorized bool `json:"authorized"`
37+ //Timestamp is populated using time.Now() during StdoutLogger.Log call
38+ Timestamp string `json:"timestamp"`
39+ }
40+
3141type StdOutLogger struct {
3242}
3343
3444func (logger * StdOutLogger ) Log (event * Event ) {
35- jsonBytes , err := json .Marshal (event )
45+ jsonBytes , err := json .Marshal (convertEvent ( event )) //internal structure mimicking event with annotations how to marshall to json
3646 if err != nil {
3747 grpcLogger .Errorf ("failed to marshal AuditEvent data to JSON: %v" , err )
3848 }
39- message := fmt .Sprintf ("[AuthZ Audit StdOutLogger] %s %v" ,
40- time .Now ().Format (time .RFC3339 ), string (jsonBytes ))
41- fmt .Println (message )
49+ // message := fmt.Sprintf("[AuthZ Audit StdOutLogger] %s %v",
50+ // time.Now().Format(time.RFC3339), string(jsonBytes))
51+ fmt .Println (string ( jsonBytes )) // built in log.go
4252}
4353
4454const (
@@ -64,3 +74,14 @@ func (StdOutLoggerBuilder) ParseLoggerConfig(config json.RawMessage) (LoggerConf
6474 "StdOutLogger doesn't support custom configs" , string (config ))
6575 return & StdoutLoggerConfig {}, nil
6676}
77+
78+ func convertEvent (event * Event ) StdoutEvent {
79+ return StdoutEvent {
80+ FullMethodName : event .FullMethodName ,
81+ Principal : event .Principal ,
82+ PolicyName : event .PolicyName ,
83+ MatchedRule : event .MatchedRule ,
84+ Authorized : event .Authorized ,
85+ Timestamp : time .Now ().Format (time .RFC3339 ),
86+ }
87+ }
0 commit comments