mirror of
https://dev.azure.com/schwarzit/schwarzit.stackit-public/_git/audit-go
synced 2026-02-14 11:57:24 +00:00
Simplify logging of cloud events
This commit is contained in:
parent
f8f0b48437
commit
0caeabedbd
1 changed files with 21 additions and 8 deletions
|
|
@ -3,18 +3,31 @@ package api
|
||||||
import (
|
import (
|
||||||
auditV1 "dev.azure.com/schwarzit/schwarzit.stackit-core-platform/audit-go.git/gen/go/audit/v1"
|
auditV1 "dev.azure.com/schwarzit/schwarzit.stackit-core-platform/audit-go.git/gen/go/audit/v1"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"google.golang.org/protobuf/encoding/protojson"
|
"google.golang.org/protobuf/encoding/protojson"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LogEvent logs an event to the terminal
|
// LogEvent logs an event to the terminal
|
||||||
func LogEvent(
|
func LogEvent(event *CloudEvent) error {
|
||||||
event *CloudEvent,
|
|
||||||
auditEvent *auditV1.AuditLogEntry,
|
if event.DataType != "audit.v1.RoutableAuditEvent" {
|
||||||
routableIdentifier *RoutableIdentifier,
|
return errors.New("Unsupported data type " + event.DataType)
|
||||||
visibility auditV1.Visibility,
|
}
|
||||||
) error {
|
|
||||||
|
var routableAuditEvent *auditV1.RoutableAuditEvent
|
||||||
|
err := proto.Unmarshal(event.Data, routableAuditEvent)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var auditEvent *auditV1.AuditLogEntry
|
||||||
|
err = proto.Unmarshal(routableAuditEvent.GetUnencryptedData().Data, auditEvent)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Convert to json
|
// Convert to json
|
||||||
auditEventJson, err := protojson.Marshal(auditEvent)
|
auditEventJson, err := protojson.Marshal(auditEvent)
|
||||||
|
|
@ -27,7 +40,7 @@ func LogEvent(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
objectIdentifierJson, err := protojson.Marshal(routableIdentifier.ToObjectIdentifier())
|
objectIdentifierJson, err := protojson.Marshal(routableAuditEvent.ObjectIdentifier)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -47,7 +60,7 @@ func LogEvent(
|
||||||
Subject: event.Subject,
|
Subject: event.Subject,
|
||||||
Data: routableEvent{
|
Data: routableEvent{
|
||||||
OperationName: auditEvent.ProtoPayload.OperationName,
|
OperationName: auditEvent.ProtoPayload.OperationName,
|
||||||
Visibility: visibility.String(),
|
Visibility: routableAuditEvent.Visibility.String(),
|
||||||
ResourceReference: objectIdentifierMap,
|
ResourceReference: objectIdentifierMap,
|
||||||
Data: auditEventMap,
|
Data: auditEventMap,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue