mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 18:02:41 +02:00
☝🧐 — Validate config file readability
This commit is contained in:
parent
416728e546
commit
8224ca8dbd
2 changed files with 15 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
- 🐛 — Fix --config option for some commands
|
- 🐛 — Fix --config option for some commands
|
||||||
|
- ☝️🧐 — Validate config file readability
|
||||||
|
|
||||||
## 0.1.0
|
## 0.1.0
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,16 @@ def coroutine(f):
|
||||||
return wrapper
|
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()
|
@click.group()
|
||||||
def cli():
|
def cli():
|
||||||
pass
|
pass
|
||||||
|
@ -93,6 +103,7 @@ def agent(server_url, auth, max_tasks, wait_time, log_level):
|
||||||
help="Path of the configuration file. "
|
help="Path of the configuration file. "
|
||||||
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
|
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
|
||||||
envvar="ARGOS_YAML_FILE",
|
envvar="ARGOS_YAML_FILE",
|
||||||
|
callback=validate_config_access,
|
||||||
)
|
)
|
||||||
@click.option("--reload", is_flag=True, help="Enable hot reloading")
|
@click.option("--reload", is_flag=True, help="Enable hot reloading")
|
||||||
def start(host, port, config, reload):
|
def start(host, port, config, reload):
|
||||||
|
@ -140,6 +151,7 @@ def validate_max_results(ctx, param, value):
|
||||||
help="Path of the configuration file. "
|
help="Path of the configuration file. "
|
||||||
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
|
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
|
||||||
envvar="ARGOS_YAML_FILE",
|
envvar="ARGOS_YAML_FILE",
|
||||||
|
callback=validate_config_access,
|
||||||
)
|
)
|
||||||
@coroutine
|
@coroutine
|
||||||
async def cleandb(max_results, max_lock_seconds, config):
|
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. "
|
help="Path of the configuration file. "
|
||||||
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
|
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
|
||||||
envvar="ARGOS_YAML_FILE",
|
envvar="ARGOS_YAML_FILE",
|
||||||
|
callback=validate_config_access,
|
||||||
)
|
)
|
||||||
@coroutine
|
@coroutine
|
||||||
async def reload_config(config):
|
async def reload_config(config):
|
||||||
|
@ -200,6 +213,7 @@ async def reload_config(config):
|
||||||
help="Path of the configuration file. "
|
help="Path of the configuration file. "
|
||||||
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
|
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
|
||||||
envvar="ARGOS_YAML_FILE",
|
envvar="ARGOS_YAML_FILE",
|
||||||
|
callback=validate_config_access,
|
||||||
)
|
)
|
||||||
@coroutine
|
@coroutine
|
||||||
async def migrate(config):
|
async def migrate(config):
|
||||||
|
|
Loading…
Reference in a new issue