ourobori.services package

Submodules

ourobori.services.errors module

This module contains all exceptions used in services based on the ourobori. Additional service specific exceptions have to be defined in the errors.py-file of the service and be defined in the service rules.py-file in Rules.handle_exceptions.

exception ourobori.services.errors.BaseError(status=NotImplemented, data=NotImplemented, description=NotImplemented)[source]

Bases: Exception

The base-exception all custom-exceptions have to inherit from.

status

This attribute has to be defined in an exception inheriting from this class. It represents the http-status-code to return to the client on raise of the exception.

data

This attribute has to be defined in an exception inheriting from this class. It contains a dict with the message (msg) to return to the client on raise of the exception. Additional keys can be passed, too.

description

The description for the exception.

exception ourobori.services.errors.DatabaseNotAliveException(status=503, data={'msg': 'Database {name} is not alive. Please contact support'}, description='Database {name} at {dsn} is not alive')[source]

Bases: ourobori.services.errors.BaseError

This exception is used inside the dependencies ourobori.apps.dependencies.dbs.PSQLDataBase

Inheritance

Inheritance diagram of DatabaseNotAliveException
status

It represents the http-status-code to return to the client on raise of the exception.

data

It contains a dict with the message (msg) to return to the client on raise of the exception.

description

The description for this exception.

exception ourobori.services.errors.DatabaseTransactionException(status=504, data={'msg': 'Database {name} transaction {transaction} not possible. Please contact support'}, description='Database {name} transaction {transaction} not possible. Err: {err}')[source]

Bases: ourobori.services.errors.BaseError

This exception is used inside the dependencies ourobori.apps.dependencies.dbs.PSQLDataBase

Inheritance

Inheritance diagram of DatabaseTransactionException
status

It represents the http-status-code to return to the client on raise of the exception.

data

It contains a dict with the message (msg) to return to the client on raise of the exception.

description

The description for this exception.

exception ourobori.services.errors.HostCmdException(status=505, data={'msg': 'Host {name} running command {cmd} not possible. Please contact support'}, description='Host {name} running command {cmd} not possible. Err: {err}')[source]

Bases: ourobori.services.errors.BaseError

This exception is used inside the dependencies ourobori.apps.dependencies.hosts.Host

Inheritance

Inheritance diagram of HostCmdException
status

It represents the http-status-code to return to the client on raise of the exception.

data

It contains a dict with the message (msg) to return to the client on raise of the exception.

description

The description for this exception.

exception ourobori.services.errors.HostConnectionException(status=508, data={'msg': 'Host {name} connecting to is not possible. Please contact support'}, description='Host {name} connecting to is not possible. Err: {err}')[source]

Bases: ourobori.services.errors.BaseError

This exception is used inside the dependencies ourobori.apps.dependencies.hosts.Host

Inheritance

Inheritance diagram of HostConnectionException
status

It represents the http-status-code to return to the client on raise of the exception.

data

It contains a dict with the message (msg) to return to the client on raise of the exception.

description

The description for this exception.

exception ourobori.services.errors.HostSCPFromException(status=506, data={'msg': 'Host {name} copying from is not possible. Please contact support'}, description='Host {name} copying from is not possible. Er: {err}')[source]

Bases: ourobori.services.errors.BaseError

This exception is used inside the dependencies ourobori.apps.dependencies.hosts.Host

Inheritance

Inheritance diagram of HostSCPFromException
status

It represents the http-status-code to return to the client on raise of the exception.

data

It contains a dict with the message (msg) to return to the client on raise of the exception.

description

The description for this exception.

exception ourobori.services.errors.HostSCPToException(status=507, data={'msg': 'Host {name} copying to is not possible. Please contact support'}, description='Host {name} copying to is not possible. Err: {err}')[source]

Bases: ourobori.services.errors.BaseError

This exception is used inside the dependencies ourobori.apps.dependencies.hosts.Host

Inheritance

Inheritance diagram of HostSCPToException
status

It represents the http-status-code to return to the client on raise of the exception.

data

It contains a dict with the message (msg) to return to the client on raise of the exception.

description

The description for this exception.

exception ourobori.services.errors.InvalidInputException(status=412, data={'msg': 'Invalid input data passed!'}, description='Invalid input data was passed to the api.')[source]

Bases: ourobori.services.errors.BaseError

This exception is used if invalid-input is passed to an api.

Inheritance

Inheritance diagram of InvalidInputException
status

It represents the http-status-code to return to the client on raise of the exception.

data

It contains a dict with the message (msg) to return to the client on raise of the exception.

description

The description for this exception.

exception ourobori.services.errors.InvalidOutputException(status=500, data={'msg': 'Please contact support'}, description='Invalid output created.')[source]

Bases: ourobori.services.errors.BaseError

This exception is used if the output created by the api is not valid.

Inheritance

Inheritance diagram of InvalidOutputException
status

It represents the http-status-code to return to the client on raise of the exception.

data

It contains a dict with the message (msg) to return to the client on raise of the exception.

description

The description for this exception.

exception ourobori.services.errors.ServiceCallException(status=501, data={'msg': 'Could not call service-dependency {name}. Please contact support'}, description='Could not call service-dependency {name} on api {api} with params {params}. Err: {err}')[source]

Bases: ourobori.services.errors.BaseError

This exception is used inside the dependencies ourobori.apps.dependencies.services.RestService

Inheritance

Inheritance diagram of ServiceCallException
status

It represents the http-status-code to return to the client on raise of the exception.

data

It contains a dict with the message (msg) to return to the client on raise of the exception.

description

The description for this exception.

exception ourobori.services.errors.ServiceNotAliveException(status=502, data={'msg': 'Service-dependency {name} is not alive. Please contact support'}, description='Service-dependency {name} is not alive')[source]

Bases: ourobori.services.errors.BaseError

This exception is used inside the dependencies ourobori.apps.dependencies.services.RestService

Inheritance

Inheritance diagram of ServiceNotAliveException
status

It represents the http-status-code to return to the client on raise of the exception.

data

It contains a dict with the message (msg) to return to the client on raise of the exception.

description

The description for this exception.

ourobori.services.http module

This module contains the ROUTES and basic apis to use for all http-services based on ourobori. The custom additional apis should be placed in the service.py-file of a service based on ourobori. This module also defines the BASE_APISPECS to be used in your service.py file to define the apispecs used by the creation of the swagger-definition at calling the ourobori.docs.swagger.create_swagger_definition(). Each service based on ourobori should also use the decorators ourobori.services.apis.decorators.transform_input() and ourobori.services.apis.decorators.transform_output() in its api-methods to transform the input- and output-data of your apis.

ourobori.services.http.ROUTES

The routes to be used by the aiohttp.web.Application for services using ourobori. Services using ourobori should use this route as their routes-definition and add additional routes to this route.

ourobori.services.http.BASE_APISPECS

The apispecs to use for the creation of the swagger-documentation. Includes the basic route ping. Services using ourobori should use this BASE_APISPECS and extend it with their additional swagger-definitions.

ourobori.services.http.api_ping(request)[source]

Basic ping-api using the decorators input_transform() and output_transform() to transform the input- and output-data from and to json. The decorator input-transform() adds two additional attributes to the request-object: request.api_id (the id for this api-call) and request.api_params (the extracted request-params).

Parameters:request – The request-object passed to this api-method
Returns:The result converted to json using SOPing
Return type:result

ourobori.services.logger module

ourobori use loguru to log. The logger to be used by the service is created using default_logger() defined in this module. The logger is called inside ourobori.apps.http._create_app() automatically so you only have to define the logfile_path where to log in your service-rules in rules.py or by passing the argument --logfile on service-start.

ourobori.services.logger.default_logger(*, mode, servicename, logfile_path, min_level='INFO', rotation='1 day', retention='1 month', debug=False, logstash_connection=None)[source]

Creates the logger based on loguru to be used inside a service using the ourobori. This function is called inside ourobori.apps.http.create_app(). The logfile_path is extracted from Rules-class inside the rules of the service.

Parameters:
  • mode – The runtime mode of the service
  • servicename – The name of the service
  • logfile_path – The folder where to store the logfiles.
  • min_level – The minimal log-level to log.
  • rotation – How to rotate the logiles.
  • retention – How long the logfiles will be kept.
  • debug – Flag if debugmode is on or not.
  • logstash_connection – The logstash-connection to use for communicate with logstash. Should be a dict containing the keys ‘host” and ‘port’.
Returns:

The logger used for logging inside the service based on the

ourobori.

Return type:

logger

ourobori.services.rules module

This module contains the base rules to be implemented as minimum in the Rules of a service using the ourobori. So the class Rules in your rules.py should inherit from the :class:BaseRules`. This module also contains the class CustomBasicAuth which is used when restricting the access to the service by as BasicAuth. This authentication has to be defined in your Rules-class in the attribute auths like the following:

class Rules(BaseRules):
    auths: CustomBasicAuth = CustomBasicAuth(
        valids=[('example_user', 'example_password')])

If you start your service with the flag --auth the BasicAuth-method defined there will be used.

class ourobori.services.rules.AuthenticatedUser(login, password)[source]

Bases: object

Class representing an authenticated user to gain access to the service via http-basic-authentication.

login
password
class ourobori.services.rules.BaseRules(servicename, port, version, description, contact, logfile, hostname, license=License(name='', url=''), auths=None, logstash_conn=None, apidoc_location=PosixPath('doc/ext/build/index.html'), client_apidoc_location=PosixPath('doc/int/build/index.html'), handle_exceptions=(<class 'ourobori.services.errors.DatabaseNotAliveException'>, <class 'ourobori.services.errors.DatabaseTransactionException'>, <class 'ourobori.services.errors.HostCmdException'>, <class 'ourobori.services.errors.HostConnectionException'>, <class 'ourobori.services.errors.HostSCPFromException'>, <class 'ourobori.services.errors.HostSCPToException'>, <class 'ourobori.services.errors.InvalidInputException'>, <class 'ourobori.services.errors.InvalidOutputException'>, <class 'ourobori.services.errors.ServiceCallException'>, <class 'ourobori.services.errors.ServiceNotAliveException'>))[source]

Bases: object

These rules are the minimal rules to implement in the Rules of a service using the ourobori.

servicename

The name of the service

port

The default port for the service to listen. Can be overwritten by the --port argument on service-startup.

version

The version of the service.

description

The description for the service.

contact

The contact-person for the service.

logfile

Path where to store the logfiles of the service. Can be overwritten by the --logfile argument on service-startup.

hostname

The hostname of the host this service is run.

license

The license for this service.

auths

The allowed users to access the service.

logstash_conn

The connection to logstash as <HOSTNANE>:<PORT>.

apidoc_location

The location of the built apidoc.

client_apidoc_location

The location of the built client-apidoc.

handle_exceptions

The exceptions to handle in the error-middleware at ourobori.apps.middlewares.error_middleware(). The defined exceptions have to inherit from ourobori.services.errors.BaseError.

apidoc_location
auths
client_apidoc_location
contact
description
handle_exceptions
hostname
license
logfile
logstash_conn
port
servicename
version
class ourobori.services.rules.CustomBasicAuth(valids, username=None, password=None, force=True, realm='')[source]

Bases: aiohttp_basicauth.BasicAuthMiddleware

Class to be used as middleware for basic-http-authentication to the service.

check_credentials(username, password)[source]

Checks if the user-password-combination is allowed to access the service.

Parameters:
  • username – The username to check in combination with the password
  • password – The password to check in combination with the username
Returns:

Check if the username-password-combination is allowed to

access the service.

Return type:

valid

password = None
username = None

Module contents