EngineProxy
What it is
A restricted view of an IEngine for a specific module. It:
- Exposes only the modules and services declared in the module’s dependencies (unless
unlocked=True). - Provides access to the engine API configuration (if available).
Public API
class ServicesProxy
Service accessor wrapper that enforces module-level service permissions.
object_storage -> ObjectStorageService
Returnsengine.services.object_storageif allowed.triple_store -> TripleStoreService
Returnsengine.services.triple_storeif allowed.vector_store -> VectorStoreService
Returnsengine.services.vector_storeif allowed.secret -> Secret
Returnsengine.services.secretif allowed.bus -> BusService
Returnsengine.services.busif allowed.kv -> KeyValueService
Returnsengine.services.kvif allowed.email -> EmailService
Returnsengine.services.emailif allowed.cache -> CacheService
Returnsengine.services.cacheif allowed.
Access control:
- If
unlocked=False(default), accessing a service not listed inmodule_dependencies.servicesraisesValueError.
class EngineProxy
Engine wrapper that enforces module-level module/service permissions.
modules -> Dict[str, BaseModule]
Returns accessible modules:- If
unlocked=True: all engine modules except the caller module itself. - If
unlocked=False: only modules listed inmodule_dependencies.modules.- Supports soft dependencies via
"<name>#soft": if missing inengine.modules, it is ignored.
- Supports soft dependencies via
- If
services -> ServicesProxy
Returns the service proxy enforcing service access control.api_configuration -> ApiConfiguration
Returnsengine.configuration.api.
RaisesRuntimeErrorif the engine has no.configurationor it lacks.api.
Configuration/Dependencies
- Requires an
engineimplementingnaas_abi_core.engine.IEngine. - Requires module dependency data (
ModuleDependencies) providing:services: a collection of allowed service types (e.g.,ObjectStorageService,BusService, etc.).modules: a collection of allowed module names (strings), optionally suffixed with#soft.
api_configurationdepends onengine.configuration.apibeing present.
Usage
from naas_abi_core.engine.EngineProxy import EngineProxy
from naas_abi_core.services.bus.BusService import BusService
# engine: IEngine
# module_dependencies: has attributes:
# - services: e.g., {BusService}
# - modules: e.g., {"other_module", "optional_module#soft"}
proxy = EngineProxy(engine, module_name="my_module", module_dependencies=module_dependencies)
# Allowed service access
bus = proxy.services.bus
# Allowed module access (filtered by dependencies)
deps_modules = proxy.modules
# Engine API configuration (if engine.configuration.api exists)
api_cfg = proxy.api_configuration
Caveats
- Unauthorized service access raises
ValueError. api_configurationraisesRuntimeErrorwhenengine.configuration.apiis not available.- Soft module dependencies (
#soft) are silently skipped if the module is not present inengine.modules; non-soft missing modules will raise aKeyErrorwhen accessed during proxy module collection.