lomas_server.utils package

Submodules

lomas_server.utils.anti_timing_att module

async lomas_server.utils.anti_timing_att.anti_timing_att(request: Request, call_next: Callable, config: Config) Response[source]

Anti-timing attack mechanism.

Changes the response time to either a minimum or by adding random noïse in order to avoid timing attacks.

Parameters:
  • request (Request) – The FastApi request.

  • call_next (Callable) – The FastApi endpoint to call.

  • config (Config) – The server config.

Returns:

The reponse from call_next.

Return type:

Response

lomas_server.utils.collection_models module

lomas_server.utils.config module

class lomas_server.utils.config.Config(*, develop_mode: bool, server: Server, submit_limit: float, admin_database: DBConfig, dataset_store: DatasetStoreConfig, dp_libraries: DPLibraryConfig)[source]

Bases: BaseModel

Server runtime config.

admin_database: DBConfig
dataset_store: DatasetStoreConfig
develop_mode: bool
dp_libraries: DPLibraryConfig
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'admin_database': FieldInfo(annotation=DBConfig, required=True), 'dataset_store': FieldInfo(annotation=DatasetStoreConfig, required=True), 'develop_mode': FieldInfo(annotation=bool, required=True), 'dp_libraries': FieldInfo(annotation=DPLibraryConfig, required=True), 'server': FieldInfo(annotation=Server, required=True), 'submit_limit': FieldInfo(annotation=float, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

server: Server
submit_limit: float
class lomas_server.utils.config.ConfigLoader[source]

Bases: object

Singleton object that holds the config for the server.

Initialises the config by calling load_config() with its default arguments.

The config can be reloaded by calling load_config with other arguments.

get_config() Config[source]

Get the config.

Returns:

The config.

Return type:

Config

load_config(config_path: str = '/usr/lomas_server/runtime.yaml', secrets_path: str = '/usr/lomas_server/secrets.yaml') None[source]

Loads the config and the secret data from disk, merges them and returns the config object.

Parameters:
  • config_path (str, optional) – The config filepath. Defaults to CONFIG_PATH.

  • secrets_path (str, optional) – The secrets filepath. Defaults to SECRETS_PATH.

Raises:

InternalServerException – If the config cannot be correctly interpreted.

set_config(config: Config) None[source]

Set the singleton’s config to config.

Parameters:

config (Config) – The new config.

class lomas_server.utils.config.DBConfig(*, db_type: str = <enum 'AdminDBType'>)[source]

Bases: BaseModel

BaseModel for database type config

db_type: str
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'db_type': FieldInfo(annotation=str, required=False, default=<enum 'AdminDBType'>)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class lomas_server.utils.config.DPLibraryConfig(*, opendp: OpenDPConfig)[source]

Bases: BaseModel

BaseModel for DP librairies config

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'opendp': FieldInfo(annotation=OpenDPConfig, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

opendp: OpenDPConfig
class lomas_server.utils.config.DatasetStoreConfig(*, ds_store_type: DatasetStoreType)[source]

Bases: BaseModel

BaseModel for dataset store configs

ds_store_type: DatasetStoreType
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'ds_store_type': FieldInfo(annotation=DatasetStoreType, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class lomas_server.utils.config.LRUDatasetStoreConfig(*, ds_store_type: DatasetStoreType, max_memory_usage: int)[source]

Bases: DatasetStoreConfig

BaseModel for dataset store configs in case of a LRU dataset store

max_memory_usage: int
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'ds_store_type': FieldInfo(annotation=DatasetStoreType, required=True), 'max_memory_usage': FieldInfo(annotation=int, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class lomas_server.utils.config.MongoDBConfig(*, db_type: str = <enum 'AdminDBType'>, address: str, port: int, username: str, password: str, db_name: str)[source]

Bases: DBConfig

BaseModel for dataset store configs in case of a MongoDB database

address: str
db_name: str
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'address': FieldInfo(annotation=str, required=True), 'db_name': FieldInfo(annotation=str, required=True), 'db_type': FieldInfo(annotation=str, required=False, default=<enum 'AdminDBType'>), 'password': FieldInfo(annotation=str, required=True), 'port': FieldInfo(annotation=int, required=True), 'username': FieldInfo(annotation=str, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

password: str
port: int
username: str
class lomas_server.utils.config.OpenDPConfig(*, contrib: bool, floating_point: bool, honest_but_curious: bool)[source]

Bases: BaseModel

BaseModel for openDP librairy config

contrib: bool
floating_point: bool
honest_but_curious: bool
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'contrib': FieldInfo(annotation=bool, required=True), 'floating_point': FieldInfo(annotation=bool, required=True), 'honest_but_curious': FieldInfo(annotation=bool, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class lomas_server.utils.config.Server(*, time_attack: TimeAttack, host_ip: str, host_port: int, log_level: str, reload: bool, workers: int)[source]

Bases: BaseModel

BaseModel for uvicorn server configs

host_ip: str
host_port: int
log_level: str
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'host_ip': FieldInfo(annotation=str, required=True), 'host_port': FieldInfo(annotation=int, required=True), 'log_level': FieldInfo(annotation=str, required=True), 'reload': FieldInfo(annotation=bool, required=True), 'time_attack': FieldInfo(annotation=TimeAttack, required=True), 'workers': FieldInfo(annotation=int, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

reload: bool
time_attack: TimeAttack
workers: int
class lomas_server.utils.config.TimeAttack(*, method: TimeAttackMethod, magnitude: float)[source]

Bases: BaseModel

BaseModel for configs to prevent timing attacks

magnitude: float
method: TimeAttackMethod
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'magnitude': FieldInfo(annotation=float, required=True), 'method': FieldInfo(annotation=TimeAttackMethod, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class lomas_server.utils.config.YamlDBConfig(*, db_type: str = <enum 'AdminDBType'>, db_file: str)[source]

Bases: DBConfig

BaseModel for dataset store configs in case of a Yaml database

db_file: str
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'db_file': FieldInfo(annotation=str, required=True), 'db_type': FieldInfo(annotation=str, required=False, default=<enum 'AdminDBType'>)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

lomas_server.utils.config.get_config() Config[source]

Get the config from the ConfigLoader Singleton instance.

Returns:

The config.

Return type:

Config

lomas_server.utils.error_handler module

exception lomas_server.utils.error_handler.ExternalLibraryException(library: str, error_message: str)[source]

Bases: Exception

Custom exception for issues within external libraries

This exception will occur when the processes fail within the external libraries (smartnoise-sql, opendp, diffprivlib)

exception lomas_server.utils.error_handler.InternalServerException(error_message: str)[source]

Bases: Exception

Custom exception for issues within server internal functionalities like unexpected match cases

exception lomas_server.utils.error_handler.InvalidQueryException(error_message: str)[source]

Bases: Exception

Custom exception for invalid queries

For example, this exception will occur when the query:
  • is not an opendp measurement

  • cannot be reconstructed properly (for opendp and diffprivlib)

exception lomas_server.utils.error_handler.UnauthorizedAccessException(error_message: str)[source]

Bases: Exception

Custom exception for unauthorized access: (unknown user, no access to dataset, etc)

lomas_server.utils.error_handler.add_exception_handlers(app: FastAPI) None[source]

Translates custom exceptions to JSONResponses. :param app: A fastapi App. :type app: FastAPI

lomas_server.utils.logger module

lomas_server.utils.query_examples module

lomas_server.utils.query_models module

Module contents