Skip to content

Commit

Permalink
fix(tenant-manager): Remove localhost check for tenant derivation
Browse files Browse the repository at this point in the history
refactor(bridge): Add method to derive ID in tenant context

feat(bridge-service): Integrate tenant-specific ID generation

- Remove check for localhost in tenant derivation logic
- Add method in Bridge class to derive IDs in tenant context
- Use context-driven ID generation during bridge bootstrap and reinstall
  • Loading branch information
atompie committed Dec 7, 2024
1 parent c27af7a commit d158ab1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tracardi/domain/bridge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from hashlib import md5
from typing import Optional

from tracardi.domain.named_entity import NamedEntity
from tracardi.service.plugin.domain.register import Form
from tracardi.service.utils.hasher import uuid4_from_md5


class Bridge(NamedEntity):
Expand All @@ -10,3 +12,7 @@ class Bridge(NamedEntity):
config: Optional[dict] = {}
form: Optional[Form] = None
manual: Optional[str] = None

def get_id_in_context_of_tenant(self, context) -> str:
id_in_context_of_tenant = md5(f"{self.id}-{context.tenant}".encode()).hexdigest()
return uuid4_from_md5(id_in_context_of_tenant)
5 changes: 5 additions & 0 deletions tracardi/service/storage/mysql/service/bridge_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import List

from tracardi.context import get_context
from tracardi.domain.bridge import Bridge
from tracardi.exceptions.log_handler import get_logger
from tracardi.service.storage.mysql.mapping.bridge_mapping import map_to_bridge_table
Expand Down Expand Up @@ -32,14 +33,18 @@ async def replace(self, bridge: Bridge):

@staticmethod
async def bootstrap(default_bridges: List[Bridge]):
context = get_context()
bs = BridgeService()
for bridge in default_bridges:
bridge.id = bridge.get_id_in_context_of_tenant(context)
await bs.insert(bridge)
logger.info(f"Bridge {bridge.name} installed.")

@staticmethod
async def reinstall(default_bridges: List[Bridge]):
context = get_context()
bs = BridgeService()
for bridge in default_bridges:
bridge.id = bridge.get_id_in_context_of_tenant(context)
await bs.replace(bridge)
logger.info(f"Bridge {bridge.name} reinstalled.")

0 comments on commit d158ab1

Please sign in to comment.