ibmfl.connection
¶
FL Connection¶
Flask Connection¶
Connection class which uses flask and request libraries to create a server client combo. All supported config combinations are shown below. connection:
name: FlaskConnection path: ibmfl.connection.flask_connection info:
ip: <ip> port: <port> headers:
‘Content-type’: ‘application/json’
- tls_config:
enable: true cert: <server.crt> key: <server.key> ca_cert: <ca.pem>
Headers and tls config both are optional. By default Content-type and Accept header are sent for every request. Additional headers can be added by changing the header section of info. TLS is by default False and can be enabled by switching adding tls_config to info section and assigning True. If certificates are not provided, adhoc ssl_context is assigned which uses Flask adhoc feature to generate certificates for connections. CA certificate is optional and should be provided if mutual authentication is required on both server and client side.
-
class
ibmfl.connection.flask_connection.
FlaskConnection
(config)[source]¶ -
__init__
(config)[source]¶ Initialized the connection object and validates the config provided to this connection instance
- Parameters
config (dict) – Dictionary of configuration provided to connection
-
get_connection_config
()[source]¶ Provide a connection information such that a node can communicate to other nodes on how to communicate with it.
- Returns
settings
- Return type
dict
-
get_ssl_config
(config)[source]¶ Loads tls config from connection config. Returns None when no config is provided :param config: Configuraiton sent from application :type config: dict
- Returns
ssl config
- Return type
dict
-
initialize_receiver
(router=None)[source]¶ Initialize flask server using the settings and handler.
- Parameters
router (Router) – Router object describing the routes for each request which are passed down to PH
-
initialize_sender
()[source]¶ Initialize simple http client using the settings provided during connection creation
-
Router¶
Module acting as a bridge between Server and ProtocolHandler Routes for all the requests received by the server are redirected to designated handler in PH using routers
-
class
ibmfl.connection.router_handler.
Router
[source]¶ Container used to add and match a group of routes.
-
__weakref__
¶ list of weak references to the object (if defined)
-
add_route
(path, handler)[source]¶ Add path, handler combination in a dictionary. Throws DuplicateRouteException when route is repeated
- Parameters
path – special pre defined /assigned identifier which will be used by the client to reach specific handler in the PH
handler – method which needs to handle the request carrying the special identifier
- Raises
DuplicateRouteException – exception is raised when path is added multiple times
-