-
Notifications
You must be signed in to change notification settings - Fork 5
export PrincipalBucketHash #1069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
accbcd3
e7c4bb5
cb358eb
85547a6
a7ce6b8
18e8dac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -719,13 +719,18 @@ func (e *Engine) GetEntitlementGrantDigest(ctx context.Context, ent *v2.Entitlem | |
| // grant-digest rollup nodes at the requested level (2^level buckets; | ||
| // level 0 = the root). For 0 <= level <= the digest's native level it | ||
| // folds the stored leaves — one scan of the digest keyspace. For a finer | ||
| // level it scans the grant index directly (O(grants)) instead of | ||
| // erroring; the level is clamped to the bucket-hash resolution | ||
| // (digestMaxWidthBits). | ||
| // level, up to digestMaxWidthBits, it scans the grant index directly | ||
| // (O(grants)) instead. A level outside [0, digestMaxWidthBits] errors: | ||
| // the bucket hash carries no more resolution than digestMaxWidthBits, so | ||
| // silently clamping would report buckets a caller's own precomputed | ||
| // index (see PrincipalDigestBucket) does not agree with. | ||
| func (e *Engine) GetEntitlementGrantDigestNodes(ctx context.Context, ent *v2.Entitlement, level int) ([]connectorstore.GrantDigestNode, bool, error) { | ||
| if level < 0 { | ||
| return nil, false, fmt.Errorf("pebble: negative grant-digest level %d", level) | ||
| } | ||
| if level > digestMaxWidthBits { | ||
| return nil, false, fmt.Errorf("pebble: grant-digest level %d exceeds bucket-hash resolution %d", level, digestMaxWidthBits) | ||
| } | ||
|
Comment on lines
+731
to
+733
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion: this is a deliberate default-behavior break on an exported interface method — a caller that previously passed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR description now calls out the default-behavior change (error instead of clamp past the bucket-hash resolution). Left |
||
| syncID, err := e.resolveActiveSyncForReader(ctx, nil) | ||
| if err != nil { | ||
| return nil, false, err | ||
|
|
@@ -746,11 +751,10 @@ func (e *Engine) GetEntitlementGrantDigestNodes(ctx context.Context, ent *v2.Ent | |
| if level == 0 { | ||
| return []connectorstore.GrantDigestNode{{Index: 0, Hash: root.Hash, Count: root.Count}}, true, nil | ||
| } | ||
| // The bucket hash carries at most digestMaxWidthBits of resolution; | ||
| // a finer level can't address more buckets, so clamp. | ||
| bits := min(level, digestMaxWidthBits) | ||
| // At or below the stored width, fold the digest leaves (cheap). Finer | ||
| // than what we stored, scan the grant index to compute the rollup. | ||
| // level is already bounded to [0, digestMaxWidthBits] above. At or | ||
| // below the stored width, fold the digest leaves (cheap); finer than | ||
| // what we stored, scan the grant index to compute the rollup. | ||
| bits := level | ||
| partition := digestPartitionForEntitlement(id) | ||
| var folded []foldedBucket | ||
| if bits <= root.Bits { | ||
|
|
@@ -775,13 +779,27 @@ func (e *Engine) GetEntitlementGrantDigestNodes(ctx context.Context, ent *v2.Ent | |
| // ScanEntitlementGrantBucket implements | ||
| // connectorstore.EntitlementGrantDigestReader. It yields every grant in | ||
| // the given digest bucket of the entitlement, translated to v2.Grant. | ||
| // Bucket Level 0 scans the whole entitlement; a finer Level is clamped | ||
| // to the bucket-hash resolution. Yields nothing when there is no active | ||
| // sync or a bare entitlement id resolves to nothing. | ||
| // Bucket Level 0 scans the whole entitlement. A Level outside | ||
| // [0, digestMaxWidthBits] errors rather than clamping to the bucket-hash | ||
| // resolution, and an Index outside [0, 2^Level) errors rather than | ||
| // wrapping to its low Level bits: either kind of silent folding would | ||
| // scan a bucket other than the one the caller addressed (see | ||
| // PrincipalDigestBucket, which only builds in-range buckets). Yields | ||
| // nothing when there is no active sync or a bare entitlement id | ||
| // resolves to nothing. | ||
| func (e *Engine) ScanEntitlementGrantBucket(ctx context.Context, ent *v2.Entitlement, bucket connectorstore.GrantDigestBucket, yield func(*v2.Grant) bool) error { | ||
| if bucket.Level < 0 { | ||
| return fmt.Errorf("pebble: negative grant-digest level %d", bucket.Level) | ||
| } | ||
| if bucket.Level > digestMaxWidthBits { | ||
| return fmt.Errorf("pebble: grant-digest level %d exceeds bucket-hash resolution %d", bucket.Level, digestMaxWidthBits) | ||
| } | ||
| // Level 0 ignores Index (whole-entitlement scan) per the | ||
| // GrantDigestBucket contract; past that, bucketBounds would shift an | ||
| // oversized index's high bits away and scan Index mod 2^Level. | ||
| if bucket.Level > 0 && uint64(bucket.Index) >= 1<<uint(bucket.Level) { | ||
| return fmt.Errorf("pebble: grant-digest bucket index %d out of range [0, 2^%d)", bucket.Index, bucket.Level) | ||
| } | ||
| syncID, err := e.resolveActiveSyncForReader(ctx, nil) | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -793,8 +811,7 @@ func (e *Engine) ScanEntitlementGrantBucket(ctx context.Context, ent *v2.Entitle | |
| if err != nil || !ok { | ||
| return err | ||
| } | ||
| bits := min(bucket.Level, digestMaxWidthBits) | ||
| return e.IterateGrantsByEntitlementBucket(ctx, id, DigestBucket{Index: bucket.Index, Bits: bits}, func(r *v3.GrantRecord) bool { | ||
| return e.IterateGrantsByEntitlementBucket(ctx, id, DigestBucket{Index: bucket.Index, Bits: bucket.Level}, func(r *v3.GrantRecord) bool { | ||
|
mj-palanker marked this conversation as resolved.
|
||
| return yield(V3GrantToV2(r)) | ||
| }) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.