Skip to content

Commit e2a55d5

Browse files
committed
Allow to configure via directory (close #2)
1 parent f5e693c commit e2a55d5

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ __pycache__
44
reports/
55
stage/
66
downloads/
7+
config/
78
config.json
89
*.tmp
910
tmp/

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
> Demo of a simple Web API to validate data against predefined criteria
77
8+
This web service implements a **[Data Validation API](#API)** being specified as part of project AQinDA. The API helps allows to check data against defined application profiles and to integrate such checks into data processing workflows. The API is not meant to define quality criteria of application profiles, this is another part of the project.
9+
810
## Table of Contents
911

1012
- [Installation](#installation)
@@ -25,9 +27,12 @@ The web application is started on <http://localhost:7007> by default.
2527

2628
### From sources
2729

28-
- Clone repository
29-
- `make deps`
30-
- `make start`
30+
Requires basic development toolchain (`sudo apt install build-essential`) and Python 3 with module venv to be installed.
31+
32+
1. clone repository: `git clone https://github.com/gbv/validation-api-ws.git && cd validation-api-ws`
33+
2. run `make deps` to install dependencies
34+
3. optionally [Configure](#configuration] the instance with
35+
3. `make start`
3136

3237
### Via Docker
3338

@@ -53,9 +58,9 @@ docker run --rm -p 7007:7007 validator
5358

5459
## Configuration
5560

56-
If local file `config.json` exist, it is used for configuration, otherwise [default configuration](config.default.json) is used.
61+
The [default configuration](config.default.json) contains some base formats. To defined the application profiles to be checked against, create a configuration file in JSON format at `config.json` in the current directory or in the local subdirectory `config`. It is also possible to pass the location of config file or directory with argument `--config` at startup.
5762

58-
Configuration must contain key `profiles` with a list of profile objects, each having a unique `id` and a list of `checks`. See [profiles configuration JSON Schema](lib/validate/profiles-schema.json) for details. Additional config fields include:
63+
The configuration file must contain field `profiles` with a list of profile objects, each having a unique `id` and a list of `checks`. See [profiles configuration JSON Schema](lib/validate/profiles-schema.json) for details. Additional config fields include:
5964

6065
- `title` (title of the webservice) is set to "Validation Service" by default.
6166
- `port` (numeric port to run the webservice) is set to 7007 by default.
@@ -108,7 +113,6 @@ Same as GET request but data is passed as request body or as file upload (conten
108113

109114
## Contributing
110115

111-
Requires basic development toolchain (`sudo apt install build-essential`) and Python 3 with module venv to be installed.
112116

113117
- `make deps` installs Python dependencies in a virtual environment in directory `.venv`. You may want to call `. .venv/bin/activate` to active the environment.
114118
- `make test` runs unit tests
@@ -126,6 +130,8 @@ test -f config.json && docker run --rm -p 7007:7007 --volume ./config.json:/app/
126130

127131
See also <https://github.com/gbv/validation-server> for a previous implementation in NodeJS. Both implementations may converge
128132

133+
This work is [funded by DFG (project "AQinDa")](https://gepris.dfg.de/gepris/projekt/521659096)
134+
129135
## License
130136

131137
MIT © 2025- Verbundzentrale des GBV (VZG)

app.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,17 @@ def validate(profile):
8282
parser.add_argument('-w', '--wsgi', action=argparse.BooleanOptionalAction, help="Use WSGI")
8383
parser.add_argument('-d', '--debug', action=argparse.BooleanOptionalAction)
8484

85-
config_file = "config.json" if Path('config.json').exists() else "config.default.json"
86-
parser.add_argument('config', help="Config file", default=config_file, nargs='?')
85+
config_file = "config.default.json"
86+
for file in [Path("config.json"), Path("config") / "config.json"]:
87+
if file.exists():
88+
config_file = file
89+
90+
parser.add_argument('config', help="Config file or directory", default=config_file, nargs='?')
8791
args = parser.parse_args()
8892

93+
if Path(args.config).is_dir():
94+
args.config = Path(args.config) / "config.json"
95+
8996
print(f"Loading configuration from {args.config}")
9097
config = json.load(Path(args.config).open())
9198

0 commit comments

Comments
 (0)