basic-python-project 0.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- basic_python_project-0.0.0/LICENSE +21 -0
- basic_python_project-0.0.0/PKG-INFO +124 -0
- basic_python_project-0.0.0/README.md +95 -0
- basic_python_project-0.0.0/pyproject.toml +28 -0
- basic_python_project-0.0.0/requirements.txt +15 -0
- basic_python_project-0.0.0/setup.cfg +4 -0
- basic_python_project-0.0.0/src/basic_python_project.egg-info/PKG-INFO +124 -0
- basic_python_project-0.0.0/src/basic_python_project.egg-info/SOURCES.txt +27 -0
- basic_python_project-0.0.0/src/basic_python_project.egg-info/dependency_links.txt +1 -0
- basic_python_project-0.0.0/src/basic_python_project.egg-info/requires.txt +15 -0
- basic_python_project-0.0.0/src/basic_python_project.egg-info/top_level.txt +1 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/__init__.py +0 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/constants.py +55 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/database/__init__.py +0 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/database/engine.py +35 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/database/models.py +276 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/dependencies.py +133 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/keycloak_clients.py +55 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/main.py +63 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/minio_client.py +52 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/routers/__init__.py +0 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/routers/guest_user_access.py +44 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/routers/records.py +268 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/routers/users.py +92 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/schemas/__init__.py +49 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/schemas/citizen_science.py +61 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/schemas/image.py +48 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/schemas/record.py +59 -0
- basic_python_project-0.0.0/src/meinewaldki_citizen_rest_service/schemas/user.py +25 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 AnhaltAI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: basic-python-project
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Template: Basic Python Project
|
|
5
|
+
Author-email: Christian Hänig <christian.haenig@hs-anhalt.de>
|
|
6
|
+
Project-URL: Gitlab, https://gitlab.hs-anhalt.de/ki/templates/basic-python-project
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.12
|
|
11
|
+
Description-Content-Type: text/markdown; charset=UTF-8
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: fastapi~=0.115.5
|
|
14
|
+
Requires-Dist: pytest~=8.3
|
|
15
|
+
Requires-Dist: pytest-asyncio~=0.24
|
|
16
|
+
Requires-Dist: starlette~=0.41.3
|
|
17
|
+
Requires-Dist: uvicorn~=0.32.1
|
|
18
|
+
Requires-Dist: python-keycloak~=4.7.3
|
|
19
|
+
Requires-Dist: python-dotenv~=1.0.1
|
|
20
|
+
Requires-Dist: sqlmodel~=0.0.34
|
|
21
|
+
Requires-Dist: sqlalchemy~=2.0
|
|
22
|
+
Requires-Dist: asyncpg~=0.30.0
|
|
23
|
+
Requires-Dist: geoalchemy2~=0.15.2
|
|
24
|
+
Requires-Dist: minio~=7.2
|
|
25
|
+
Requires-Dist: Pillow~=11.0
|
|
26
|
+
Requires-Dist: python-multipart~=0.0.20
|
|
27
|
+
Requires-Dist: sentry-sdk[fastapi]~=2.0
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# Meinewaldki Citizen Rest Service
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## Installation for Kubernetes
|
|
34
|
+
|
|
35
|
+
You need to have helm and kubectl installed.
|
|
36
|
+
|
|
37
|
+
Your kubeconfig should be set to the correct cluster (meinewaldki).
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
kubectl config current-context
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Navigate to the configuration directory:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
cd config
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Keycloak
|
|
50
|
+
|
|
51
|
+
For keycloak you need to run the following command:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
helm install test-keycloak keycloak --namespace citizen-scientist-app
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The configurations are in the keycloak/values.yaml file.
|
|
58
|
+
|
|
59
|
+
Base configuration your endpoint will be `https://meinewaldki.anhalt.ai/dev-auth`.
|
|
60
|
+
|
|
61
|
+
To uninstall keycloak run the following command:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
helm uninstall test-keycloak --namespace citizen-scientist-app
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
#### Settings
|
|
68
|
+
|
|
69
|
+
Log into keycloak with the following credentials:
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
Username: admin-dev
|
|
73
|
+
Password: PLS_CHG_ME
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Add a new realm for guest users.
|
|
77
|
+
|
|
78
|
+
In the new realm create a new client with the ClientID `MeineWaldKIApp`.
|
|
79
|
+
Enable OAuth 2.0 Device Authorization Grant.
|
|
80
|
+
|
|
81
|
+
After creating the client change the following settings:
|
|
82
|
+
|
|
83
|
+
Origin: `*` (should be more restrictive in production, but did not check if this works with a more restrictive setting)
|
|
84
|
+
Valid Redirect URIs: `*` (should be more restrictive in production, but did not check if this works with a more restrictive setting)
|
|
85
|
+
|
|
86
|
+
Add the role `guest` to the client roles.
|
|
87
|
+
|
|
88
|
+
Go to Realm Settings. Set SSO Session Idle very high and SSO Session also very high (Sessions).
|
|
89
|
+
|
|
90
|
+
Set Access Token Lifespan to a very high value (Tokens).
|
|
91
|
+
|
|
92
|
+
Remove the first name and last name from the required user attributes (User profile).
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
### Installation Rest Service
|
|
96
|
+
|
|
97
|
+
I will add the automatic deployment through CI/CD later.
|
|
98
|
+
|
|
99
|
+
The deployment helm is mostly written but the Docker image is not yet in a registry.
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
## Run locally
|
|
103
|
+
After Installing keycloak and creating your realms and changing the admin password and or admin user you can run the service locally.
|
|
104
|
+
|
|
105
|
+
Add the following environment variables to your .env file:
|
|
106
|
+
|
|
107
|
+
```env
|
|
108
|
+
KEYCLOAK_SERVER_URL=https://meinewaldki.anhalt.ai/dev-auth/ (if not changed)
|
|
109
|
+
ADMIN_USERNAME=admin_dev (if not changed)
|
|
110
|
+
ADMIN_PASSWORD=PLS_CHG_ME (if not changed)
|
|
111
|
+
ADMIN_REALM_NAME=master (if not changed)
|
|
112
|
+
GUEST_USER_REALM_NAME=YourRealm (I set it to guest-users)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Mark the src directory as source root in your IDE.
|
|
116
|
+
|
|
117
|
+
Run the main.py file with the working directory set to the root directory of the project.
|
|
118
|
+
|
|
119
|
+
### Endpoints
|
|
120
|
+
I did not setup an endpoint for cookies. This should make it easier to test the endpoints.
|
|
121
|
+
|
|
122
|
+
http://127.0.0.1:5001/citizen-api/guest-user/create -> Create a new guest user
|
|
123
|
+
http://127.0.0.1:5001/citizen-api/guest-user/check -> Check if Token is valid (Post request)
|
|
124
|
+
http://127.0.0.1:5001/citizen-api/docs -> Swagger UI (Easy to test the endpoints)
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Meinewaldki Citizen Rest Service
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## Installation for Kubernetes
|
|
5
|
+
|
|
6
|
+
You need to have helm and kubectl installed.
|
|
7
|
+
|
|
8
|
+
Your kubeconfig should be set to the correct cluster (meinewaldki).
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
kubectl config current-context
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Navigate to the configuration directory:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
cd config
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Keycloak
|
|
21
|
+
|
|
22
|
+
For keycloak you need to run the following command:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
helm install test-keycloak keycloak --namespace citizen-scientist-app
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The configurations are in the keycloak/values.yaml file.
|
|
29
|
+
|
|
30
|
+
Base configuration your endpoint will be `https://meinewaldki.anhalt.ai/dev-auth`.
|
|
31
|
+
|
|
32
|
+
To uninstall keycloak run the following command:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
helm uninstall test-keycloak --namespace citizen-scientist-app
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
#### Settings
|
|
39
|
+
|
|
40
|
+
Log into keycloak with the following credentials:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
Username: admin-dev
|
|
44
|
+
Password: PLS_CHG_ME
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Add a new realm for guest users.
|
|
48
|
+
|
|
49
|
+
In the new realm create a new client with the ClientID `MeineWaldKIApp`.
|
|
50
|
+
Enable OAuth 2.0 Device Authorization Grant.
|
|
51
|
+
|
|
52
|
+
After creating the client change the following settings:
|
|
53
|
+
|
|
54
|
+
Origin: `*` (should be more restrictive in production, but did not check if this works with a more restrictive setting)
|
|
55
|
+
Valid Redirect URIs: `*` (should be more restrictive in production, but did not check if this works with a more restrictive setting)
|
|
56
|
+
|
|
57
|
+
Add the role `guest` to the client roles.
|
|
58
|
+
|
|
59
|
+
Go to Realm Settings. Set SSO Session Idle very high and SSO Session also very high (Sessions).
|
|
60
|
+
|
|
61
|
+
Set Access Token Lifespan to a very high value (Tokens).
|
|
62
|
+
|
|
63
|
+
Remove the first name and last name from the required user attributes (User profile).
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
### Installation Rest Service
|
|
67
|
+
|
|
68
|
+
I will add the automatic deployment through CI/CD later.
|
|
69
|
+
|
|
70
|
+
The deployment helm is mostly written but the Docker image is not yet in a registry.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## Run locally
|
|
74
|
+
After Installing keycloak and creating your realms and changing the admin password and or admin user you can run the service locally.
|
|
75
|
+
|
|
76
|
+
Add the following environment variables to your .env file:
|
|
77
|
+
|
|
78
|
+
```env
|
|
79
|
+
KEYCLOAK_SERVER_URL=https://meinewaldki.anhalt.ai/dev-auth/ (if not changed)
|
|
80
|
+
ADMIN_USERNAME=admin_dev (if not changed)
|
|
81
|
+
ADMIN_PASSWORD=PLS_CHG_ME (if not changed)
|
|
82
|
+
ADMIN_REALM_NAME=master (if not changed)
|
|
83
|
+
GUEST_USER_REALM_NAME=YourRealm (I set it to guest-users)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Mark the src directory as source root in your IDE.
|
|
87
|
+
|
|
88
|
+
Run the main.py file with the working directory set to the root directory of the project.
|
|
89
|
+
|
|
90
|
+
### Endpoints
|
|
91
|
+
I did not setup an endpoint for cookies. This should make it easier to test the endpoints.
|
|
92
|
+
|
|
93
|
+
http://127.0.0.1:5001/citizen-api/guest-user/create -> Create a new guest user
|
|
94
|
+
http://127.0.0.1:5001/citizen-api/guest-user/check -> Check if Token is valid (Post request)
|
|
95
|
+
http://127.0.0.1:5001/citizen-api/docs -> Swagger UI (Easy to test the endpoints)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=72.2.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "basic-python-project"
|
|
7
|
+
description = "Template: Basic Python Project"
|
|
8
|
+
authors = [{ name = "Christian Hänig", email = "christian.haenig@hs-anhalt.de" }, ]
|
|
9
|
+
|
|
10
|
+
dynamic = ["version", "readme", "dependencies"]
|
|
11
|
+
|
|
12
|
+
requires-python = ">=3.12"
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[tool.setuptools.dynamic]
|
|
20
|
+
version = { file = ["VERSION"] }
|
|
21
|
+
readme = { file = ["README.md"], content-type = "text/markdown; charset=UTF-8" }
|
|
22
|
+
dependencies = { file = ["requirements.txt"] }
|
|
23
|
+
|
|
24
|
+
[tool.pytest.ini_options]
|
|
25
|
+
asyncio_mode = "auto"
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Gitlab = "https://gitlab.hs-anhalt.de/ki/templates/basic-python-project"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
fastapi~=0.115.5
|
|
2
|
+
pytest~=8.3
|
|
3
|
+
pytest-asyncio~=0.24
|
|
4
|
+
starlette~=0.41.3
|
|
5
|
+
uvicorn~=0.32.1
|
|
6
|
+
python-keycloak~=4.7.3
|
|
7
|
+
python-dotenv~=1.0.1
|
|
8
|
+
sqlmodel~=0.0.34
|
|
9
|
+
sqlalchemy~=2.0
|
|
10
|
+
asyncpg~=0.30.0
|
|
11
|
+
geoalchemy2~=0.15.2
|
|
12
|
+
minio~=7.2
|
|
13
|
+
Pillow~=11.0
|
|
14
|
+
python-multipart~=0.0.20
|
|
15
|
+
sentry-sdk[fastapi]~=2.0
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: basic-python-project
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Template: Basic Python Project
|
|
5
|
+
Author-email: Christian Hänig <christian.haenig@hs-anhalt.de>
|
|
6
|
+
Project-URL: Gitlab, https://gitlab.hs-anhalt.de/ki/templates/basic-python-project
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.12
|
|
11
|
+
Description-Content-Type: text/markdown; charset=UTF-8
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: fastapi~=0.115.5
|
|
14
|
+
Requires-Dist: pytest~=8.3
|
|
15
|
+
Requires-Dist: pytest-asyncio~=0.24
|
|
16
|
+
Requires-Dist: starlette~=0.41.3
|
|
17
|
+
Requires-Dist: uvicorn~=0.32.1
|
|
18
|
+
Requires-Dist: python-keycloak~=4.7.3
|
|
19
|
+
Requires-Dist: python-dotenv~=1.0.1
|
|
20
|
+
Requires-Dist: sqlmodel~=0.0.34
|
|
21
|
+
Requires-Dist: sqlalchemy~=2.0
|
|
22
|
+
Requires-Dist: asyncpg~=0.30.0
|
|
23
|
+
Requires-Dist: geoalchemy2~=0.15.2
|
|
24
|
+
Requires-Dist: minio~=7.2
|
|
25
|
+
Requires-Dist: Pillow~=11.0
|
|
26
|
+
Requires-Dist: python-multipart~=0.0.20
|
|
27
|
+
Requires-Dist: sentry-sdk[fastapi]~=2.0
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# Meinewaldki Citizen Rest Service
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## Installation for Kubernetes
|
|
34
|
+
|
|
35
|
+
You need to have helm and kubectl installed.
|
|
36
|
+
|
|
37
|
+
Your kubeconfig should be set to the correct cluster (meinewaldki).
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
kubectl config current-context
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Navigate to the configuration directory:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
cd config
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Keycloak
|
|
50
|
+
|
|
51
|
+
For keycloak you need to run the following command:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
helm install test-keycloak keycloak --namespace citizen-scientist-app
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The configurations are in the keycloak/values.yaml file.
|
|
58
|
+
|
|
59
|
+
Base configuration your endpoint will be `https://meinewaldki.anhalt.ai/dev-auth`.
|
|
60
|
+
|
|
61
|
+
To uninstall keycloak run the following command:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
helm uninstall test-keycloak --namespace citizen-scientist-app
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
#### Settings
|
|
68
|
+
|
|
69
|
+
Log into keycloak with the following credentials:
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
Username: admin-dev
|
|
73
|
+
Password: PLS_CHG_ME
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Add a new realm for guest users.
|
|
77
|
+
|
|
78
|
+
In the new realm create a new client with the ClientID `MeineWaldKIApp`.
|
|
79
|
+
Enable OAuth 2.0 Device Authorization Grant.
|
|
80
|
+
|
|
81
|
+
After creating the client change the following settings:
|
|
82
|
+
|
|
83
|
+
Origin: `*` (should be more restrictive in production, but did not check if this works with a more restrictive setting)
|
|
84
|
+
Valid Redirect URIs: `*` (should be more restrictive in production, but did not check if this works with a more restrictive setting)
|
|
85
|
+
|
|
86
|
+
Add the role `guest` to the client roles.
|
|
87
|
+
|
|
88
|
+
Go to Realm Settings. Set SSO Session Idle very high and SSO Session also very high (Sessions).
|
|
89
|
+
|
|
90
|
+
Set Access Token Lifespan to a very high value (Tokens).
|
|
91
|
+
|
|
92
|
+
Remove the first name and last name from the required user attributes (User profile).
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
### Installation Rest Service
|
|
96
|
+
|
|
97
|
+
I will add the automatic deployment through CI/CD later.
|
|
98
|
+
|
|
99
|
+
The deployment helm is mostly written but the Docker image is not yet in a registry.
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
## Run locally
|
|
103
|
+
After Installing keycloak and creating your realms and changing the admin password and or admin user you can run the service locally.
|
|
104
|
+
|
|
105
|
+
Add the following environment variables to your .env file:
|
|
106
|
+
|
|
107
|
+
```env
|
|
108
|
+
KEYCLOAK_SERVER_URL=https://meinewaldki.anhalt.ai/dev-auth/ (if not changed)
|
|
109
|
+
ADMIN_USERNAME=admin_dev (if not changed)
|
|
110
|
+
ADMIN_PASSWORD=PLS_CHG_ME (if not changed)
|
|
111
|
+
ADMIN_REALM_NAME=master (if not changed)
|
|
112
|
+
GUEST_USER_REALM_NAME=YourRealm (I set it to guest-users)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Mark the src directory as source root in your IDE.
|
|
116
|
+
|
|
117
|
+
Run the main.py file with the working directory set to the root directory of the project.
|
|
118
|
+
|
|
119
|
+
### Endpoints
|
|
120
|
+
I did not setup an endpoint for cookies. This should make it easier to test the endpoints.
|
|
121
|
+
|
|
122
|
+
http://127.0.0.1:5001/citizen-api/guest-user/create -> Create a new guest user
|
|
123
|
+
http://127.0.0.1:5001/citizen-api/guest-user/check -> Check if Token is valid (Post request)
|
|
124
|
+
http://127.0.0.1:5001/citizen-api/docs -> Swagger UI (Easy to test the endpoints)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
requirements.txt
|
|
5
|
+
src/basic_python_project.egg-info/PKG-INFO
|
|
6
|
+
src/basic_python_project.egg-info/SOURCES.txt
|
|
7
|
+
src/basic_python_project.egg-info/dependency_links.txt
|
|
8
|
+
src/basic_python_project.egg-info/requires.txt
|
|
9
|
+
src/basic_python_project.egg-info/top_level.txt
|
|
10
|
+
src/meinewaldki_citizen_rest_service/__init__.py
|
|
11
|
+
src/meinewaldki_citizen_rest_service/constants.py
|
|
12
|
+
src/meinewaldki_citizen_rest_service/dependencies.py
|
|
13
|
+
src/meinewaldki_citizen_rest_service/keycloak_clients.py
|
|
14
|
+
src/meinewaldki_citizen_rest_service/main.py
|
|
15
|
+
src/meinewaldki_citizen_rest_service/minio_client.py
|
|
16
|
+
src/meinewaldki_citizen_rest_service/database/__init__.py
|
|
17
|
+
src/meinewaldki_citizen_rest_service/database/engine.py
|
|
18
|
+
src/meinewaldki_citizen_rest_service/database/models.py
|
|
19
|
+
src/meinewaldki_citizen_rest_service/routers/__init__.py
|
|
20
|
+
src/meinewaldki_citizen_rest_service/routers/guest_user_access.py
|
|
21
|
+
src/meinewaldki_citizen_rest_service/routers/records.py
|
|
22
|
+
src/meinewaldki_citizen_rest_service/routers/users.py
|
|
23
|
+
src/meinewaldki_citizen_rest_service/schemas/__init__.py
|
|
24
|
+
src/meinewaldki_citizen_rest_service/schemas/citizen_science.py
|
|
25
|
+
src/meinewaldki_citizen_rest_service/schemas/image.py
|
|
26
|
+
src/meinewaldki_citizen_rest_service/schemas/record.py
|
|
27
|
+
src/meinewaldki_citizen_rest_service/schemas/user.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
fastapi~=0.115.5
|
|
2
|
+
pytest~=8.3
|
|
3
|
+
pytest-asyncio~=0.24
|
|
4
|
+
starlette~=0.41.3
|
|
5
|
+
uvicorn~=0.32.1
|
|
6
|
+
python-keycloak~=4.7.3
|
|
7
|
+
python-dotenv~=1.0.1
|
|
8
|
+
sqlmodel~=0.0.34
|
|
9
|
+
sqlalchemy~=2.0
|
|
10
|
+
asyncpg~=0.30.0
|
|
11
|
+
geoalchemy2~=0.15.2
|
|
12
|
+
minio~=7.2
|
|
13
|
+
Pillow~=11.0
|
|
14
|
+
python-multipart~=0.0.20
|
|
15
|
+
sentry-sdk[fastapi]~=2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
meinewaldki_citizen_rest_service
|
|
File without changes
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Constants for the MeineWaldKI Citizen REST Service."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
from dotenv import load_dotenv
|
|
6
|
+
|
|
7
|
+
if os.path.exists(".env"):
|
|
8
|
+
load_dotenv(dotenv_path=".env")
|
|
9
|
+
|
|
10
|
+
KEYCLOAK_SERVER_URL = os.environ["KEYCLOAK_SERVER_URL"]
|
|
11
|
+
# Optional path to a CA cert for Keycloak TLS verification.
|
|
12
|
+
# Set in dev when using a self-signed cert. Leave unset in production.
|
|
13
|
+
KEYCLOAK_CERT_PATH = os.environ.get("KEYCLOAK_CERT_PATH")
|
|
14
|
+
|
|
15
|
+
GUEST_ADMIN_USERNAME = os.environ["GUEST_ADMIN_USERNAME"]
|
|
16
|
+
GUEST_ADMIN_PASSWORD = os.environ["GUEST_ADMIN_PASSWORD"]
|
|
17
|
+
GUEST_ADMIN_REALM_NAME = os.environ["GUEST_ADMIN_REALM_NAME"]
|
|
18
|
+
|
|
19
|
+
REGISTERED_ADMIN_USERNAME = os.environ["REGISTERED_ADMIN_USERNAME"]
|
|
20
|
+
REGISTERED_ADMIN_PASSWORD = os.environ["REGISTERED_ADMIN_PASSWORD"]
|
|
21
|
+
REGISTERED_ADMIN_REALM_NAME = os.environ["REGISTERED_ADMIN_REALM_NAME"]
|
|
22
|
+
|
|
23
|
+
GUEST_USER_REALM_NAME = os.environ["GUEST_USER_REALM_NAME"]
|
|
24
|
+
REGISTERED_USER_REALM_NAME = os.environ["REGISTERED_USER_REALM_NAME"]
|
|
25
|
+
|
|
26
|
+
CLIENT_NAME = "MeineWaldKIApp"
|
|
27
|
+
|
|
28
|
+
DB_USER = os.environ.get("DB_USER", "")
|
|
29
|
+
DB_PASSWORD = os.environ.get("DB_PASSWORD", "")
|
|
30
|
+
DB_HOST = os.environ.get("DB_HOST", "")
|
|
31
|
+
DB_PORT = os.environ.get("DB_PORT", "5432")
|
|
32
|
+
DB_NAME = os.environ.get("DB_NAME", "")
|
|
33
|
+
|
|
34
|
+
MINIO_ENDPOINT = os.environ["MINIO_ENDPOINT"]
|
|
35
|
+
MINIO_ACCESS_KEY = os.environ["MINIO_ACCESS_KEY"]
|
|
36
|
+
MINIO_SECRET_KEY = os.environ["MINIO_SECRET_KEY"]
|
|
37
|
+
MINIO_BUCKET = os.environ["MINIO_BUCKET"]
|
|
38
|
+
MINIO_SECURE = os.environ.get("MINIO_SECURE", "true").lower() == "true"
|
|
39
|
+
|
|
40
|
+
# GlitchTip / Sentry DSN — leave unset to disable error reporting
|
|
41
|
+
GLITCHTIP_DSN = os.environ.get("GLITCHTIP_DSN")
|
|
42
|
+
|
|
43
|
+
# EPSG:4326 — World Geodetic System 1984. Lat/lon in decimal degrees on the
|
|
44
|
+
# WGS 84 ellipsoid; the reference system behind GPS and most web maps.
|
|
45
|
+
WGS84_SRID = 4326
|
|
46
|
+
|
|
47
|
+
ALLOWED_IMAGE_MIME_TYPES = frozenset(
|
|
48
|
+
{
|
|
49
|
+
"image/jpeg",
|
|
50
|
+
"image/png",
|
|
51
|
+
"image/webp",
|
|
52
|
+
"image/heic",
|
|
53
|
+
"image/heif",
|
|
54
|
+
}
|
|
55
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from collections.abc import AsyncGenerator
|
|
2
|
+
from urllib.parse import quote_plus
|
|
3
|
+
|
|
4
|
+
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
5
|
+
|
|
6
|
+
from meinewaldki_citizen_rest_service.constants import (
|
|
7
|
+
DB_HOST,
|
|
8
|
+
DB_NAME,
|
|
9
|
+
DB_PASSWORD,
|
|
10
|
+
DB_PORT,
|
|
11
|
+
DB_USER,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
_DATABASE_URL = (
|
|
15
|
+
f"postgresql+asyncpg://{quote_plus(DB_USER)}"
|
|
16
|
+
f":{quote_plus(DB_PASSWORD)}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
engine = create_async_engine(_DATABASE_URL, echo=False, pool_pre_ping=True)
|
|
20
|
+
|
|
21
|
+
SessionLocal = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
async def get_session() -> AsyncGenerator[AsyncSession, None]:
|
|
25
|
+
"""Yields an async database session for use as a FastAPI dependency.
|
|
26
|
+
|
|
27
|
+
Yields:
|
|
28
|
+
An async SQLAlchemy session that is automatically rolled back on error.
|
|
29
|
+
"""
|
|
30
|
+
async with SessionLocal() as session:
|
|
31
|
+
try:
|
|
32
|
+
yield session
|
|
33
|
+
except Exception:
|
|
34
|
+
await session.rollback()
|
|
35
|
+
raise
|