Skip to content

Commit 2ad246e

Browse files
authored
Merge pull request #26 from itk-dev/feature/api
Use the real API
2 parents a4aee17 + e85c951 commit 2ad246e

36 files changed

+339
-2166
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "api"]
2+
path = api
3+
url = https://github.com/AAK-MBU/Process_Dashboard_API

.markdownlintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ web/*.md
1010
web/core/
1111
web/libraries/
1212
web/*/contrib/
13+
14+
/api/

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# The Svelte standalone widgets have a life of their own …
22
widgets/
3+
4+
# The API must also not be touched
5+
api/

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
* [PR-27](https://github.com/itk-dev/rpa-process-overview/pull/27)
1111
Added pre-defined users in OIDC mock
12+
* [PR-26](https://github.com/itk-dev/rpa-process-overview/pull/26)
13+
Added [the real API](https://github.com/AAK-MBU/Process_Dashboard_API) for local development and testing
1214
* [PR-24](https://github.com/itk-dev/rpa-process-overview/pull/24)
1315
Remove search from url
1416
* [PR-25](https://github.com/itk-dev/rpa-process-overview/pull/25)

README.md

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,67 @@ Run
2828
task site:update
2929
```
3030

31-
to get things started.
31+
> [!NOTE]
32+
> Running `task site:update` on [macOS (darwin)](https://en.wikipedia.org/wiki/Darwin_(operating_system)) will pull and
33+
> patch the API Git submodule (cf. [#api](API)). See [`Taskfile.yml`](Taskfile.yml) for details.
3234
3335
Load fixtures with
3436

3537
``` shell
36-
task fixtures:load
38+
task app:fixtures:load
3739
```
3840

41+
> [!TIP]
42+
> Pro tip! Run
43+
>
44+
> ``` shell
45+
> task fixtures:load --yes
46+
> ```
47+
>
48+
> to load all fixtures in succession (including the fixtures mentioned below).
49+
3950
### Icons
4051
4152
The icons are copied from [heroicons](https://heroicons.com).
4253
43-
## API Mock
54+
## API
55+
56+
For development, we run [AAK-MBU/Process_Dashboard_API](https://github.com/AAK-MBU/Process_Dashboard_API) locally. The
57+
API is added as a [Git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules) in the [api](./api) folder.
58+
59+
``` shell
60+
task api:create:api-keys
61+
```
4462
45-
We use a [FastAPI](https://fastapi.tiangolo.com) app to mock the RPA process overview API.
63+
Test access to the API:
4664

4765
``` shell
48-
curl "http://$(docker compose port api 8000)/openapi.json"
49-
curl "http://$(docker compose port api 8000)/api/v1/process"
50-
curl "http://$(docker compose port api 8000)/api/v1/process" --header 'x-api-key: a-not-so-secret-key'
66+
task api:test
67+
task api:get API_PATH=/api/v1/auth/me
68+
69+
task api:get API_PATH='/api/v1/runs/?process_id=1'
70+
task api:get API_PATH='/api/v1/runs/?process_id=1&meta_filter=name:Gregory%20Mendez'
5171
```
5272

53-
Create some fixture data for the API:
73+
See [`docker-compose.api.yml`](docker-compose.api.yml) for the docker compose setup for the API.
74+
75+
## Updating the API
76+
77+
Run
5478

5579
``` shell
56-
task api:fixtures:load
57-
curl "http://$(docker compose port api 8000)/api/v1/process/" --header 'x-api-key: a-not-so-secret-key'
80+
task api:update
5881
```
5982

60-
See [api/README.md](api/README.md) for some more details (and [`docker-compose.api.yml`](docker-compose.api.yml) for the
61-
docker compose setup).
83+
to update the API to the latest version (the [`main`
84+
branch](https://github.com/AAK-MBU/Process_Dashboard_API/tree/main)).
85+
86+
### Loading data
87+
88+
``` shell
89+
task api:script:run SCRIPT_PATH=«path to seed_data.py»
90+
task api:script:run SCRIPT_PATH=«path to seed_data_aktindsigt.py»
91+
```
6292

6393
## CORS
6494

Taskfile.yml

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ tasks:
3737
- task: compose
3838
vars:
3939
TASK_ARGS: pull
40+
41+
# Additional setup for local development (assuming we're running on maxOS (darwin))
42+
- cmd: |
43+
git -C api checkout .
44+
git submodule update --init
45+
# Apply a patch to support MySQL in the API and make building it work.
46+
git -C api apply < patches/Process_Dashboard_API.patch
47+
# https://taskfile.dev/docs/reference/schema#platforms
48+
platforms: [darwin]
49+
4050
- task: compose
4151
vars:
4252
TASK_ARGS: up --build --detach --wait
@@ -83,21 +93,21 @@ tasks:
8393
vars:
8494
TASK_ARGS: cache:clear
8595

86-
fixtures:load:
87-
desc: Load fixtures
96+
app:fixtures:load:
97+
desc: Load app fixtures
8898
prompt: This will reset your database. Continue?
8999
cmds:
90100
- task: console
91101
vars:
92102
TASK_ARGS: hautelook:fixtures:load --no-interaction
93103

94-
api:fixtures:load:
95-
desc: Load API fixtures
96-
prompt: Continue?
104+
fixtures:load:
105+
desc: Load all fixtures
106+
prompt: This will reset your databases. Continue?
97107
cmds:
98-
- task: compose
99-
vars:
100-
TASK_ARGS: exec api uv run python -m src.api.fixtures
108+
- task: api:fixtures:load
109+
- task: app:fixtures:load
110+
- task: oidc:fixtures:load
101111

102112
translations:extract:
103113
cmds:
@@ -134,3 +144,73 @@ tasks:
134144
vars:
135145
BUILD_DIR: widgets/static/dist/
136146
PUBLIC_DIR: public/widgets
147+
148+
api:create:api-keys:
149+
desc: Create API keys
150+
cmds:
151+
- task: api:script:run
152+
vars:
153+
SCRIPT_PATH: scripts/api/create_api_keys.py
154+
155+
api:fixtures:load:
156+
desc: Load API fixtures
157+
prompt: Continue?
158+
cmds:
159+
# Install faker and load fixtures
160+
- task: compose
161+
vars:
162+
TASK_ARGS: exec api uv add --dev faker
163+
- task: api:create:api-keys
164+
- task: api:script:run
165+
vars:
166+
SCRIPT_PATH: scripts/api/fixtures.py
167+
168+
api:update:
169+
desc: Update API to latest version (https://github.com/AAK-MBU/Process_Dashboard_API/tree/main)
170+
prompt: Really?
171+
cmds:
172+
- git -C api checkout .
173+
- git -C api checkout main
174+
- git -C api pull
175+
# Check that our patch can be applied.
176+
- git -C api apply --check < patches/Process_Dashboard_API.patch
177+
178+
api:script:run:
179+
desc: "Run script inside API service container, example: `task {{.TASK}} SCRIPT_PATH=test/load_data.py"
180+
silent: true
181+
cmds:
182+
- echo "Running {{.SCRIPT_PATH}} inside API service"
183+
- task: compose
184+
vars:
185+
TASK_ARGS: cp {{.SCRIPT_PATH}} api:/app/scripts
186+
- task: compose
187+
vars:
188+
TASK_ARGS: exec api python scripts/$(basename {{.SCRIPT_PATH}})
189+
requires:
190+
vars: [SCRIPT_PATH]
191+
preconditions:
192+
- sh: test -f {{.SCRIPT_PATH}}
193+
msg: "{{.SCRIPT_PATH}} does not exist"
194+
195+
api:get:
196+
desc: "Perform a GET request to an API endpoint, examples: `task {{.TASK}} API_PATH=/api/v1/auth/me`, `task {{.TASK}} API_PATH=/api/v1/auth/me API_KEY=my-api-key`"
197+
cmds:
198+
- |-
199+
task compose -- exec phpfpm curl --silent --verbose --header 'x-api-key: {{.API_KEY}}' '{{.API_BASE_URL}}{{.API_PATH}}' | docker run --rm --interactive ghcr.io/jqlang/jq:latest
200+
requires:
201+
vars: [API_PATH]
202+
vars:
203+
API_BASE_URL: http://api:8000
204+
# Cf. scripts/api/create_api_keys.py
205+
API_KEY: '{{ .API_KEY | default "user-api-key" }}'
206+
silent: true
207+
208+
api:test:
209+
cmds:
210+
- for:
211+
- /api/v1/auth/me
212+
- /api/v1/processes/processes/
213+
- /api/v1/processes/processes/1
214+
task: api:get
215+
vars:
216+
API_PATH: "{{.ITEM}}"

api

Submodule api added at dafcb82

api/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

api/.python-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

api/Dockerfile

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)