zero: resource bundle reconciler (#4445)

This commit is contained in:
Denis Mishin 2023-08-17 13:19:51 -04:00 committed by GitHub
parent 788376bf60
commit 3b65049d2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 1560 additions and 0 deletions

View file

@ -0,0 +1,35 @@
package reconciler
import (
"bufio"
"errors"
"fmt"
"io"
"google.golang.org/protobuf/encoding/protodelim"
"github.com/pomerium/pomerium/pkg/grpc/databroker"
)
var unmarshalOpts = protodelim.UnmarshalOptions{}
// ReadBundleRecords reads records in a protobuf wire format from src.
// Each record is expected to be a databroker.Record.
func ReadBundleRecords(src io.Reader) (RecordSetBundle[DatabrokerRecord], error) {
r := bufio.NewReader(src)
rsb := make(RecordSetBundle[DatabrokerRecord])
for {
record := new(databroker.Record)
err := unmarshalOpts.UnmarshalFrom(r, record)
if errors.Is(err, io.EOF) {
break
}
if err != nil {
return nil, fmt.Errorf("error reading protobuf record: %w", err)
}
rsb.Add(DatabrokerRecord{record})
}
return rsb, nil
}