ObjectStorageService
What it is
- A thin domain service wrapping an
IObjectStorageAdapter. - Normalizes object prefixes by stripping a leading
storage/to avoid creating an extrastoragefolder (notably with filesystem-backed adapters).
Public API
Class: ObjectStorageService(adapter: IObjectStorageAdapter)
Implements IObjectStorageDomain and delegates operations to the provided adapter.
Methods
get_object(prefix: str, key: str) -> bytes- Returns object content for
prefix/keyvia the adapter after prefix normalization.
- Returns object content for
put_object(prefix: str, key: str, content: bytes) -> None- Stores
contentatprefix/keyvia the adapter after prefix normalization.
- Stores
delete_object(prefix: str, key: str) -> None- Deletes
prefix/keyvia the adapter after prefix normalization.
- Deletes
list_objects(prefix: str = "", queue: Optional[Queue] = None) -> list[str]- Lists objects under
prefixvia the adapter after prefix normalization. - Special case: if normalized
prefix == "/", it is converted to""before delegation.
- Lists objects under
Configuration/Dependencies
- Requires an implementation of
IObjectStorageAdapter(fromnaas_abi_core.services.object_storage.ObjectStoragePort). - Optional dependency for
list_objects: aqueue.Queueinstance passed through to the adapter.
Usage
from naas_abi_core.services.object_storage.ObjectStorageService import ObjectStorageService
# adapter must implement IObjectStorageAdapter (not shown here)
adapter = ... # e.g., filesystem/S3 adapter implementation
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 only removes a leading
"storage/". Other occurrences are not altered. list_objects()treats"/"as the empty prefix ("").