Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 46 additions & 12 deletions pb/c1/connector/v2/grant.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 4 additions & 11 deletions pb/c1/connector/v2/grant.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 44 additions & 12 deletions pb/c1/connector/v2/grant_protoopaque.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/connectorbuilder/resource_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ func (b *builder) ListGrants(ctx context.Context, request *v2.GrantsServiceListG

start := b.nowFunc()
tt := tasks.ListGrantsType

if request.GetResource() == nil {
err := fmt.Errorf("error: list grants requires a resource")
b.m.RecordTaskFailure(ctx, tt, b.nowFunc().Sub(start), err)
return nil, err
}

rid := request.GetResource().GetId()
rb, ok := b.resourceSyncers[rid.GetResourceType()]
if !ok {
Expand Down
7 changes: 7 additions & 0 deletions pkg/connectorstore/connectorstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,10 @@ type Writer interface {
PutEntitlements(ctx context.Context, entitlements ...*v2.Entitlement) error
DeleteGrant(ctx context.Context, grantId string) error
}

// ExpansionStore provides methods for grant expansion operations.
// Not all store implementations support expansion; callers should type-assert.
type ExpansionStore interface {
// SetSupportsDiff marks the sync as supporting diff operations.
SetSupportsDiff(ctx context.Context, syncID string) error
}
21 changes: 19 additions & 2 deletions pkg/dotc1z/c1file_attached.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"fmt"
"strings"
"time"

reader_v2 "github.com/conductorone/baton-sdk/pb/c1/reader/v2"
Expand Down Expand Up @@ -227,6 +228,8 @@ func (c *C1FileAttached) GenerateSyncDiffFromFile(ctx context.Context, oldSyncID
"sync_type": connectorstore.SyncTypePartialDeletions,
"parent_sync_id": oldSyncID,
"linked_sync_id": upsertsSyncID,
// This sync is generated by the new SQL-layer diff logic, so it is safe for diff operations.
"supports_diff": 1,
})
query, args, err := deletionsInsert.ToSQL()
if err != nil {
Expand All @@ -244,6 +247,8 @@ func (c *C1FileAttached) GenerateSyncDiffFromFile(ctx context.Context, oldSyncID
"sync_type": connectorstore.SyncTypePartialUpserts,
"parent_sync_id": oldSyncID,
"linked_sync_id": deletionsSyncID,
// This sync is generated by the new SQL-layer diff logic, so it is safe for diff operations.
"supports_diff": 1,
})
query, args, err = upsertsInsert.ToSQL()
if err != nil {
Expand Down Expand Up @@ -374,6 +379,18 @@ func (c *C1FileAttached) diffTableFromMainTx(ctx context.Context, tx *sql.Tx, ta
// 1. Not in attached (OLD) - additions
// 2. In attached but with different data - modifications
// newSyncID is in main, oldSyncID is in attached
//
// For grants, we also compare the expansion column since GrantExpandable
// annotation is stored separately from data.
var dataCompare string
if strings.Contains(tableName, "grants") {
// For grants: compare both data AND expansion columns.
// Use IFNULL to handle NULL expansion values.
dataCompare = "(a.data != m.data OR IFNULL(a.expansion, X'') != IFNULL(m.expansion, X''))"
} else {
dataCompare = "a.data != m.data"
}

//nolint:gosec // table names are from hardcoded list, not user input
query := fmt.Sprintf(`
INSERT INTO main.%s (%s)
Expand All @@ -389,10 +406,10 @@ func (c *C1FileAttached) diffTableFromMainTx(ctx context.Context, tx *sql.Tx, ta
SELECT 1 FROM attached.%s AS a
WHERE a.external_id = m.external_id
AND a.sync_id = ?
AND a.data != m.data
AND %s
)
)
`, tableName, columnList, selectList, tableName, tableName, tableName)
`, tableName, columnList, selectList, tableName, tableName, tableName, dataCompare)

_, err = tx.ExecContext(ctx, query, targetSyncID, newSyncID, oldSyncID, oldSyncID)
return err
Expand Down
Loading
Loading