コード例 #1
0
ファイル: utils.py プロジェクト: blazing-gig/multi-tenant-poc
def construct_conn_alias(tenant_alias, orm_key, template_alias):
    return join_keys(tenant_alias,
                     settings.TENANT_ROUTER_SERVICE_NAME,
                     ORM_CONFIG_PREFIX_KEY,
                     orm_key,
                     template_alias,
                     separator=constants.KEY_SEPARATOR)
コード例 #2
0
    def _fill_template_aliases(self):
        service_name = settings.TENANT_ROUTER_SERVICE_NAME

        for tenant_context in tenant_context_manager.all():
            cache_prefix = join_keys(
                tenant_context.alias,
                service_name,
                CACHE_CONFIG_PREFIX_KEY
            )

            for cache_alias in self._config_store.iter_keys(
                    cache_prefix + '*'
            ):
                cache_config = self._config_store.get(cache_alias)
                self._register_config(cache_alias, cache_config)
コード例 #3
0
    def _orm_key_deleter(self):
        prefix = join_keys(self.tenant_context.alias,
                           settings.TENANT_ROUTER_SERVICE_NAME,
                           ORM_CONFIG_PREFIX_KEY)

        for key in self.config_store.iter_keys(prefix + "*"):
            _, orm_key, _ = deconstruct_conn_alias(key)

            if orm_key in self.final_event_payload[ORM_CONFIG_PREFIX_KEY]:
                self.final_event_payload[ORM_CONFIG_PREFIX_KEY][
                    orm_key].append(key)
            else:
                self.final_event_payload[ORM_CONFIG_PREFIX_KEY][orm_key] = [
                    key
                ]

            self.config_store.delete(key)
コード例 #4
0
    def _orm_key_handler(self, mapping_key, value):
        orm_key_template_alias = remove_prefix(
            mapping_key,
            prefix=ORM_CONFIG_PREFIX_KEY).strip(constants.KEY_SEPARATOR)

        orm_key, _ = deconstruct_orm_key_template_alias(orm_key_template_alias)

        orm_manager = orm_managers[orm_key]

        final_key = join_keys(
            TenantContext.from_id(self.tenant_id).alias,
            settings.TENANT_ROUTER_SERVICE_NAME, mapping_key)
        final_config = orm_manager.format_conn_url(value)

        self.config_store.set(final_key, final_config)
        self.final_event_payload[ORM_CONFIG_PREFIX_KEY][orm_key] = {
            final_key: final_config
        }
コード例 #5
0
ファイル: core.py プロジェクト: blazing-gig/multi-tenant-poc
    def _construct_orm_config(orm_keys):
        orm_config = {}
        service_name = settings.TENANT_ROUTER_SERVICE_NAME
        config_store = caches[constants.CONFIG_STORE_ALIAS]

        for tenant_context in tenant_context_manager.all():
            for orm_key in orm_keys:
                prefix_key = join_keys(tenant_context.alias, service_name,
                                       ORM_CONFIG_PREFIX_KEY, orm_key)

                for conn_alias in config_store.iter_keys(prefix_key + "*"):
                    db_config = config_store.get(conn_alias)
                    if orm_key in orm_config:
                        orm_config[orm_key][conn_alias] = db_config
                    else:
                        orm_config[orm_key] = {conn_alias: db_config}

        return orm_config
コード例 #6
0
def construct_schedule_name(tenant_alias, schedule_name):
    return join_keys(tenant_alias, settings.TENANT_ROUTER_SERVICE_NAME,
                     schedule_name)
コード例 #7
0
 def NORMALIZED_MAPPING_METADATA(self):
     return join_keys(settings.TENANT_ROUTER_SERVICE_NAME,
                      self.MAPPING_METADATA)
コード例 #8
0
def construct_cache_alias(tenant_alias, template_alias):
    return join_keys(tenant_alias, settings.TENANT_ROUTER_SERVICE_NAME,
                     CACHE_CONFIG_PREFIX_KEY, template_alias)
コード例 #9
0
def construct_tenant_channel_name(lifecycle_event, tenant_context=None):
    if lifecycle_event in TenantLifecycleEvent.get_tenant_bound_events():
        return join_keys(tenant_context.alias,
                         settings.TENANT_ROUTER_SERVICE_NAME, lifecycle_event)
    else:
        return lifecycle_event