Skip to content

Commit c52f837

Browse files
committed
polishing the first release 1.0
1 parent e31dcff commit c52f837

File tree

20 files changed

+97
-67
lines changed

20 files changed

+97
-67
lines changed

README.md

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ This is aimed at Hash Kennels to announce runs which then can be consumed
66
by [Harrier Central](https://www.harriercentral.com)
77

88
## Requirements
9+
You need to have a running Wordpress site with 'WP Event Manager' Plugin installed.
10+
911
### Software
1012
* python >= 3.6
1113
* starlette
@@ -20,22 +22,22 @@ by [Harrier Central](https://www.harriercentral.com)
2022
### WP Event Manager Plugin
2123
* WP Event Manager >= 3.1.21
2224

23-
# Installing
25+
## Installing
2426
* here we assume we install in ```/opt```
2527

26-
## RedHat based OS
28+
### RedHat based OS
2729
* on RedHat/CentOS 7 you need to install python3.6 and pip from EPEL first
2830
* on RHEL/Rocky Linux 8 systems the package name changed to `python3-pip`
2931
```shell
3032
yum install python36-pip
3133
```
3234

33-
## Ubuntu 18.04 & 20.04
35+
### Ubuntu 18.04 & 20.04
3436
```shell
3537
apt-get update && apt-get install python3-venv
3638
```
3739

38-
## Clone repo and install dependencies
40+
### Clone repo and install dependencies
3941
* download and setup of virtual environment
4042
```shell
4143
cd /opt
@@ -46,7 +48,7 @@ python3 -m venv .venv
4648
pip3 install -r requirements.txt || pip install -r requirements.txt
4749
```
4850

49-
## Install as systemd service
51+
### Install as systemd service
5052
If files have been installed in a different directory then the systemd service file
5153
needs to be edited.
5254

@@ -66,7 +68,7 @@ systemctl start wordpress-hash-event-api
6668
systemctl enable wordpress-hash-event-api
6769
```
6870

69-
## Install as OpenRC service
71+
### Install as OpenRC service
7072
The [uvicorn.confd](contrib/uvicorn.confd) config file needs to be copied to `/etc/conf.d/`.
7173
Let's assume the API is called `nerd-h3`.
7274
```shell
@@ -90,7 +92,7 @@ is finished the service can be started.
9092
rc-update add uvicorn.nerd-h3 default
9193
```
9294

93-
## Docker
95+
### Docker
9496

9597
Run the application in docker container
9698

@@ -99,31 +101,36 @@ Run the application in docker container
99101

100102
```
101103
docker build -t wordpress-hash-event-api .
102-
docker run --rm -it -v $(pwd)/config.ini:/app/settings.ini wordpress-hash-event-api
104+
docker run --rm -it -v $(pwd)/config.ini:/app/config.ini wordpress-hash-event-api
105+
```
106+
107+
### Nginx as reverse proxy
108+
In case you want to use Nginx as a reverse proxy you can add following lines
109+
to your server block configuration. Make sure to adjust your IP and port accordingly.
110+
```nginx
111+
location /api {
112+
return 307 /api/v1;
113+
}
114+
location /api/v1/ {
115+
rewrite /api/v1/(.*) /$1 break;
116+
proxy_pass http://127.0.0.1:8000;
117+
proxy_redirect off;
118+
proxy_set_header Host $host;
119+
proxy_set_header X-Real-IP $remote_addr;
120+
# activate to see the actual remote IP and not just your reverse proxy
121+
# attention: in Europe this has implications on your GDPR statements on your page
122+
# as you log IP addresses.
123+
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
124+
#proxy_set_header X-Forwarded-Proto $scheme;
125+
}
103126
```
104127

105128
## Setup
106129
Copy the [config-example.ini](config-example.ini) sample settings file to `config.ini`.
107130
All options are described in the example file.
108131

109-
110-
## ToDo
111-
- [x] fix and test db connection timeout
112-
- [ ] fill README with useful information
113-
- [x] describe config
114-
- [ ] function and class doc strings
115-
- [x] add filters for most run attributes
116-
- [x] add API auth
117-
- [x] clean up code / linting
118-
- [x] describe setup and installation
119-
- [x] add docker file
120-
- [x] try to add "auto-install", this should set up the WordPress Event Manager to add all available fields to all events
121-
- [x] requirements.ini
122-
- [x] add OpenRC init script and config to server API via uvicorn
123-
- [ ] add nginx config example
124-
- [ ] add CORS Headers to nginx config
125-
126-
132+
After starting the API the first time it will add additional fields to each event.
133+
Such as a choice for the hosting Kennel or amount of Hash Cash.
127134

128135

129136
## License

api/factory/runs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (c) 2021 Ricardo Bartels. All rights reserved.
2+
# Copyright (c) 2022 Ricardo Bartels. All rights reserved.
33
#
44
# wordpress-hash-event-api
55
#

api/models/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (c) 2021 Ricardo Bartels. All rights reserved.
2+
# Copyright (c) 2022 Ricardo Bartels. All rights reserved.
33
#
44
# wordpress-hash-event-api
55
#

api/models/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (c) 2021 Ricardo Bartels. All rights reserved.
2+
# Copyright (c) 2022 Ricardo Bartels. All rights reserved.
33
#
44
# wordpress-hash-event-api
55
#

api/routers/runs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (c) 2021 Ricardo Bartels. All rights reserved.
2+
# Copyright (c) 2022 Ricardo Bartels. All rights reserved.
33
#
44
# wordpress-hash-event-api
55
#

api/security.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (c) 2021 Ricardo Bartels. All rights reserved.
2+
# Copyright (c) 2022 Ricardo Bartels. All rights reserved.
33
#
44
# wordpress-hash-event-api
55
#

common/log.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (c) 2021 Ricardo Bartels. All rights reserved.
2+
# Copyright (c) 2022 Ricardo Bartels. All rights reserved.
33
#
44
# wordpress-hash-event-api
55
#
@@ -8,8 +8,8 @@
88
# repository or visit: <https://opensource.org/licenses/MIT>.
99

1010
import logging
11-
import psutil
12-
import os
11+
12+
from config.log import run_by_systemd
1313

1414
# define valid log levels
1515
valid_log_levels = ["DEBUG", "INFO", "WARNING", "ERROR"]
@@ -43,12 +43,8 @@ def setup_logging(log_level=None):
4343

4444
log_format = '%(asctime)s - %(levelname)s: %(message)s'
4545

46-
# if app is started via systemd then strip time stamp from log format
47-
try:
48-
if psutil.Process(psutil.Process(os.getpid()).ppid()).name() == "systemd":
49-
log_format = '%(levelname)s: %(message)s'
50-
except Exception as e:
51-
print(f"unable to determine parent process name: {e}")
46+
if run_by_systemd is True:
47+
log_format = '%(levelname)s: %(message)s'
5248

5349
if log_level is None or log_level == "":
5450
print("ERROR: log level undefined or empty. Check config please.")

common/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (c) 2021 Ricardo Bartels. All rights reserved.
2+
# Copyright (c) 2022 Ricardo Bartels. All rights reserved.
33
#
44
# wordpress-hash-event-api
55
#

config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (c) 2021 Ricardo Bartels. All rights reserved.
2+
# Copyright (c) 2022 Ricardo Bartels. All rights reserved.
33
#
44
# wordpress-hash-event-api
55
#

config/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (c) 2021 Ricardo Bartels. All rights reserved.
2+
# Copyright (c) 2022 Ricardo Bartels. All rights reserved.
33
#
44
# wordpress-hash-event-api
55
#
@@ -15,7 +15,7 @@ class BasicAPISettings(BaseModel):
1515
title = 'Kennel Runs API'
1616
openapi_url = "/openapi.json"
1717
root_path = "/api/v1"
18-
version = '0.1'
18+
version = '1.0'
1919
debug = False
2020

2121
# EOF

0 commit comments

Comments
 (0)