swh.objstorage.backends.http module#
- class swh.objstorage.backends.http.HTTPReadOnlyObjStorage(url=None, compression: Literal['bz2', 'lzma', 'gzip', 'zlib', 'none'] = 'none', **kwargs)[source]#
Bases:
ObjStorage
Simple ObjStorage retrieving objects from an HTTP server.
For example, can be used to retrieve objects from S3:
objstorage: cls: http url: https://softwareheritage.s3.amazonaws.com/content/
Retry strategy can be defined via the ‘retry’ configuration, e.g.:
objstorage: cls: http url: https://softwareheritage.s3.amazonaws.com/content/ retry: total: 5 backoff_factor: 0.2 status_forcelist: - 404 - 500
See https://urllib3.readthedocs.io/en/stable/reference/urllib3.util.html#urllib3.util.Retry for more details on the possible configuration entries.
- name: str = 'http'#
Default objstorage name; can be overloaded at instantiation time giving a ‘name’ argument to the constructor
- add(content: bytes, obj_id: ObjId, check_presence: bool = True) None [source]#
Add a new object to the object storage.
- Parameters:
content – object’s raw content to add in storage.
obj_id – either dict of checksums, or single checksum of [bytes] using [ID_HASH_ALGO] algorithm. It is trusted to match the bytes.
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.
- delete(obj_id: ObjId)[source]#
Delete an object.
- Parameters:
obj_id – object identifier.
- Raises:
ObjNotFoundError – if the requested object is missing.
- restore(content: bytes, obj_id: ObjId) None [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)
- list_content(last_obj_id: ObjId | None = None, limit: int | None = 10000) Iterator[ObjId] [source]#
Generates known object ids.
- Parameters:
last_obj_id – object id from which to iterate from (excluded).
limit (int) – max number of object ids to generate. If unset (None), generate all objects (behavior might not be guaranteed for all backends).
- Generates:
obj_id: object ids.
- get(obj_id: ObjId) bytes [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.
- download_url(obj_id: ObjId, 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
None
if the objstorage backend does not support such feature.
- Direct download URL for the object or