server package¶
Subpackages¶
- server.events package
- server.resources package
- server.views_api package
- Submodules
- server.views_api.datafiles module
- server.views_api.device module
- server.views_api.experiment module
- server.views_api.other module
- server.views_api.session module
- server.views_api.user module
- server.views_api.usergroup module
- server.views_api.validations module
email_address_is_valid()get_device_metadata_errors()get_metadata_errors()get_password_errors()get_session_metadata_errors()ipv4_is_valid()name_is_valid()password_format_is_valid()password_is_secure()password_is_too_short()pretty_name_is_valid()role_is_valid()username_is_too_long()username_is_too_short()username_is_valid_format()
- server.views_main package
Submodules¶
server.blacklist_helpers module¶
- server.blacklist_helpers.add_token_to_database(encoded_token)[source]¶
Add a new token to the database. It is not revoked when it is added.
- server.blacklist_helpers.get_user_tokens(user_identity)[source]¶
Return all tokens belonging to given user.
- server.blacklist_helpers.revoke_all_tokens(user_identity)[source]¶
Revoke all tokens belonging to given user.
- server.blacklist_helpers.revoke_token(token_id, user)[source]¶
Revoke token. If it does not exist in database, raise TokenNotFound.
server.config module¶
server.exceptions module¶
- exception server.exceptions.ItemMustHaveId[source]¶
Bases:
PyplasError
- exception server.exceptions.NonexistentDevice[source]¶
Bases:
PyplasError
- exception server.exceptions.NonexistentSid[source]¶
Bases:
PyplasError
- exception server.exceptions.TokenNotFound[source]¶
Bases:
PyplasErrorToken cannot be found in database.
- exception server.exceptions.UniqueIdConflict[source]¶
Bases:
PyplasError
server.functions module¶
server.models module¶
- class server.models.Experiment(**kwargs)[source]¶
Bases:
Model- devices¶
- id¶
- id_public¶
- name¶
- sessions¶
- class server.models.Session(**kwargs)[source]¶
Bases:
Model- classmethod all_active(user=None, device=None)[source]¶
Get active sessions belonging to a user and/or device. If neither user nor device is specified, return all active sessions.
- Parameters:
user – server.models.User or None
device – server.models.Device or None
- Returns:
set of server.models.Session
- begin¶
- end¶
- experiment¶
- experiment_id¶
- id¶
- id_public¶
- name¶
- users¶
- class server.models.Token(**kwargs)[source]¶
Bases:
Model- expires¶
- id¶
- jti¶
- revoked¶
- token_type¶
- user_identity¶
- class server.models.User(**kwargs)[source]¶
Bases:
Model- email¶
- id¶
- id_public¶
- property is_admin¶
- password¶
- role¶
- sessions¶
- usergroups¶
- username¶
server.protections module¶
This file contains protections that are used for routes in API.
- server.protections.admin_required(f)[source]¶
Decorator: accept when authenticated and role == admin.
- server.protections.admin_required_sio(f)[source]¶
Event decorator: accept authenticated users with role admin.
- server.protections.content_json(mandatory_keys)[source]¶
Endpoint decorator: Make sure content is application/json and json contains mandatory keys. Otherwise return with error status code.
- server.protections.device_required_sio(f)[source]¶
Event decorator: accept authenticated devices. Corresponding Device object (queried from database) is passed as a first argument to the decorated func.
server.proxy_helpers module¶
- server.proxy_helpers.real_remote_addr()[source]¶
Returns the real remote IP address. Uses BEHIND_PROXY config setting.
When the app is not behind a proxy (BEHIND_PROXY==None), the returned address is just request.remote_addr. Otherwise, the real address must be retrieved from a special header set by the proxy service.
server.serverlogging module¶
- class server.serverlogging.SlackHandler(token, channel)[source]¶
Bases:
HandlerSend messages or files to a Slack channel. To send a file, specify the path to the file as a file attribute:
slacklog.info(“Sending file”, extra={“file”: “path/to/file.txt”})
- class server.serverlogging.TimedSummaryFilter(interval=10, levels=[20])[source]¶
Bases:
FilterThis can deal with very frequent records from libraries like socketio.
- Start timer, intercept everything with specified level.
count identical records (identical: levelno & message & args)
let first through, drop any subsequent (i.e. infrequent records are not affected)
- Timer finishes, make a summary and log it.
log the counts (minus the first one) per each record entry
restart timer, continue with step 1.