uhd-urz / elAPI

An extensible API client for eLabFTW
GNU Affero General Public License v3.0
5 stars 0 forks source link

Values in configuration file elapi.yml aren't validated #30

Closed alexander-haller closed 3 months ago

alexander-haller commented 5 months ago

In GitLab by @mhxion on Apr 28, 2024, 24:47

elapi.yml could be given values of invalid types, elapi will still try to accept it. E.g.,

host: <host>
api_token: <token>
export_dir: true  # <- boolean instead of a string

If elapi is run a Python error is raised.

$ elapi

...
  File "/Users/<username>/Workshop/elapi/src/elapi/path.py", line 94, in expanded
    return Path(self.name).expanduser()
           ^^^^^^^^^^^^^^^
  File "/Users/<username>/.pyenv/versions/3.11.4/lib/python3.11/pathlib.py", line 871, in __new__
    self = cls._from_parts(args)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/<username>/.pyenv/versions/3.11.4/lib/python3.11/pathlib.py", line 509, in _from_parts
    drv, root, parts = self._parse_args(args)
                       ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/<username>/.pyenv/versions/3.11.4/lib/python3.11/pathlib.py", line 493, in _parse_args
    a = os.fspath(a)
        ^^^^^^^^^^^^
TypeError: expected str, bytes or os.PathLike object, not bool

Though the error itself isn't terribly a bad thing, elapi should properly validate the input values found in elapi.yml.