From 020a3ccea1522aa456705b9e37b135396f293495 Mon Sep 17 00:00:00 2001
From: W13R <9070224-W13R@users.noreply.gitlab.com>
Date: Sat, 28 May 2022 19:38:40 +0200
Subject: [PATCH 1/6] Removed old tests directory
---
tests/lib/__init__.py | 18 -------
tests/test-database-stability.py | 84 --------------------------------
2 files changed, 102 deletions(-)
delete mode 100644 tests/lib/__init__.py
delete mode 100644 tests/test-database-stability.py
diff --git a/tests/lib/__init__.py b/tests/lib/__init__.py
deleted file mode 100644
index 3da5d92..0000000
--- a/tests/lib/__init__.py
+++ /dev/null
@@ -1,18 +0,0 @@
-
-def parse_config_from_file(filepath):
-
- config = {}
-
- with open(filepath, "r") as f:
- lines = f.readlines()
- for line in lines:
- line = line.lstrip(" ").replace("\n", "")
- if line.startswith("export "):
- line = line.replace("export ", "").lstrip(" ")
- varname = line[:line.find("=")]
- varvalue = line[line.find("=")+1:]
- if varvalue.startswith("'"): varvalue = varvalue.strip("'")
- elif varvalue.startswith('"'): varvalue = varvalue.strip('"')
- config[varname] = varvalue
-
- return config
diff --git a/tests/test-database-stability.py b/tests/test-database-stability.py
deleted file mode 100644
index 228bb97..0000000
--- a/tests/test-database-stability.py
+++ /dev/null
@@ -1,84 +0,0 @@
-#!/usr/bin/env python3
-
-import os, sys
-
-from pathlib import Path
-
-from psycopg2 import connect
-from psycopg2 import Error
-
-from lib import parse_config_from_file
-
-
-USER_ID = 2
-N_NEW_ORDER_ROWS = 1000000
-COMMIT_AFTER = 50
-AMOUNT_PER_ORDER = 1
-PRODUCT_NAME = "Wasser"
-DRINK_ID = 1
-
-
-if __name__ == "__main__":
-
-
- print("\nGetting config...")
-
- config_file = Path(Path(os.path.dirname(__file__)).parent / "config" / "config.sh").absolute()
-
- config = parse_config_from_file(config_file)
-
- print(f"Commit will be done after every {COMMIT_AFTER} rows.")
-
- x = input(f"Do you want to add {N_NEW_ORDER_ROWS} rows to the app_order table? (enter 'yes' to continue) ")
- try:
- if str(x) != "yes":
- exit()
- except ValueError:
- exit()
-
- try:
-
- print("\nConnecting to database...")
-
- conn = connect(
- user = config["PGDB_USER"],
- password = config["PGDB_PASSWORD"],
- host = config["PGDB_HOST"],
- port = config["PGDB_PORT"],
- database = config["PGDB_DB"]
- )
-
- cur = conn.cursor()
-
- for i in range(N_NEW_ORDER_ROWS):
-
- cur.execute(f"""
- insert into app_order (datetime, product_name, price_sum, content_litres, drink_id, user_id, amount)
- values (
- current_timestamp,
- '{PRODUCT_NAME}',
- 10.00,
- 0.5,
- {DRINK_ID},
- {USER_ID},
- {AMOUNT_PER_ORDER}
- )
- """)
-
- if i % COMMIT_AFTER == 0 and not i == 0:
- conn.commit()
- print(f"\nAdded {i} rows")
-
- conn.commit()
- print(f"\nAdded {N_NEW_ORDER_ROWS} rows")
-
- print("done with db setup.")
-
- except (Error, Exception) as err:
-
- print(f"An error occured while connecting to the database {config['PGDB_DB']} at {config['PGDB_HOST']}:\n{err}", file=sys.stderr)
-
- finally:
-
- cur.close()
- conn.close()
From 672f7d6a80d162be40f296a87b2ccc9a7fe4a52b Mon Sep 17 00:00:00 2001
From: W13R <9070224-W13R@users.noreply.gitlab.com>
Date: Sat, 28 May 2022 19:44:36 +0200
Subject: [PATCH 2/6] Update package names for pg_config and Python version in
docs
---
docs/Setup.md | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/docs/Setup.md b/docs/Setup.md
index f42ba70..caef81a 100644
--- a/docs/Setup.md
+++ b/docs/Setup.md
@@ -8,10 +8,11 @@ Before the actual setup, you have to satisfy the following dependencies:
### System
- `pg_config`
- - Fedora/RHEL/Ubuntu: `libpq-dev`
+ - Ubuntu: `libpq-dev`
+ - Fedora/RHEL: `libpq-devel`
- `Caddy` 2.4.3+ (HTTP Reverse Proxy & Static File Server)
- `gcc`, `gettext`
-- `Python` 3.9 with pip
+- `Python` 3.9+ with pip
- `Python` header files
- Fedora/RHEL: `python3-devel`
- Ubuntu: `python3-dev`
From 97462c78841d82c98a6e9daf160702c0118b84c3 Mon Sep 17 00:00:00 2001
From: W13R <9070224-W13R@users.noreply.gitlab.com>
Date: Sun, 29 May 2022 15:31:44 +0200
Subject: [PATCH 3/6] Rename example systemd service file
---
misc/{drinks-manager.service.sample => drinks-manager.service} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename misc/{drinks-manager.service.sample => drinks-manager.service} (100%)
diff --git a/misc/drinks-manager.service.sample b/misc/drinks-manager.service
similarity index 100%
rename from misc/drinks-manager.service.sample
rename to misc/drinks-manager.service
From df91a89cd5ec4415ec254ede873f2e387e1f7a83 Mon Sep 17 00:00:00 2001
From: W13R <9070224-W13R@users.noreply.gitlab.com>
Date: Sun, 29 May 2022 20:56:16 +0200
Subject: [PATCH 4/6] Updated docs
---
README.md | 4 ++--
docs/Configuration.md | 10 +++++-----
docs/Setup.md | 28 ++++++++++++++++------------
3 files changed, 23 insertions(+), 19 deletions(-)
diff --git a/README.md b/README.md
index d84db1e..27df4cf 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Drinks Manager (season 2)
-Note: This piece of software is tailored to my own needs.
+Note: This software is tailored to my own needs.
I probably won't accept feature requests, and don't recommend you
to use this software if this isn't exactly what you are looking for.
@@ -15,7 +15,7 @@ You have to bring your own PostgreSQL Database though.
## Setup, Installation, Updating and Dependencies
-You can find the latest releases [here](https://gitlab.com/W13R/drinks-manager/-/releases), but for Installation/Updating, you should consider using Git.
+You can find the latest releases [here](https://gitlab.com/W13R/drinks-manager/-/releases), but you should consider using Git to easily switch between versions.
For more information see [Setup](docs/Setup.md).
diff --git a/docs/Configuration.md b/docs/Configuration.md
index 239dde3..00d5933 100644
--- a/docs/Configuration.md
+++ b/docs/Configuration.md
@@ -1,14 +1,14 @@
# Configuration
-## Main Configuration
+## Main Configuration
-`./config/config.sh`
+`config/config.sh`
-There is no default configuration available, only a sample configuration with explanations.
+There is a sample configuration with explanations: [/config/config.sample.sh](/config/config.sample.sh)
-## Caddy Server Configuration
+## Caddy (Reverse Proxy & Static File Server)
-`./config/Caddyfile`
+[config/Caddyfile](/config/Caddyfile)
The default configuration should work out of the box, don't edit this file unless you know what you're doing.
diff --git a/docs/Setup.md b/docs/Setup.md
index caef81a..28805cb 100644
--- a/docs/Setup.md
+++ b/docs/Setup.md
@@ -20,7 +20,7 @@ Before the actual setup, you have to satisfy the following dependencies:
### Python Packages (pip)
-All required python packages are listed `in pip-dependencies.txt`
+All required python packages are listed in [pip-dependencies.txt](/pip-dependencies.txt)
You can install the required python packages with
```bash
@@ -32,9 +32,9 @@ You can install the required python packages with
You can get the latest version with git:
```
-git clone --branch release-x.x https://gitlab.com/W13R/drinks-manager.git
+git clone --branch release-x https://gitlab.com/W13R/drinks-manager.git
```
-(replace x.x with the latest version)
+(replace x with the latest version)
Alternatively, you can download the [latest release](https://gitlab.com/W13R/drinks-manager/-/releases) and extract the files to your prefered destination.
@@ -55,9 +55,9 @@ If you installed the application with git, you can run the following in the drin
```
git fetch
-git checkout x.x
+git checkout x
```
-(replace x.x with the new version)
+(replace x with the new version)
If you downloaded the application from the releases page, you can download the new release in the same manner, and overwrite the old files with the new ones.
@@ -69,16 +69,20 @@ Further upgrading-instructions may be provided in the Release Notes on the Relea
## III. Database
-This project is using PostgreSQL. You have to set up a database by yourself.
-The database must have the schema `public` (exists on a new database). Make shure that you create a database user with the necessary privileges to write to and read from the database (SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, CREATE, CONNECT):
+This project is using PostgreSQL. You have to set up a database:
```sql
--- connected to target database
-grant SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES on all tables in schema public to ;
-grant CREATE, CONNECT on database to ;
+create user drinksmanager password '';
+create database drinksmgr owner drinksmanager;
```
-You can configure your database connection in `config/config.sh`.
+After creating the user, you have to edit your `pg_hba.conf` (see https://www.postgresql.org/docs/current/auth-pg-hba-conf.html).
+Add the following line:
+```
+host drinksmgr drinksmanager 127.0.0.1/32 md5
+```
+
+Now you can configure your database connection in `config/config.sh`.
## IV. HTTPS & TLS Certificates
@@ -89,7 +93,7 @@ Filepaths:
- `config/tls/server.pem` for the certificate
- `config/tls/server-key.pem` for the key
-You can set another filepath for those files in your caddy configuration at `config/Caddyfile`.
+You can set another filepath for those files in your caddy configuration at [config/Caddyfile](/config/Caddyfile).
## V. Configuration
From 6ca7f70a2e252065c562471c7aadd9b9c53c6477 Mon Sep 17 00:00:00 2001
From: W13R <9070224-W13R@users.noreply.gitlab.com>
Date: Sun, 29 May 2022 20:56:50 +0200
Subject: [PATCH 5/6] Updated sample config
---
config/config.sample.sh | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/config/config.sample.sh b/config/config.sample.sh
index d82100a..51aa8f0 100644
--- a/config/config.sample.sh
+++ b/config/config.sample.sh
@@ -1,15 +1,15 @@
# environment variables
-export HTTP_PORT=80 # required by caddy, will be redirected to https
-export HTTPS_PORT=443 # actual port for webinterface
+export HTTP_PORT=80 # required by caddy, will be redirected to https
+export HTTPS_PORT=443 # actual port for the webinterface
export DJANGO_PORT=8001 # caddy's http port (should be blocked by the firewall)
export DJANGO_SESSION_COOKIE_AGE=600 # auto-logout, in seconds
-export SESSION_CLEAR_INTERVAL=120 # interval for automatic session clearing, in minutes
+export SESSION_CLEAR_INTERVAL=120 # interval for automatic session clearing, in minutes
-export DJANGO_LANGUAGE_CODE="en" # the default and fallback language. Currently only de and en are supported.
-export DJANGO_TIME_ZONE="CET"
+export DJANGO_LANGUAGE_CODE="en" # the default and fallback language, currently only de and en are supported.
+export DJANGO_TIME_ZONE="CET" # your timezone
export CURRENCY_SUFFIX="$" # if you have another currency symbol, you can specify it here
@@ -18,10 +18,10 @@ export CURRENCY_SUFFIX="$" # if you have another currency symbol, you can specif
export DJANGO_ENABLE_PASSWORD_VALIDATION="true"
# database connection (postgresql)
-export PGDB_DB="" # The name of the databae
+export PGDB_DB="" # The name of the database
export PGDB_USER="" # The database user
export PGDB_PASSWORD='' # The password for the database user
-export PGDB_HOST="" # The hostname of your database (e.g. example.org or 127.0.0.1)
+export PGDB_HOST="127.0.0.1" # The hostname of your database
export PGDB_PORT=5432 # The port your database is listening on
# log files
From 5d96558451caf063fd2b3dcde5f6d4251a8746d7 Mon Sep 17 00:00:00 2001
From: W13R <9070224-W13R@users.noreply.gitlab.com>
Date: Sun, 29 May 2022 20:57:38 +0200
Subject: [PATCH 6/6] Bump version to 7
---
lib/env.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/env.sh b/lib/env.sh
index 5c3bf23..b49cbd4 100644
--- a/lib/env.sh
+++ b/lib/env.sh
@@ -2,5 +2,5 @@
export DJANGO_SK_ABS_FP="$(pwd)/config/secret_key.txt"
export STATIC_FILES="$(pwd)/static/"
-export APP_VERSION="6"
+export APP_VERSION="7"
export PYTHONPATH="$(pwd)/packages/"