Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions asab/web/tenant/providers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from .static import StaticTenantProvider
from .system import SystemTenantProvider
from .web import WebTenantProvider
from .zookeeper import ZookeeperTenantProvider

__all__ = [
"StaticTenantProvider",
"SystemTenantProvider",
"WebTenantProvider",
"ZookeeperTenantProvider"
]
4 changes: 4 additions & 0 deletions asab/web/tenant/providers/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@


class TenantProviderABC(abc.ABC):

Type = None


def __init__(self, app, tenant_service, config):
self.App = app
self.TenantService = tenant_service
Expand Down
2 changes: 2 additions & 0 deletions asab/web/tenant/providers/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

class StaticTenantProvider(TenantProviderABC):

Type = "static"


def __init__(self, app, tenant_service, config):
super().__init__(app, tenant_service, config)
Expand Down
16 changes: 16 additions & 0 deletions asab/web/tenant/providers/system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import typing
import logging

from .static import StaticTenantProvider

L = logging.getLogger(__name__)


class SystemTenantProvider(StaticTenantProvider):

Type = "system"


def __init__(self, app, tenant_service, config):
super().__init__(app, tenant_service, config)
self.Tenants: typing.Set[str] = {"system"}
4 changes: 4 additions & 0 deletions asab/web/tenant/providers/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@


class WebTenantProvider(TenantProviderABC):

Type = "web"


def __init__(self, app, tenant_service, config):
super().__init__(app, tenant_service, config)
self.Tenants: typing.Set[str] = set()
Expand Down
4 changes: 4 additions & 0 deletions asab/web/tenant/providers/zookeeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@


class ZookeeperTenantProvider(TenantProviderABC):

Type = "zookeeper"


def __init__(self, app, tenant_service, config):
super().__init__(app, tenant_service, config)
self.Tenants: typing.Set[str] = set()
Expand Down
19 changes: 19 additions & 0 deletions asab/web/tenant/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def Tenants(self) -> typing.Set[str]:


def _prepare_providers(self):
from .providers import SystemTenantProvider
self.Providers.append(SystemTenantProvider(self.App, self, Config["tenants"]))

if Config.get("tenants", "ids", fallback=None):
from .providers import StaticTenantProvider
self.Providers.append(StaticTenantProvider(self.App, self, Config["tenants"]))
Expand All @@ -93,6 +96,22 @@ async def update_tenants(self):
await asyncio.gather(*tasks)


async def get_provider(self, provider_type: str):
"""
Get a tenant provider by its type.

Args:
provider_type: Type of the tenant provider to retrieve.

Returns:
The tenant provider instance or None if not found.
"""
for provider in self.Providers:
if provider.Type == provider_type:
return provider
return None


async def get_tenants(self) -> typing.Set[str]:
"""
Get the set of known tenant IDs.
Expand Down