🔀 Merge branch 'feature/validate-config-access' into 'main'

🧐 — Validate config file readability

See merge request framasoft/framaspace/argos!48
This commit is contained in:
Luc Didry 2024-04-29 12:23:34 +00:00
commit 6f405f0912
2 changed files with 15 additions and 0 deletions

View file

@ -3,6 +3,7 @@
## [Unreleased]
- 🐛 — Fix --config option for some commands
- ☝️🧐 — Validate config file readability
## 0.1.0

View file

@ -31,6 +31,16 @@ def coroutine(f):
return wrapper
def validate_config_access(ctx, param, value):
if os.path.isfile(value) and os.access(value, os.R_OK):
return value
if os.path.isfile(value):
raise click.BadParameter(f"the file {value} is not readabale.")
raise click.BadParameter(f"the file {value} does not exists or is not reachable.")
@click.group()
def cli():
pass
@ -93,6 +103,7 @@ def agent(server_url, auth, max_tasks, wait_time, log_level):
help="Path of the configuration file. "
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
envvar="ARGOS_YAML_FILE",
callback=validate_config_access,
)
@click.option("--reload", is_flag=True, help="Enable hot reloading")
def start(host, port, config, reload):
@ -140,6 +151,7 @@ def validate_max_results(ctx, param, value):
help="Path of the configuration file. "
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
envvar="ARGOS_YAML_FILE",
callback=validate_config_access,
)
@coroutine
async def cleandb(max_results, max_lock_seconds, config):
@ -170,6 +182,7 @@ async def cleandb(max_results, max_lock_seconds, config):
help="Path of the configuration file. "
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
envvar="ARGOS_YAML_FILE",
callback=validate_config_access,
)
@coroutine
async def reload_config(config):
@ -200,6 +213,7 @@ async def reload_config(config):
help="Path of the configuration file. "
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
envvar="ARGOS_YAML_FILE",
callback=validate_config_access,
)
@coroutine
async def migrate(config):