Read the environment with typed parsers and apply the documented defaults
set_defaults() assigned os.getenv() results directly, which overwrote the argparse defaults with None whenever a variable was unset. A default container therefore ran "seaf-cli config -k delete_confirm_threshold -v None", and the same for upload_limit and download_limit: none of the three documented defaults were ever applied. SEAFILE_UID and SEAFILE_GID had a second problem. argparse type=int applies only to command line flags, never to set_defaults, so both stayed strings. The check in setup_uid compares them against pwd integers, and a string is never equal to one, so usermod ran on every start. dsc/config.py reads each variable with its documented default and rejects a malformed or negative value at startup, naming the variable, instead of passing it on. An empty variable counts as unset. Booleans are now rendered as true and false rather than Python's True and False. The daemon reads disable_verify_certificate with its boolean accessor, which does not recognise the capitalised form. I could not run the daemon to confirm the previous value's effect, since the AppImage is x86_64 only. seaf-cli is no longer given a None value for any option.
This commit is contained in:
1 parent
87b76b80f6
commit
e6034a69a6
8 files changed
+283
-26
No files matched your search
@@ -7,6 +7,7 @@ import signal
|
||||
import sys
|
||||
|
||||
from dsc import SeafileClient, const
|
||||
from dsc.config import env_bool, env_int, env_str
|
||||
from dsc.errors import ConfigError, DscError, GracefulShutdown
|
||||
from dsc.misc import setup_uid, create_dir
|
||||
from dsc.paths import plan_lib_dirs
|
||||
@@ -26,6 +27,30 @@ def install_signal_handlers():
|
||||
signal.signal(signum, handle_signal)
|
||||
|
||||
|
||||
def defaults_from_env() -> dict:
|
||||
"""
|
||||
Read every setting from the environment with its documented default.
|
||||
|
||||
Reading these directly leaves an unset variable as None, which reaches
|
||||
seaf-cli as the string "None" and silently replaces the documented value.
|
||||
"""
|
||||
return dict(
|
||||
server=env_str("SERVER_HOST"),
|
||||
username=env_str("USERNAME"),
|
||||
password=env_str("PASSWORD"),
|
||||
password_file=env_str("PASSWORD_FILE"),
|
||||
token=env_str("TOKEN"),
|
||||
token_file=env_str("TOKEN_FILE"),
|
||||
libraries=env_str("LIBRARY_ID"),
|
||||
uid=env_int("SEAFILE_UID", 1000),
|
||||
gid=env_int("SEAFILE_GID", 1000),
|
||||
upload_limit=env_int("UPLOAD_LIMIT", 0),
|
||||
download_limit=env_int("DOWNLOAD_LIMIT", 0),
|
||||
delete_confirm_threshold=env_int("DELETE_CONFIRM_THRESHOLD", 500),
|
||||
disable_verify_certificate=env_bool("DISABLE_VERIFY_CERTIFICATE", False),
|
||||
)
|
||||
|
||||
|
||||
def resolve_libraries(client, requested: str, server: str) -> set:
|
||||
"""Map the requested names or IDs to library IDs that are not synced yet."""
|
||||
libs_to_sync = set()
|
||||
@@ -94,21 +119,11 @@ def main():
|
||||
parser.add_argument("--disable-verify-certificate", action="store_true")
|
||||
parser.add_argument("--delete-confirm-threshold", type=int, default=500)
|
||||
|
||||
parser.set_defaults(
|
||||
server=os.getenv("SERVER_HOST"),
|
||||
username=os.getenv("USERNAME"),
|
||||
password=os.getenv("PASSWORD"),
|
||||
password_file=os.getenv("PASSWORD_FILE"),
|
||||
token=os.getenv("TOKEN"),
|
||||
token_file=os.getenv("TOKEN_FILE"),
|
||||
libraries=os.getenv("LIBRARY_ID"),
|
||||
uid=os.getenv("SEAFILE_UID", default=1000),
|
||||
gid=os.getenv("SEAFILE_GID", default=1000),
|
||||
upload_limit=os.getenv("UPLOAD_LIMIT"),
|
||||
download_limit=os.getenv("DOWNLOAD_LIMIT"),
|
||||
disable_verify_certificate=os.getenv("DISABLE_VERIFY_CERTIFICATE") in ("true", "1", "True"),
|
||||
delete_confirm_threshold=os.getenv("DELETE_CONFIRM_THRESHOLD"),
|
||||
)
|
||||
try:
|
||||
parser.set_defaults(**defaults_from_env())
|
||||
except ConfigError as err:
|
||||
_lg.error("%s", err)
|
||||
return 2
|
||||
args = parser.parse_args()
|
||||
if not args.server:
|
||||
parser.error("Seafile server is not specified")
|
||||
|
||||
Reference in new issue
Block a user