|
2 | 2 | from typing import Union |
3 | 3 |
|
4 | 4 | from ._overload_history import reinitiate_config |
5 | | -from .config import APIToken |
| 5 | +from .config import ( |
| 6 | + MinimalActiveConfiguration, |
| 7 | + APIToken, |
| 8 | + KEY_HOST, |
| 9 | + ELAB_HOST_URL_API_SUFFIX, |
| 10 | + KEY_API_TOKEN, |
| 11 | + KEY_EXPORT_DIR, |
| 12 | + KEY_UNSAFE_TOKEN_WARNING, |
| 13 | + KEY_ENABLE_HTTP2, |
| 14 | + KEY_VERIFY_SSL, |
| 15 | + KEY_TIMEOUT, |
| 16 | + KEY_DEVELOPMENT_MODE, |
| 17 | + KEY_PLUGIN_KEY_NAME, |
| 18 | +) |
6 | 19 | from ..styles import Missing |
7 | 20 |
|
8 | 21 |
|
9 | | -def _run_validation_once() -> None: |
10 | | - if get_development_mode() is False or get_development_mode() == Missing(): |
11 | | - reinitiate_config() |
12 | | - |
13 | | - |
14 | | -def get_active_host() -> str: |
15 | | - from .config import KEY_HOST, MinimalActiveConfiguration |
16 | | - |
17 | | - _run_validation_once() |
| 22 | +def get_active_host(*, skip_validation: bool = False) -> str: |
| 23 | + if not skip_validation: |
| 24 | + _development_mode_validation_switch() |
18 | 25 | return MinimalActiveConfiguration().get_value(KEY_HOST) |
19 | 26 |
|
20 | 27 |
|
21 | | -def get_active_host_url_without_api_subdir() -> Union[str, Missing]: |
| 28 | +def get_active_host_url_without_api_subdir( |
| 29 | + *, skip_validation: bool = False |
| 30 | +) -> Union[str, Missing]: |
22 | 31 | import re |
23 | | - from .config import ELAB_HOST_URL_API_SUFFIX |
24 | 32 |
|
25 | | - if (host := get_active_host()) != Missing(): |
| 33 | + if (host := get_active_host(skip_validation=skip_validation)) != Missing(): |
26 | 34 | return re.sub( |
27 | 35 | ELAB_HOST_URL_API_SUFFIX, |
28 | 36 | r"", |
29 | | - get_active_host(), |
| 37 | + get_active_host(skip_validation=skip_validation), |
30 | 38 | count=1, |
31 | 39 | flags=re.IGNORECASE, |
32 | 40 | ) |
33 | 41 | return host |
34 | 42 |
|
35 | 43 |
|
36 | | -def get_active_api_token() -> APIToken: |
37 | | - from .config import KEY_API_TOKEN, MinimalActiveConfiguration |
38 | | - |
39 | | - _run_validation_once() |
| 44 | +def get_active_api_token(*, skip_validation: bool = False) -> APIToken: |
| 45 | + if not skip_validation: |
| 46 | + _development_mode_validation_switch() |
40 | 47 | return MinimalActiveConfiguration().get_value(KEY_API_TOKEN) |
41 | 48 |
|
42 | 49 |
|
43 | | -def get_active_export_dir() -> Path: |
44 | | - from .config import KEY_EXPORT_DIR, MinimalActiveConfiguration |
45 | | - |
46 | | - _run_validation_once() |
| 50 | +def get_active_export_dir(*, skip_validation: bool = False) -> Path: |
| 51 | + if not skip_validation: |
| 52 | + _development_mode_validation_switch() |
47 | 53 | return MinimalActiveConfiguration().get_value(KEY_EXPORT_DIR) |
48 | 54 |
|
49 | 55 |
|
50 | | -def get_active_unsafe_token_warning() -> bool: |
51 | | - from .config import KEY_UNSAFE_TOKEN_WARNING, MinimalActiveConfiguration |
52 | | - |
53 | | - _run_validation_once() |
| 56 | +def get_active_unsafe_token_warning(*, skip_validation: bool = False) -> bool: |
| 57 | + if not skip_validation: |
| 58 | + _development_mode_validation_switch() |
54 | 59 | return MinimalActiveConfiguration().get_value(KEY_UNSAFE_TOKEN_WARNING) |
55 | 60 |
|
56 | 61 |
|
57 | | -def get_active_enable_http2() -> bool: |
58 | | - from .config import KEY_ENABLE_HTTP2, MinimalActiveConfiguration |
59 | | - |
60 | | - _run_validation_once() |
| 62 | +def get_active_enable_http2(*, skip_validation: bool = False) -> bool: |
| 63 | + if not skip_validation: |
| 64 | + _development_mode_validation_switch() |
61 | 65 | return MinimalActiveConfiguration().get_value(KEY_ENABLE_HTTP2) |
62 | 66 |
|
63 | 67 |
|
64 | | -def get_active_verify_ssl() -> bool: |
65 | | - from .config import KEY_VERIFY_SSL, MinimalActiveConfiguration |
66 | | - |
67 | | - _run_validation_once() |
| 68 | +def get_active_verify_ssl(*, skip_validation: bool = False) -> bool: |
| 69 | + if not skip_validation: |
| 70 | + _development_mode_validation_switch() |
68 | 71 | return MinimalActiveConfiguration().get_value(KEY_VERIFY_SSL) |
69 | 72 |
|
70 | 73 |
|
71 | | -def get_active_timeout() -> float: |
72 | | - from .config import KEY_TIMEOUT, MinimalActiveConfiguration |
73 | | - |
74 | | - _run_validation_once() |
| 74 | +def get_active_timeout(*, skip_validation: bool = False) -> float: |
| 75 | + if not skip_validation: |
| 76 | + _development_mode_validation_switch() |
75 | 77 | return MinimalActiveConfiguration().get_value(KEY_TIMEOUT) |
76 | 78 |
|
77 | 79 |
|
78 | | -def get_development_mode() -> bool: |
79 | | - from .config import KEY_DEVELOPMENT_MODE, MinimalActiveConfiguration |
| 80 | +def _development_mode_validation_switch() -> None: |
| 81 | + _value = MinimalActiveConfiguration().get_value(KEY_DEVELOPMENT_MODE) |
| 82 | + if _value is False or _value == Missing(): |
| 83 | + reinitiate_config() |
80 | 84 |
|
81 | | - return MinimalActiveConfiguration().get_value(KEY_DEVELOPMENT_MODE) |
82 | 85 |
|
| 86 | +def get_development_mode(*, skip_validation: bool = False) -> bool: |
| 87 | + if not skip_validation: |
| 88 | + _development_mode_validation_switch() |
| 89 | + return MinimalActiveConfiguration().get_value(KEY_DEVELOPMENT_MODE) |
83 | 90 |
|
84 | | -def get_active_plugin_configs() -> dict: |
85 | | - from .config import KEY_PLUGIN_KEY_NAME, MinimalActiveConfiguration |
86 | 91 |
|
87 | | - _run_validation_once() |
| 92 | +def get_active_plugin_configs(*, skip_validation: bool = False) -> dict: |
| 93 | + if not skip_validation: |
| 94 | + _development_mode_validation_switch() |
88 | 95 | return MinimalActiveConfiguration().get_value(KEY_PLUGIN_KEY_NAME) |
0 commit comments