diff --git a/README.md b/README.md index 7f5b6f82c3995a927d4e305ededd056e220eb3ca..badfd958dc02ac30eadc8c46aad28e2b0ef248a0 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ - [Getting started](#getting-started) - [Requirements](#requirements) - [Installation](#installation) + - [Setting up the database](#setting-up-the-database) - [Configuration](#configuration) - [Engine 1 Node](#engine-1-node) - [Engine 2 Node](#engine-2-node) @@ -115,8 +116,10 @@ The most simple way to get started is by running Engine API using [Docker](https If you are not planning to go with Docker or just want to setup a local development environment, then you'll need: - [Python 3.8+](https://www.python.org/) -- [MariaDB](https://mariadb.org/) -- [Virtualenv](https://virtualenv.pypa.io/en/latest/) +- [`pip`](https://pip.pypa.io/en/stable/) +- [`git`](https://git-scm.com/) +- [PostgreSQL 13+](https://www.postgresql.org/) or [MariaDB 10+](https://mariadb.org/) +- [Virtualenv](https://virtualenv.pypa.io/en/latest/) (Optional, development only) ### Installation @@ -136,12 +139,30 @@ Install the required dependencies ```bash pip3 install -r requirements.txt -# Additional requirements for the chosen database +``` + +#### Setting up the database + +The primary database supported by AURA is PostgreSQL. + +```bash +# Additional Python packages for PostgreSQL +pip3 install -r contrib/postgresql-requirements.txt +# Create database and user (change password in script) +sudo -u postgres psql -f contrib/postgresql-create-database.sql +``` + +Alternatively you can also use MariaDB: + +```bash +# Additional Python packages for MariaDB pip3 install -r contrib/mariadb-requirements.txt # Create database and user (change password in script) sudo mysql -u root -p < contrib/mariadb-database.sql ``` +You might want to change the password for the database user created by the relevant script. + ### Configuration Copy the sample configuration file in `./config/sample/sample-production.engine-api` to `config` and edit the file. diff --git a/config/sample/sample-development.engine-api.ini b/config/sample/sample-development.engine-api.ini index faebbb637f2cc6cd680c0d6689ccaddfe2d74cf2..29ac7003cbd94d668c91344879f6b10acb3ece75 100644 --- a/config/sample/sample-development.engine-api.ini +++ b/config/sample/sample-development.engine-api.ini @@ -5,8 +5,10 @@ [database] -db_user="aura" +# Use 'postgresql' or 'mysql' +db_type="postgresql" db_name="aura_engine_api" +db_user="aura_engine_api" db_pass="---SECRET--PASSWORD---" db_host="localhost" db_charset="utf8" @@ -26,7 +28,7 @@ api_cors="*" enable_federation="false" # Defines the engine number id for identification of record sources. Default values are: -# +# # 1 ... Engine 1 (main node) # 2 ... Engine 2 (main node, not needed for single deployment) # 0 ... Sync Host (sync node, not needed for single engine deployment) diff --git a/config/sample/sample-docker.engine-api.ini b/config/sample/sample-docker.engine-api.ini index 084980e6a77d0e45d0103fdf5d45d39813771b5b..f18d26ae7e1c36c39c9b4e9be7a36e14668f11a6 100644 --- a/config/sample/sample-docker.engine-api.ini +++ b/config/sample/sample-docker.engine-api.ini @@ -5,8 +5,10 @@ [database] -db_user="aura" +# Use 'postgresql' or 'mysql' +db_type="postgresql" db_name="aura_engine_api" +db_user="aura_engine_api" db_pass="---SECRET--PASSWORD---" db_host="localhost" db_charset="utf8" @@ -26,7 +28,7 @@ api_cors="*" enable_federation="false" # Defines the engine number id for identification of record sources. Default values are: -# +# # 1 ... Engine 1 (main node) # 2 ... Engine 2 (main node, not needed for single deployment) # 0 ... Sync Host (sync node, not needed for single engine deployment) diff --git a/config/sample/sample-production.engine-api.ini b/config/sample/sample-production.engine-api.ini index 919c2fe7b7032d7272913bccbc70f37957a81ab2..85d67deb9b9f638a1d4ed28848137dce2842b049 100644 --- a/config/sample/sample-production.engine-api.ini +++ b/config/sample/sample-production.engine-api.ini @@ -5,8 +5,10 @@ [database] -db_user="aura" +# Use 'postgresql' or 'mysql' +db_type="postgresql" db_name="aura_engine_api" +db_user="aura_engine_api" db_pass="---SECRET--PASSWORD---" db_host="localhost" db_charset="utf8" @@ -26,7 +28,7 @@ api_cors="*" enable_federation="false" # Defines the engine number id for identification of record sources. Default values are: -# +# # 1 ... Engine 1 (main node) # 2 ... Engine 2 (main node, not needed for single deployment) # 0 ... Sync Host (sync node, not needed for single engine deployment) diff --git a/contrib/postgresql-create-database.sql b/contrib/postgresql-create-database.sql new file mode 100644 index 0000000000000000000000000000000000000000..8926681fee263c3fc704ef1f730827a68410eaac --- /dev/null +++ b/contrib/postgresql-create-database.sql @@ -0,0 +1,4 @@ +\c postgres +create database aura_engine_api; +create user aura_engine_api with encrypted password '1234'; +grant all privileges on database aura_engine_api to aura_engine_api; diff --git a/contrib/postgresql-create-test-databases.sql b/contrib/postgresql-create-test-databases.sql new file mode 100644 index 0000000000000000000000000000000000000000..e668df8297dad16f476ffdd9eec8f0a69eab475a --- /dev/null +++ b/contrib/postgresql-create-test-databases.sql @@ -0,0 +1,8 @@ +\c postgres +create database aura_engine_api_0; +create database aura_engine_api_1; +create database aura_engine_api_2; +create user aura_engine_api with encrypted password '1234'; +grant all privileges on database aura_engine_api_0 to aura_engine_api; +grant all privileges on database aura_engine_api_1 to aura_engine_api; +grant all privileges on database aura_engine_api_2 to aura_engine_api; diff --git a/contrib/postgresql-requirements.txt b/contrib/postgresql-requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..4ae932dc8afb1225f6d1367cd0373c26ed54076a --- /dev/null +++ b/contrib/postgresql-requirements.txt @@ -0,0 +1 @@ +psycopg2-binary==2.8.6 \ No newline at end of file diff --git a/src/base/config.py b/src/base/config.py index 41cca870ddf73fdd1996e34a9575fa5248180795..e6a1d77891c00898e4a4f05c34574e04909bde11 100644 --- a/src/base/config.py +++ b/src/base/config.py @@ -27,16 +27,16 @@ from configparser import ConfigParser class AuraConfig: - """ + """ AuraConfig Class - + Holds the Aura Configuration as in the file `engine-api.ini`. """ ini_path = "" logger = None - def __init__(self, ini_path="/etc/aura/engine-api.ini"): + def __init__(self, ini_path="/etc/aura/engine-api.ini"): """ Initializes the configuration, defaults to `/etc/aura/engine.ini`. If this file doesn't exist it uses `./config/engine.ini` from @@ -151,5 +151,11 @@ class AuraConfig: db_user = str(self.get("db_user")) db_pass = str(self.get("db_pass")) db_host = str(self.get("db_host")) + db_type = str(self.get("db_type")) db_charset = self.get("db_charset", "utf8") - return "mysql://" + db_user + ":" + db_pass + "@" + db_host + "/" + db_name + "?charset=" + db_charset \ No newline at end of file + if db_type == "mysql": + return "mysql://" + db_user + ":" + db_pass + "@" + db_host + "/" + db_name + "?charset=" + db_charset + elif db_type == "postgresql": + return f"postgresql+psycopg2://{db_user}:{db_pass}@{db_host}/{db_name}?client_encoding={db_charset}" + else: + return f"Error: invalid database type '{db_type}'" \ No newline at end of file