mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-04 09:19:39 +02:00
zero: resource bundle reconciler
This commit is contained in:
parent
0affd9268b
commit
48c248657d
13 changed files with 1246 additions and 30 deletions
43
internal/zero/reconciler/bundles_format.go
Normal file
43
internal/zero/reconciler/bundles_format.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package reconciler
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"google.golang.org/protobuf/encoding/protodelim"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
|
||||
"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) {
|
||||
// start reading
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
data, err := protojson.Marshal(record)
|
||||
if err == nil {
|
||||
fmt.Printf("record: %s\n", string(data))
|
||||
}
|
||||
|
||||
rsb.Add(DatabrokerRecord{record})
|
||||
}
|
||||
|
||||
return rsb, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue