fork of https://github.com/sourcegraph/zoekt
1package tenant
2
3import (
4 "context"
5
6 "github.com/sourcegraph/zoekt/internal/tenant/systemtenant"
7)
8
9// HasAccess returns true if the tenant ID in the context matches the
10// given ID. If tenant enforcement is disabled, it always returns true.
11func HasAccess(ctx context.Context, id int) bool {
12 if !EnforceTenant() {
13 return true
14 }
15 if systemtenant.Is(ctx) {
16 return true
17 }
18 t, err := FromContext(ctx)
19 if err != nil {
20 return false
21 }
22 return t.ID() == id
23}