fork of https://github.com/sourcegraph/zoekt
1package tenant
2
3import (
4 "os"
5
6 "github.com/sourcegraph/zoekt/internal/tenant/internal/enforcement"
7)
8
9func EnforceTenant() bool {
10 switch enforcement.EnforcementMode.Load() {
11 case "strict":
12 return true
13 default:
14 return false
15 }
16}
17
18// UseIDBasedShardNames returns true if the on disk layout of shards should
19// instead use tenant ID and repository IDs in the names instead of the actual
20// repository names.
21//
22// It is possible for repositories to have the same name, but have different
23// content in a multi-tenant setup. As such, this implementation only returns
24// true in those situations.
25//
26// Note: We could migrate all on-disk layout to only be ID based. However,
27// ID's are a Sourcegraph specific feature so we will always need the two code
28// paths. As such we only return true in multitenant setups.
29//
30// This is Sourcegraph specific.
31func UseIDBasedShardNames() bool {
32 // We use the presence of this environment variable to tell if we are in a
33 // multi-tenant setup. This is the same check that is done in the
34 // Sourcegraph monorepo.
35 return os.Getenv("WORKSPACES_API_URL") != ""
36}