|
1 | 1 | from checkers.google_com_checker import GoogleComChecker
|
2 | 2 |
|
| 3 | +import string |
| 4 | +import os |
| 5 | +import ast |
| 6 | + |
3 | 7 |
|
4 | 8 | # enable to get more information in logs
|
5 | 9 | DEBUG = False
|
6 | 10 |
|
| 11 | + |
7 | 12 | """
|
8 | 13 | Database settings (do not try to change after creation of the database)
|
9 | 14 | """
|
|
19 | 24 | DB_MAX_DOMAIN_LENGTH = 128
|
20 | 25 | DB_AUTH_DATA_MAX_LENGTH = 64
|
21 | 26 |
|
| 27 | + |
22 | 28 | """
|
23 | 29 | Fetcher settings
|
24 | 30 | """
|
|
67 | 73 | GoogleComChecker,
|
68 | 74 | ]
|
69 | 75 |
|
| 76 | + |
70 | 77 | """
|
71 | 78 | Server settings
|
72 | 79 | """
|
|
81 | 88 |
|
82 | 89 | PROXY_PROVIDER_SERVER_API_CONFIG_FETCH_CONFIG = {
|
83 | 90 | 'fields': [
|
84 |
| - 'address', 'protocol', 'auth_data', 'domain', 'port', 'last_check_time', 'next_check_time', 'number_of_bad_checks', |
85 |
| - 'bad_proxy', 'uptime', 'response_time', 'white_ipv4', 'white_ipv6', 'city', 'country_code', 'region' |
| 91 | + 'address', 'protocol', 'auth_data', 'domain', 'port', |
| 92 | + 'last_check_time', 'next_check_time', |
| 93 | + 'number_of_bad_checks', 'bad_proxy', 'uptime', |
| 94 | + 'response_time', 'white_ipv4', 'white_ipv6', |
| 95 | + 'city', 'country_code', 'region' |
86 | 96 | ],
|
87 | 97 | 'filter_fields': [
|
88 |
| - 'last_check_time', 'protocol', 'number_of_bad_checks', 'bad_proxy', 'uptime', 'response_time' |
| 98 | + 'last_check_time', 'protocol', 'number_of_bad_checks', 'bad_proxy', |
| 99 | + 'uptime', 'response_time' |
| 100 | + ], |
| 101 | + 'order_by_fields': [ |
| 102 | + 'last_check_time', 'number_of_bad_checks', 'uptime', 'response_time', |
| 103 | + 'country_code' |
89 | 104 | ],
|
90 |
| - 'order_by_fields': ['last_check_time', 'number_of_bad_checks', 'uptime', 'response_time', 'country_code'], |
91 | 105 | 'default_order_by_fields': ['response_time', ],
|
92 | 106 | }
|
93 | 107 |
|
|
102 | 116 | }
|
103 | 117 |
|
104 | 118 | TEMPLATES_PATH = "server/templates"
|
| 119 | + |
| 120 | + |
| 121 | +""" |
| 122 | +Loading from the environment |
| 123 | +""" |
| 124 | + |
| 125 | + |
| 126 | +def load_settings_from_environment(): |
| 127 | + for key, val in globals().items(): |
| 128 | + # filter only variables with capital letters or digits or undescore |
| 129 | + rest = "".join([ |
| 130 | + ch for ch in key |
| 131 | + if ch not in string.ascii_uppercase and ch not in string.digits and ch != '_' |
| 132 | + ]) |
| 133 | + if len(rest) > 0: |
| 134 | + continue |
| 135 | + |
| 136 | + env_key = "PROXY_PY_" + key |
| 137 | + if env_key in os.environ: |
| 138 | + env_value = os.environ[env_key] |
| 139 | + try: |
| 140 | + globals()[key] = ast.literal_eval(env_value) |
| 141 | + except: |
| 142 | + raise Exception( |
| 143 | + f"An error happened during parsing environment value. " + |
| 144 | + f"Key = {env_key}, Value = {env_value}" |
| 145 | + ) |
| 146 | + |
| 147 | + |
| 148 | +load_settings_from_environment() |
0 commit comments