diff --git a/go/vehicle-gateway/internal/realtime/model.go b/go/vehicle-gateway/internal/realtime/model.go index d5b978f0..2414782d 100644 --- a/go/vehicle-gateway/internal/realtime/model.go +++ b/go/vehicle-gateway/internal/realtime/model.go @@ -7,18 +7,17 @@ import ( ) type Snapshot struct { - VehicleKey string `json:"vehicle_key"` - VIN string `json:"vin"` - Protocol envelope.Protocol `json:"protocol,omitempty"` - Protocols []envelope.Protocol `json:"protocols,omitempty"` - EventID string `json:"event_id,omitempty"` - EventTimeMS int64 `json:"event_time_ms"` - ReceivedAtMS int64 `json:"received_at_ms"` - SourceEndpoint string `json:"source_endpoint,omitempty"` - Fields map[string]any `json:"fields,omitempty"` - FieldTimesMS map[string]int64 `json:"field_times_ms,omitempty"` - Parsed map[string]any `json:"parsed,omitempty"` - UpdatedAtMS int64 `json:"updated_at_ms"` + VehicleKey string `json:"vehicle_key"` + VIN string `json:"vin"` + Protocol envelope.Protocol `json:"protocol,omitempty"` + Protocols []envelope.Protocol `json:"protocols,omitempty"` + EventID string `json:"event_id,omitempty"` + EventTimeMS int64 `json:"event_time_ms"` + ReceivedAtMS int64 `json:"received_at_ms"` + Fields map[string]any `json:"fields,omitempty"` + FieldTimesMS map[string]int64 `json:"field_times_ms,omitempty"` + Parsed map[string]any `json:"parsed,omitempty"` + UpdatedAtMS int64 `json:"updated_at_ms"` } func (s Snapshot) Lightweight() Snapshot { diff --git a/go/vehicle-gateway/internal/realtime/repository.go b/go/vehicle-gateway/internal/realtime/repository.go index 596188ff..a61c4924 100644 --- a/go/vehicle-gateway/internal/realtime/repository.go +++ b/go/vehicle-gateway/internal/realtime/repository.go @@ -39,17 +39,16 @@ func (r *Repository) Update(ctx context.Context, env envelope.FrameEnvelope) err eventMS = env.ReceivedAtMS } protocolSnapshot := Snapshot{ - VehicleKey: vehicleKey, - VIN: vin, - Protocol: env.Protocol, - EventID: env.StableEventID(), - EventTimeMS: eventMS, - ReceivedAtMS: env.ReceivedAtMS, - SourceEndpoint: env.SourceEndpoint, - Fields: cloneFields(env.Fields), - FieldTimesMS: fieldTimes(env.Fields, eventMS), - Parsed: cloneMap(env.Parsed), - UpdatedAtMS: nowMS, + VehicleKey: vehicleKey, + VIN: vin, + Protocol: env.Protocol, + EventID: env.StableEventID(), + EventTimeMS: eventMS, + ReceivedAtMS: env.ReceivedAtMS, + Fields: cloneFields(env.Fields), + FieldTimesMS: fieldTimes(env.Fields, eventMS), + Parsed: cloneMap(env.Parsed), + UpdatedAtMS: nowMS, } existingProtocol, err := r.GetProtocol(ctx, vehicleKey, env.Protocol) if err != nil && !errors.Is(err, redis.Nil) { @@ -69,7 +68,6 @@ func (r *Repository) Update(ctx context.Context, env envelope.FrameEnvelope) err protocolSnapshot.EventTimeMS = eventMS protocolSnapshot.EventID = env.StableEventID() protocolSnapshot.ReceivedAtMS = env.ReceivedAtMS - protocolSnapshot.SourceEndpoint = env.SourceEndpoint } protocolSnapshot.UpdatedAtMS = nowMS } @@ -105,7 +103,6 @@ func (r *Repository) Update(ctx context.Context, env envelope.FrameEnvelope) err merged.EventTimeMS = eventMS merged.EventID = env.StableEventID() merged.ReceivedAtMS = env.ReceivedAtMS - merged.SourceEndpoint = env.SourceEndpoint } merged.Protocols = protocols merged.UpdatedAtMS = nowMS diff --git a/go/vehicle-gateway/internal/realtime/repository_test.go b/go/vehicle-gateway/internal/realtime/repository_test.go index a9970529..8943de04 100644 --- a/go/vehicle-gateway/internal/realtime/repository_test.go +++ b/go/vehicle-gateway/internal/realtime/repository_test.go @@ -380,11 +380,12 @@ func TestHandlerReturnsMergedSnapshot(t *testing.T) { repo, closeFn := newTestRepository(t) defer closeFn() if err := repo.Update(context.Background(), envelope.FrameEnvelope{ - Protocol: envelope.ProtocolJT808, - VIN: "VIN001", - EventTimeMS: 1000, - ReceivedAtMS: 1100, - Fields: map[string]any{envelope.FieldSpeedKMH: 12.3}, + Protocol: envelope.ProtocolJT808, + VIN: "VIN001", + SourceEndpoint: "115.231.168.135:43625", + EventTimeMS: 1000, + ReceivedAtMS: 1100, + Fields: map[string]any{envelope.FieldSpeedKMH: 12.3}, }); err != nil { t.Fatalf("Update() error = %v", err) } @@ -398,6 +399,9 @@ func TestHandlerReturnsMergedSnapshot(t *testing.T) { if !stringsContains(rec.Body.String(), `"vin":"VIN001"`) { t.Fatalf("unexpected body: %s", rec.Body.String()) } + if stringsContains(rec.Body.String(), "source_endpoint") { + t.Fatalf("realtime snapshot should not expose source_endpoint: %s", rec.Body.String()) + } } func TestHandlerReturnsPhoneOnlyVehicleKeySnapshot(t *testing.T) {