EngineConfiguration_ObjectStorageService
What it is
Pydantic-based configuration models and loaders for wiring an ObjectStorageService with a selectable object storage adapter (fs, s3, naas, or custom).
Public API
ObjectStorageAdapterFSConfiguration- Filesystem adapter config model.
- Fields:
base_path: str
ObjectStorageAdapterS3Configuration- S3 adapter config model.
- Fields:
bucket_name: str,base_prefix: str,access_key_id: str,secret_access_key: str,session_token: str|None,endpoint_url: str|None
ObjectStorageAdapterNaasConfiguration- Naas adapter config model.
- Fields:
naas_api_key: str,workspace_id: str,storage_name: str,base_prefix: str = ""
ObjectStorageAdapterConfiguration(inheritsGenericLoader)- Selects and instantiates an adapter implementation.
- Fields:
adapter: Literal["fs", "s3", "naas", "custom"]config: Union[...config models...] | None
- Methods:
validate_adapter() -> Self: validatesconfigmatches the selected adapter (and is present unlessadapter="custom").load() -> IObjectStorageAdapter: returns an instantiated adapter.
ObjectStorageServiceConfiguration- Top-level service config wrapper.
- Fields:
object_storage_adapter: ObjectStorageAdapterConfiguration - Methods:
load() -> ObjectStorageService: constructsObjectStorageService(adapter=...).
Configuration/Dependencies
- Uses Pydantic v2 (
BaseModel,model_validator,ConfigDict(extra="forbid")). - Adapter selection:
adapter="fs"loadsObjectStorageSecondaryAdapterFSadapter="s3"loadsObjectStorageSecondaryAdapterS3adapter="naas"loadsObjectStorageSecondaryAdapterNaasadapter="custom"delegates toGenericLoader.load()(behavior defined inGenericLoader).
- Validation helper:
pydantic_model_validator(...)is used to ensureconfigconforms to the correct adapter config model. - All configuration models forbid unknown fields (
extra="forbid").
Usage
from naas_abi_core.engine.engine_configuration.EngineConfiguration_ObjectStorageService import (
ObjectStorageServiceConfiguration,
ObjectStorageAdapterConfiguration,
ObjectStorageAdapterFSConfiguration,
)
cfg = ObjectStorageServiceConfiguration(
object_storage_adapter=ObjectStorageAdapterConfiguration(
adapter="fs",
config=ObjectStorageAdapterFSConfiguration(base_path="storage/datastore"),
)
)
service = cfg.load() # ObjectStorageService with FS adapterCaveats
- If
adapter != "custom",configis required; otherwise anAssertionErroris raised. - If
adapterisfs/s3/naas,configmust match the corresponding config model or validation will fail. adapter="custom"requiresGenericLoader-specific configuration (not shown in this file).