Fix data and content-type in legacy apis

This commit is contained in:
Christian Schaible 2024-10-01 14:36:10 +02:00
parent 6fd141e227
commit 0e6aac7370
4 changed files with 8 additions and 7 deletions

View file

@ -16,6 +16,7 @@ import (
// ContentTypeCloudEventsProtobuf the cloudevents protobuf content-type sent in metadata of messages
const ContentTypeCloudEventsProtobuf = "application/cloudevents+protobuf"
const ContentTypeCloudEventsJson = "application/cloudevents+json; charset=UTF-8"
// ErrUnknownPluralType indicates that the given input is an unknown plural type
var ErrUnknownPluralType = errors.New("unknown plural type")

View file

@ -2,11 +2,9 @@ package api
import (
"context"
"errors"
"fmt"
"dev.azure.com/schwarzit/schwarzit.stackit-core-platform/audit-go.git/audit/messaging"
auditV1 "dev.azure.com/schwarzit/schwarzit.stackit-core-platform/audit-go.git/gen/go/audit/v1"
"errors"
"google.golang.org/protobuf/proto"
)
@ -136,8 +134,8 @@ func (a *LegacyAuditApi) ValidateAndSerializeWithTrace(
Source: event.ProtoPayload.ServiceName,
Id: event.InsertId,
Time: event.ProtoPayload.RequestMetadata.RequestAttributes.Time.AsTime(),
DataContentType: ContentTypeCloudEventsProtobuf,
DataType: fmt.Sprintf("%v", routableEvent.ProtoReflect().Descriptor().FullName()),
DataContentType: ContentTypeCloudEventsJson,
DataType: "audit.v1.LegacyAuditEvent",
Subject: event.ProtoPayload.ResourceName,
Data: legacyBytes,
TraceParent: traceParent,

View file

@ -119,8 +119,8 @@ func (a *DynamicLegacyAuditApi) ValidateAndSerializeWithTrace(
Source: event.ProtoPayload.ServiceName,
Id: event.InsertId,
Time: event.ProtoPayload.RequestMetadata.RequestAttributes.Time.AsTime(),
DataContentType: ContentTypeCloudEventsProtobuf,
DataType: fmt.Sprintf("%v", routableEvent.ProtoReflect().Descriptor().FullName()),
DataContentType: ContentTypeCloudEventsJson,
DataType: "audit.v1.LegacyAuditEvent",
Subject: event.ProtoPayload.ResourceName,
Data: legacyBytes,
TraceParent: traceParent,

View file

@ -441,6 +441,8 @@ func validateSentMessageWithDetails(
// Check topic name
assert.Equal(t, topicName, *message.Properties.To)
assert.Equal(t, ContentTypeCloudEventsJson, message.ApplicationProperties["cloudEvents:datacontenttype"])
assert.Equal(t, "audit.v1.LegacyAuditEvent", message.ApplicationProperties["cloudEvents:type"])
assert.Equal(t, *traceParent, message.ApplicationProperties["cloudEvents:traceparent"])
assert.Equal(t, *traceState, message.ApplicationProperties["cloudEvents:tracestate"])