ObjectStorageService
What it is
- A domain service that wraps an
IObjectStorageAdapterto provide object storage operations. - Normalizes
prefixvalues by stripping a leading"storage/"(primarily for filesystem-backed adapters) before delegating to the adapter.
Public API
Class: ObjectStorageService(adapter: IObjectStorageAdapter)
- Purpose: Provide a stable object storage domain interface backed by a pluggable adapter.
Methods
get_object(prefix: str, key: str) -> bytes- Fetch an object’s raw bytes via the adapter (after prefix normalization).
put_object(prefix: str, key: str, content: bytes) -> None- Store object bytes via the adapter (after prefix normalization).
delete_object(prefix: str, key: str) -> None- Delete an object via the adapter (after prefix normalization).
list_objects(prefix: str = "", queue: Optional[Queue] = None) -> list[str]- List object keys via the adapter (after prefix normalization).
- If
prefix == "/", it is converted to"". - Optionally accepts a
queue.Queueto pass through to the adapter.
get_object_metadata(prefix: str, key: str) -> ObjectMetaData- Return object metadata via the adapter.
- Note: This method does not apply the
"storage/"prefix normalization.
Configuration/Dependencies
- Requires an implementation of
IObjectStorageAdapterfromnaas_abi_core.services.object_storage.ObjectStoragePort. - Uses:
queue.Queue(optional parameter forlist_objects)ObjectMetaDatatype for metadata returns
- Inherits from
ServiceBaseand implementsIObjectStorageDomain.
Usage
from naas_abi_core.services.object_storage.ObjectStorageService import ObjectStorageService
# adapter must implement IObjectStorageAdapter
adapter = ... # e.g., filesystem/S3 adapter provided elsewhere
svc = ObjectStorageService(adapter)
svc.put_object("storage/my-prefix", "hello.txt", b"hello")
data = svc.get_object("storage/my-prefix", "hello.txt")
keys = svc.list_objects("storage/my-prefix")
svc.delete_object("storage/my-prefix", "hello.txt")
Caveats
- Prefix normalization (
"storage/"removal and"/"→"") is applied toget_object,put_object,delete_object, andlist_objects, but not toget_object_metadata. Ensure you pass the correctprefixformat for metadata calls.