swh.objstorage.proxies.readonly module#
- class swh.objstorage.proxies.readonly.ReadOnlyProxyObjStorage(storage: ObjStorageInterface | Dict, **kwargs)[source]#
Bases:
ObjStorageFilter that disable write operation of the storage.
Writes will always succeed without doing any actual write operations.
- name: str = 'read-only'#
Default objstorage name; can be overloaded at instantiation time giving a ‘name’ argument to the constructor
- get(obj_id, *args, **kwargs)[source]#
Retrieve the content of a given object.
- Parameters:
obj_id – object id.
- Returns:
the content of the requested object as bytes.
- Raises:
ObjNotFoundError – if the requested object is missing.
- get_batch(obj_ids: Iterable[HashDict]) Iterator[bytes | None][source]#
Retrieve objects’ raw content in bulk from storage.
Note: This function does have a default implementation in ObjStorage that is suitable for most cases.
For object storages that needs to do the minimal number of requests possible (ex: remote object storages), that method can be overridden to perform a more efficient operation.
- Parameters:
obj_ids – list of object ids.
- Returns:
list of resulting contents, or None if the content could not be retrieved. Do not raise any exception as a fail for one content will not cancel the whole request.
- download_url(obj_id: HashDict, content_disposition: str | None = None, expiry: timedelta | None = None) str | None[source]#
Get a direct download link for the object if the obstorage backend supports such feature.
Some objstorage backends, typically cloud based ones like azure or s3, can provide a direct download link for a stored object.
- Parameters:
obj_id – object identifier
content_disposition – set Content-Disposition header for the generated URL response if the objstorage backend supports it
expiry – the duration after which the URL expires if the objstorage backend supports it, if not provided the URL expires 24 hours after its creation
- Returns:
- Direct download URL for the object or
Noneif the objstorage backend does not support such feature.
- Direct download URL for the object or
- check(obj_id, *args, **kwargs)[source]#
Check if a content is found and recompute its hash to check integrity.
- check_config(*, check_write)[source]#
Check whether the object storage is properly configured.
- Parameters:
check_write (bool) – if True, check if writes to the object storage
succeed. (can)
- Returns:
True if the configuration check worked, False if ‘check_write’ is True and the object storage is actually read only, and an exception if the check failed.
- add(*args, **kwargs)[source]#
Add a new object to the object storage.
- Parameters:
content – object’s raw content to add in storage.
obj_id – dict of checksums.
check_presence (bool) – indicate if the presence of the content should be verified before adding the file.
- Returns:
the id (bytes) of the object into the storage.
- restore(*args, **kwargs)[source]#
Restore a content that have been corrupted.
This function is identical to add but does not check if the object id is already in the file system. The default implementation provided by the current class is suitable for most cases.
- Parameters:
content – object’s raw content to add in storage
obj_id – dict of hashes of the content (or only the sha1, for legacy clients)
- delete(*args, **kwargs)[source]#
Delete an object.
- Parameters:
obj_id – object identifier.
- Raises:
ObjNotFoundError – if the requested object is missing.