Skip to content

Commit

Permalink
[doc] cherrypy mentions substituted by fastAPI and its structure
Browse files Browse the repository at this point in the history
  • Loading branch information
hmaciasc committed Mar 15, 2024
1 parent 125e15a commit b5128cc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
3 changes: 1 addition & 2 deletions doc/system/access_control/access_control.tex
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ \subsection{Authorized IPs File}
The syntax for the pattern uses the asterisk to mean ``any''. For example: {\tt``local = 127.*.*.*''}

\subsection{Usage}
To add the authentication requisite to a method it is enough to add the {\tt@authenticate} decorator. It is important to add it
below the {\tt@cherrypy.expose} decorator. Otherwise the method will not be longer exposed.
To require IP validation in order to be able to reach an endpoint it is enough to add the dependency {\tt Depends(validate\_ip)} in the parameters of the decorator for each endpoint and import said method from ``guards.py''.
11 changes: 5 additions & 6 deletions doc/system/archive/archive.tex
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ \subsection{Introduction}
The archive module is a standalone application destined to communicate with other modules using webservices. It is designed to implement a stable, simple, and scalable system for archiving all experiments done with IPOL.

\paragraph{Technologies used} \hspace{0pt} \\
The archive module, written in Python, is using the Cherrypy framework for webservices, the Mako template library for webpage rendering, Python Image Library for thumbnails creations, and the python-magic library available on pip (not to be mistaken with python-magic5 which is the one available on the Ubuntu repositories). The module communicates using JSON, both in input and output. The database engine used is SQLite.
The archive module, written in Python, is using fastAPI for webservices, Python Image Library for thumbnails creations, and the python-magic library available on pip (not to be mistaken with python-magic5 which is the one available on the Ubuntu repositories). The module communicates using JSON, both in input and output. The database engine used is SQLite.

\subsection{Architecture}

\paragraph{Module composition} \hspace{0pt} \\
The module is composed of very few files, the code itself in ``module.py'', a cherrypy configuration file ``archive.conf'', and a database. It will also need four directories, respectively for storing blobs, thumbnails, the database, and logs.
The module is composed of very few files, the code itself in ``archive.py'', a ``router.py'', and a database.

\paragraph{Module architecture} \hspace{0pt} \\
The module is composed of a class, 'Archive', encapsulating the data needed to function. The services offered by the module are all methods of this class. The cherrypy framework provide the abstraction for making the methods available as webservices. \\
Upon starting the module, the cherrypy engine is launched, an object of the Archive class is created, and the cherrypy configuration is loaded from ``archive.conf''. If they don't exist, both the database and the directories needed for the storage of blobs, logs, the database and thumbnails will be created, provided that the user launching the module has the necessary rights. Otherwise, the module will not start. These directories are indicated in the cherrypy configuration for maximum configurability, if they are missing from it, the module will not start. \\
The webservices communicate with the server via arguments given through URL, as unicode strings directly passed to the methods. \\
The services all connect to the database in a thread-safe way, instanciating its own connection when called, commiting when done if there are modifications, or rollbacking, if there is an error, and closing the connection. \\
The module is composed of a class, 'Archive', encapsulating the data needed to function. The services offered by the module are all methods of this class. FastAPI will expose all archive http endpoints to make them available and take incoming requests. \\
Upon starting the core module, it will mount archive's router where all endpoints are defined. If they don't exist, both the database and the directories needed for the storage of blobs, logs, the database and thumbnails will be created in their corresponding locations specified in the ``config.py'' file, provided that the user launching the module has the necessary rights. Otherwise, the module will not start. These directories are indicated in the ``config.py'' file, if they are missing from it, the module will not start. \\
The services all connect to each database in a thread-safe way, instanciating its own connection when called, commiting when done if there are modifications, or rollbacking individual queries, if there is an error, and closing the connection. \\
There is a logger initialised with the Archive object, writing errors in ``error.log'' in the logs directory given in the configuration file.

\subsection{Database design}
Expand Down
8 changes: 4 additions & 4 deletions doc/system/blobs/blobs.tex
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ \section{The Blobs module}
\subsection{Introduction}
Each demo of IPOL offers to the user a set of defaults blobs (\textbf{b}inary \textbf{l}arge \textbf{o}bjects). Thus, the users are not forced to supply their own files for the executions of the algorithms. These defaults blobs can be tagged and linked to differents demos.

The blobs module is composed of several Python modules. It is composed of the same technical stack as the rest of the rest of the IPOL modules: written in Python, using a web server, a database, and using templates for generating HTML responses for webservices destinated to humans.
The blobs module is composed of several Python modules. It is composed of the same technical stack as the rest of the rest of the IPOL modules: written in Python, with fastAPI, mounts a router for every endpoind, a database, and using templates for generating HTML responses for webservices destinated to humans.

\subsection{Main}
The main module is called by ``start.sh'', the script called by the control terminal to get modules running on different servers over ssh. It consist of setting up some variables used by cherrypy, as well as mounting the blobs class at the root of the used server.
\subsection{Router}
Blobs router is mounted in ``app.py'' and depends on the Core module in order to run. This router will listen to all http requests destinated to blobs api.

\subsection{Error control}
This module describes the errors issued by the Blobs IPOL module and adds color to the error messages printed in the terminal.
Expand All @@ -34,7 +34,7 @@ \subsubsection{Database access}
\subsection{The Blobs module}
The blobs Python module is the core of this. It implement three classes, DatabaseConnection as referenced earlier in the present documentation, and MyFieldStorage, for intermediate storage of the uploaded blobs in the /tmp/ directory, and Blobs as an encapsulation of the webservices and the data they use. It also has some utilitary function.

The Blobs class implements all the webservices constituting this module, as well as web pages generated via HTML templates. An instance of the Blobs class should possess information about the storage of blobs and the networking parameters cherrypy use, such as a port number. A cherrypy configuration file, named ``blobs.conf'' contains the informations one might need to change to run the module on another server, without changing the code, such as the directories where the blobs can be found, the port used by the cherrypy engine, or the path to the database.
The Blobs class implements all methods needed to create, update and remove blobs and templates in relation to demos.

The webservices of the module access the database via instanciations of Database objects managed by the DatabaseConnection class. Some read information, and some modify the database by adding or removing information. For handling a webservice automatically and charging his JSON response as a Python object, the utilitary function use\_web\_service is used.

Expand Down
3 changes: 1 addition & 2 deletions doc/system/conversion/conversion.tex
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ \subsection{Introduction}
\paragraph{Technologies} \hspace{0pt} \\
\begin{itemize}
\item Python (with packages available from PIP)
\item cherrypy (framework for webservices)
\item simplejson (required by cherrypy, JSON is the syntax to communicate with the module)
\item fastAPI (web framework for building APIs with Python)
\item opencv-python (Python binding for the image processing library OpenCV, used for images and video)
\item tifffile (a Python binding for the libtiff library, used to load and save images in tiff format)
\item numpy (a Python library for matrix calculation, used to modify image data)
Expand Down

0 comments on commit b5128cc

Please sign in to comment.