Repository navigation
feat(store): add the principal store and share-locked reads #59
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
Merged
pyropy
merged 11 commits into
srdjan/feat/iam-vocabulary
from
srdjan/feat/iam-principal-store
Oct 14, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6c17ff8
feat(store): add the principal store and share-locked reads
pyropy bbafa88
docs(store): say why the memory Lock holds nothing
pyropy 8f8bb3e
refactor(store): take the read lock as a functional option
pyropy 6c264b0
test: fail instead of hanging when the writer exits before its lock
pyropy d7624e5
test: name the wait helper's timeout
pyropy 32070ed
test: call the wait helper's timeout WaitTimeout
pyropy 8f1a8d0
test: call the wait helper's blocked window MinBlock
pyropy 2e6ad47
docs(testutil): say that the writer blocks until release is closed
pyropy 08ee063
refactor(store): call the principal removal Tombstone and its callbac…
pyropy 56ef319
refactor(store): rename the principal store's Lock to WithLock
pyropy 767c2b2
refactor(store): keep beforeCommit as the Postgres principal store's …
pyropy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package testutil | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
| ) | ||
|
|
||
| // MinBlock is how long a call that must wait on a writer has to stay blocked. | ||
| const MinBlock = 300 * time.Millisecond | ||
|
|
||
| // WaitTimeout is how long a call that must finish is given before the test fails. | ||
| const WaitTimeout = 10 * time.Second | ||
|
|
||
| // RequireWaitsForWriter runs write in the background; write must close | ||
| // entered once it holds its lock, then block until release is closed before | ||
| // finishing. It then starts wait, requires that wait has not returned within [MinBlock], | ||
| // releases the writer, and returns the writer's and wait's errors. | ||
| func RequireWaitsForWriter(t *testing.T, write func(entered chan<- struct{}, release <-chan struct{}) error, wait func() error) (writeErr, waitErr error) { | ||
| t.Helper() | ||
| entered := make(chan struct{}) | ||
| release := make(chan struct{}) | ||
| wrote := make(chan error, 1) | ||
| go func() { wrote <- write(entered, release) }() | ||
| select { | ||
| case <-entered: | ||
| case err := <-wrote: | ||
| t.Fatalf("the writer returned before taking its lock: %v", err) | ||
| case <-time.After(WaitTimeout): | ||
| t.Fatal("the writer did not take its lock") | ||
| } | ||
|
|
||
| waited := make(chan error, 1) | ||
| go func() { waited <- wait() }() | ||
| select { | ||
| case <-waited: | ||
| t.Fatal("the waiting call returned while the writer held its lock") | ||
| case <-time.After(MinBlock): | ||
| } | ||
|
|
||
| close(release) | ||
| writeErr = <-wrote | ||
| select { | ||
| case waitErr = <-waited: | ||
| case <-time.After(WaitTimeout): | ||
| t.Fatal("the waiting call did not return after the writer finished") | ||
| } | ||
| return writeErr, waitErr | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| -- +goose Up | ||
| -- +goose StatementBegin | ||
| -- principal is a console user within a tenant, identified by the console's | ||
| -- principalId. A principal holds no key material and no delegations: its access | ||
| -- is computed from bucket policies at request time. Removal sets deleted_at | ||
| -- rather than deleting the row, so a later PUT for the same id revives it and | ||
| -- an id reused by the console never inherits anything. | ||
| CREATE TABLE principal ( | ||
| tenant_id TEXT NOT NULL REFERENCES tenant(id) ON DELETE RESTRICT, -- DID (did:plc) | ||
| external_id TEXT NOT NULL, -- console principalId | ||
| created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
| deleted_at TIMESTAMPTZ, -- set by removal; cleared by revive | ||
| PRIMARY KEY (tenant_id, external_id) | ||
| ); | ||
| -- +goose StatementEnd | ||
|
|
||
| -- +goose Down | ||
| -- +goose StatementBegin | ||
| DROP TABLE IF EXISTS principal; | ||
| -- +goose StatementEnd |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.