mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-15 18:17:49 +02:00
postgres: return unknown records instead of skipping them (#3876)
This commit is contained in:
parent
9677e18bbd
commit
92b50683ff
2 changed files with 41 additions and 41 deletions
|
@ -173,10 +173,11 @@ func TestBackend(t *testing.T) {
|
|||
_, err = backend.Get(ctx, "unknown", "1")
|
||||
assert.ErrorIs(t, err, storage.ErrNotFound)
|
||||
|
||||
_, _, stream, err := backend.SyncLatest(ctx, "unknown-test", nil)
|
||||
_, _, stream, err := backend.SyncLatest(ctx, "unknown", nil)
|
||||
if assert.NoError(t, err) {
|
||||
_, err := storage.RecordStreamToList(stream)
|
||||
records, err := storage.RecordStreamToList(stream)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, records, 1)
|
||||
stream.Close()
|
||||
}
|
||||
})
|
||||
|
|
|
@ -97,7 +97,6 @@ func getLatestRecordVersion(ctx context.Context, q querier) (recordVersion uint6
|
|||
}
|
||||
|
||||
func getNextChangedRecord(ctx context.Context, q querier, recordType string, afterRecordVersion uint64) (*databroker.Record, error) {
|
||||
for {
|
||||
var recordID string
|
||||
var version uint64
|
||||
var data []byte
|
||||
|
@ -123,12 +122,12 @@ func getNextChangedRecord(ctx context.Context, q querier, recordType string, aft
|
|||
} else if err != nil {
|
||||
return nil, fmt.Errorf("error querying next changed record: %w", err)
|
||||
}
|
||||
afterRecordVersion = version
|
||||
|
||||
any, err := protoutil.UnmarshalAnyJSON(data)
|
||||
if isUnknownType(err) {
|
||||
// ignore
|
||||
continue
|
||||
any = protoutil.ToAny(protoutil.ToStruct(map[string]string{
|
||||
"id": recordID,
|
||||
}))
|
||||
} else if err != nil {
|
||||
return nil, fmt.Errorf("error unmarshaling changed record data: %w", err)
|
||||
}
|
||||
|
@ -141,7 +140,6 @@ func getNextChangedRecord(ctx context.Context, q querier, recordType string, aft
|
|||
ModifiedAt: timestamppbFromTimestamptz(modifiedAt),
|
||||
DeletedAt: timestamppbFromTimestamptz(deletedAt),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func getOptions(ctx context.Context, q querier, recordType string) (*databroker.Options, error) {
|
||||
|
@ -229,8 +227,9 @@ func listRecords(ctx context.Context, q querier, expr storage.FilterExpression,
|
|||
|
||||
any, err := protoutil.UnmarshalAnyJSON(data)
|
||||
if isUnknownType(err) {
|
||||
// ignore records with an unknown type
|
||||
continue
|
||||
any = protoutil.ToAny(protoutil.ToStruct(map[string]string{
|
||||
"id": id,
|
||||
}))
|
||||
} else if err != nil {
|
||||
return nil, fmt.Errorf("postgres: failed to unmarshal data: %w", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue