ZoneMinder / mlapi

An easy to use/extend object recognition API you can locally install. Python+Flask. Also works with ZMES!
Other
58 stars 35 forks source link

Secrets file is required, not optional #51

Closed jantman closed 8 months ago

jantman commented 8 months ago

The provided example mlapiconfig.ini says that the secrets file is optional:

[general]
# This is an optional file
# If specified, you can specify tokens with secret values in that file
# and onlt refer to the tokens in your main config file

#secrets=./secrets.ini
secrets=/etc/zm/secrets.ini

However, if I comment out both secrets= lines, mlapi dies with an unhandled error:

mlapi-1  | Dec 18 2023 06:13:34.796375 [ERR] Error parsing config:/etc/mlapiconfig.ini
mlapi-1  | Dec 18 2023 06:13:34.796390 [ERR] Error was:'NoneType' object is not iterable
mlapi-1  | Dec 18 2023 06:13:34.797252 [FAT] error: Traceback:Traceback (most recent call last):
mlapi-1  |   File "/mlapi/modules/utils.py", line 403, in process_config
mlapi-1  |     secrets = pyzmutils.read_config(g.config['secrets'])
mlapi-1  |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mlapi-1  |   File "/usr/local/lib/python3.11/dist-packages/pyzm/helpers/utils.py", line 46, in read_config
mlapi-1  |     config_file.read(file)
mlapi-1  |   File "/usr/lib/python3.11/configparser.py", line 710, in read
mlapi-1  |     for filename in filenames:
mlapi-1  | TypeError: 'NoneType' object is not iterable

And if I set them to secrets= (empty string), mlapi dies with a different unhandled error:

mlapi-1  | Dec 18 2023 06:18:47.444560 [INF] Reading config from: /etc/mlapiconfig.ini
mlapi-1  | Dec 18 2023 06:18:47.444588 [INF] Reading secrets from: 
mlapi-1  | Dec 18 2023 06:18:47.444666 [ERR] Error parsing config:/etc/mlapiconfig.ini
mlapi-1  | Dec 18 2023 06:18:47.444680 [ERR] Error was:[Errno 2] No such file or directory: ''
mlapi-1  | Dec 18 2023 06:18:47.445022 [FAT] error: Traceback:Traceback (most recent call last):
mlapi-1  |   File "/mlapi/modules/utils.py", line 262, in process_config
mlapi-1  |     with open(secrets_filename) as f:
mlapi-1  |          ^^^^^^^^^^^^^^^^^^^^^^
mlapi-1  | FileNotFoundError: [Errno 2] No such file or directory: ''

It seems like either the example config needs to be updated to clarify that a secrets file is required or (preferred for my use case) the code needs to actually handle not having a secrets file, as the example config indicates.

I should hopefully have a PR coming to fix this, once I can actually get mlapi up and running.

jantman commented 8 months ago

Closing this. There's a similar issue with pyzm and it looks like easy fix is just to provide an empty secrets file if you don't want to use it.