mirror of
https://dev.azure.com/schwarzit/schwarzit.stackit-public/_git/audit-go
synced 2026-02-07 16:47: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 (
|
||||
auditV1 "dev.azure.com/schwarzit/schwarzit.stackit-core-platform/audit-go.git/gen/go/audit/v1"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"log/slog"
|
||||
"time"
|
||||
)
|
||||
|
||||
// LogEvent logs an event to the terminal
|
||||
func LogEvent(
|
||||
event *CloudEvent,
|
||||
auditEvent *auditV1.AuditLogEntry,
|
||||
routableIdentifier *RoutableIdentifier,
|
||||
visibility auditV1.Visibility,
|
||||
) error {
|
||||
func LogEvent(event *CloudEvent) error {
|
||||
|
||||
if event.DataType != "audit.v1.RoutableAuditEvent" {
|
||||
return errors.New("Unsupported data type " + event.DataType)
|
||||
}
|
||||
|
||||
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
|
||||
auditEventJson, err := protojson.Marshal(auditEvent)
|
||||
|
|
@ -27,7 +40,7 @@ func LogEvent(
|
|||
return err
|
||||
}
|
||||
|
||||
objectIdentifierJson, err := protojson.Marshal(routableIdentifier.ToObjectIdentifier())
|
||||
objectIdentifierJson, err := protojson.Marshal(routableAuditEvent.ObjectIdentifier)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -47,7 +60,7 @@ func LogEvent(
|
|||
Subject: event.Subject,
|
||||
Data: routableEvent{
|
||||
OperationName: auditEvent.ProtoPayload.OperationName,
|
||||
Visibility: visibility.String(),
|
||||
Visibility: routableAuditEvent.Visibility.String(),
|
||||
ResourceReference: objectIdentifierMap,
|
||||
Data: auditEventMap,
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue