Skip to content

Commit

Permalink
use tenant providers
Browse files Browse the repository at this point in the history
  • Loading branch information
byewokko committed Nov 7, 2024
1 parent d742e4d commit 519df6c
Showing 1 changed file with 0 additions and 55 deletions.
55 changes: 0 additions & 55 deletions asab/web/tenant/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,58 +62,3 @@ def get_tenants(self) -> typing.Set[str]:

def is_tenant_known(self, tenant: str) -> bool:
return tenant in self.Tenants

def locate_tenant(self, tenant_id):
if tenant_id in self.Tenants:
return tenant_id
elif self.TenantsTrusted:
self.Tenants.add(tenant_id)
return tenant_id
else:
return None


def get_tenants(self):
return list(self.Tenants)


def add_web_api(self, web_container):
from .web import TenantWebHandler
self.TenantWebHandler = TenantWebHandler(self.App, self, web_container)


async def _update_tenants(self, message_name=None):
new_tenants = set()

if len(self.TenantUrl) > 0:
async with aiohttp.ClientSession() as session:
async with session.get(self.TenantUrl) as resp:
if resp.status == 200:
external_tenants = await resp.json()
else:
L.warning("Failed to load tenants.", struct_data={"url": self.TenantUrl})
return

new_tenants.update(external_tenants)

if len(self._StaticTenants) > 0:
new_tenants.update(self._StaticTenants)

if self.Tenants != new_tenants:
self.App.PubSub.publish("Tenants.change!")
self.Tenants = new_tenants


def _read_tenants_from_config() -> typing.Set[str]:
tenants = set()
for tenant_id in re.split(r"[,\s]+", Config.get("tenants", "ids"), flags=re.MULTILINE):
tenant_id = tenant_id.strip()
# Skip comments and empty lines
if len(tenant_id) == 0:
continue
if tenant_id[0] == '#':
continue
if tenant_id[0] == ';':
continue
tenants.add(tenant_id)
return tenants

0 comments on commit 519df6c

Please sign in to comment.