swh.objstorage.backends.noop module#

class swh.objstorage.backends.noop.NoopObjStorage(*, allow_delete: bool = False, **kwargs)[source]#

Bases: ObjStorage

Noop objstorage. Basic implementation which does no operations at all.

Only intended for test purposes to avoid either memory or i/o operations. This allows swh clients to use the swh stack without having to deal with objstorage configuration. So users can concentrate on testing the remaining part of the stack without the objstorage.

name: str = 'noop'#

Default objstorage name; can be overloaded at instantiation time giving a ‘name’ argument to the constructor

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(content, obj_id, check_presence=True, *args, **kwargs)[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.

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.

check(obj_id, *args, **kwargs)[source]#

Check if a content is found and recompute its hash to check integrity.

delete(obj_id, *args, **kwargs)[source]#

Delete an object.

Parameters:

obj_id – object identifier.

Raises:

ObjNotFoundError – if the requested object is missing.