config: Use logic from zulip_tools, to support bools.

This commit is contained in:
Alex Vandiver 2024-03-05 16:22:49 +00:00 committed by Tim Abbott
parent b36f389e9e
commit 0f70ab7679
2 changed files with 14 additions and 8 deletions

View File

@ -588,7 +588,7 @@ def get_config(
config_file: configparser.RawConfigParser, config_file: configparser.RawConfigParser,
section: str, section: str,
key: str, key: str,
default_value: None, default_value: None = None,
) -> Optional[str]: ... ) -> Optional[str]: ...
@overload @overload
def get_config( def get_config(

View File

@ -1,6 +1,8 @@
import configparser import configparser
import os import os
from typing import Optional, overload from typing import Optional, Union, overload
from scripts.lib.zulip_tools import get_config as get_config_from_file
class ZulipSettingsError(Exception): class ZulipSettingsError(Exception):
@ -22,12 +24,12 @@ else:
secrets_file.read(os.path.join(DEPLOY_ROOT, "zproject/dev-secrets.conf")) secrets_file.read(os.path.join(DEPLOY_ROOT, "zproject/dev-secrets.conf"))
@overload
def get_secret(key: str, default_value: str, development_only: bool = False) -> str: ...
@overload @overload
def get_secret( def get_secret(
key: str, default_value: Optional[str] = None, development_only: bool = False key: str, default_value: None = None, development_only: bool = False
) -> Optional[str]: ... ) -> Optional[str]: ...
@overload
def get_secret(key: str, default_value: str, development_only: bool = False) -> str: ...
def get_secret( def get_secret(
key: str, default_value: Optional[str] = None, development_only: bool = False key: str, default_value: Optional[str] = None, development_only: bool = False
) -> Optional[str]: ) -> Optional[str]:
@ -45,12 +47,16 @@ def get_mandatory_secret(key: str) -> str:
return secret return secret
@overload
def get_config(section: str, key: str, default_value: None = None) -> Optional[str]: ...
@overload @overload
def get_config(section: str, key: str, default_value: str) -> str: ... def get_config(section: str, key: str, default_value: str) -> str: ...
@overload @overload
def get_config(section: str, key: str, default_value: Optional[str] = None) -> Optional[str]: ... def get_config(section: str, key: str, default_value: bool) -> bool: ...
def get_config(section: str, key: str, default_value: Optional[str] = None) -> Optional[str]: def get_config(
return config_file.get(section, key, fallback=default_value) section: str, key: str, default_value: Union[str, bool, None] = None
) -> Union[str, bool, None]:
return get_config_from_file(config_file, section, key, default_value)
def get_from_file_if_exists(path: str) -> str: def get_from_file_if_exists(path: str) -> str: