Phase 13, part 5: each team's jobs, locks, files and sign-ins

Background jobs run for each active team on its own Server and under its
own locks, a few teams at a time and from a different team each round, so
the work is shared between copies of the app and no team holds up another.
Each team's files are under its own prefix, and an OAuth sign-in comes
back only to the team that started it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 12:26:33 -07:00
co-authored by Claude Opus 5.5
parent 47cc8b2b10
commit af6598271c
16 changed files with 275 additions and 40 deletions
+66
View File
@@ -102,3 +102,69 @@ func Check(ctx context.Context, st Store) error {
}
return nil
}
// Under is a store whose files are under prefix in another: each team's
// own place in the platform's store. Keys are checked before the prefix
// is added, so none reaches outside it.
func Under(s Store, prefix string) Store {
return &under{s: s, prefix: strings.Trim(prefix, "/") + "/"}
}
type under struct {
s Store
prefix string
}
func (u *under) key(k string) (string, error) {
if err := CheckKey(k); err != nil {
return "", err
}
return u.prefix + k, nil
}
func (u *under) Put(ctx context.Context, key string, r io.Reader, size int64) error {
k, err := u.key(key)
if err != nil {
return err
}
return u.s.Put(ctx, k, r, size)
}
func (u *under) Get(ctx context.Context, key string) (io.ReadCloser, error) {
k, err := u.key(key)
if err != nil {
return nil, err
}
return u.s.Get(ctx, k)
}
func (u *under) Stat(ctx context.Context, key string) (Info, error) {
k, err := u.key(key)
if err != nil {
return Info{}, err
}
i, err := u.s.Stat(ctx, k)
i.Key = strings.TrimPrefix(i.Key, u.prefix)
return i, err
}
func (u *under) List(ctx context.Context, prefix string) ([]Info, error) {
if strings.Contains(prefix, "..") || strings.HasPrefix(prefix, "/") || strings.Contains(prefix, "\\") {
return nil, fmt.Errorf("storage: %q isn't a usable prefix", prefix)
}
list, err := u.s.List(ctx, u.prefix+prefix)
for i := range list {
list[i].Key = strings.TrimPrefix(list[i].Key, u.prefix)
}
return list, err
}
func (u *under) Delete(ctx context.Context, key string) error {
k, err := u.key(key)
if err != nil {
return err
}
return u.s.Delete(ctx, k)
}
func (u *under) String() string { return u.s.String() + " under " + u.prefix }