mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-31 01:47:33 +02:00
zero: resource bundle reconciler (#4445)
This commit is contained in:
parent
c0b1309e90
commit
ea8762d706
17 changed files with 1559 additions and 0 deletions
53
internal/zero/reconciler/databroker_changeset.go
Normal file
53
internal/zero/reconciler/databroker_changeset.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package reconciler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
||||
)
|
||||
|
||||
// DatabrokerChangeSet is a set of databroker changes.
|
||||
type DatabrokerChangeSet struct {
|
||||
now *timestamppb.Timestamp
|
||||
updates []*databroker.Record
|
||||
}
|
||||
|
||||
// NewDatabrokerChangeSet creates a new databroker change set.
|
||||
func NewDatabrokerChangeSet() *DatabrokerChangeSet {
|
||||
return &DatabrokerChangeSet{
|
||||
now: timestamppb.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
// Remove adds a record to the change set.
|
||||
func (cs *DatabrokerChangeSet) Remove(typ string, id string) {
|
||||
cs.updates = append(cs.updates, &databroker.Record{
|
||||
Type: typ,
|
||||
Id: id,
|
||||
DeletedAt: cs.now,
|
||||
})
|
||||
}
|
||||
|
||||
// Upsert adds a record to the change set.
|
||||
func (cs *DatabrokerChangeSet) Upsert(record *databroker.Record) {
|
||||
cs.updates = append(cs.updates, &databroker.Record{
|
||||
Type: record.Type,
|
||||
Id: record.Id,
|
||||
Data: record.Data,
|
||||
})
|
||||
}
|
||||
|
||||
// ApplyChanges applies the changes to the databroker.
|
||||
func ApplyChanges(ctx context.Context, client databroker.DataBrokerServiceClient, changes *DatabrokerChangeSet) error {
|
||||
updates := databroker.OptimumPutRequestsFromRecords(changes.updates)
|
||||
for _, req := range updates {
|
||||
_, err := client.Put(ctx, req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("put databroker record: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue