|
5 | 5 | # pylint: disable=import-error |
6 | 6 | import yaml |
7 | 7 |
|
| 8 | +from bookstack_file_exporter.common.util import check_var |
8 | 9 | from bookstack_file_exporter.config_helper import models |
9 | 10 | from bookstack_file_exporter.config_helper.remote import StorageProviderConfig |
10 | 11 |
|
@@ -83,17 +84,17 @@ def _generate_credentials(self) -> Tuple[str, str]: |
83 | 84 | token_secret = self.user_inputs.credentials.token_secret |
84 | 85 |
|
85 | 86 | # check to see if env var is specified, if so, it takes precedence |
86 | | - token_id = self._check_var(_BOOKSTACK_TOKEN_FIELD, token_id) |
87 | | - token_secret = self._check_var(_BOOKSTACK_TOKEN_SECRET_FIELD, token_secret) |
| 87 | + token_id = check_var(_BOOKSTACK_TOKEN_FIELD, token_id) |
| 88 | + token_secret = check_var(_BOOKSTACK_TOKEN_SECRET_FIELD, token_secret) |
88 | 89 | return token_id, token_secret |
89 | 90 |
|
90 | 91 | def _generate_remote_config(self) -> Dict[str, StorageProviderConfig]: |
91 | 92 | object_config = {} |
92 | 93 | # check for optional minio credentials if configuration is set in yaml configuration file |
93 | 94 | if self.user_inputs.minio: |
94 | | - minio_access_key = self._check_var(_MINIO_ACCESS_KEY_FIELD, |
| 95 | + minio_access_key = check_var(_MINIO_ACCESS_KEY_FIELD, |
95 | 96 | self.user_inputs.minio.access_key) |
96 | | - minio_secret_key = self._check_var(_MINIO_SECRET_KEY_FIELD, |
| 97 | + minio_secret_key = check_var(_MINIO_SECRET_KEY_FIELD, |
97 | 98 | self.user_inputs.minio.secret_key) |
98 | 99 |
|
99 | 100 | object_config["minio"] = StorageProviderConfig(minio_access_key, |
@@ -177,24 +178,24 @@ def object_storage_config(self) -> Dict[str, StorageProviderConfig]: |
177 | 178 | """return remote storage configuration""" |
178 | 179 | return self._object_storage_config |
179 | 180 |
|
180 | | - @staticmethod |
181 | | - def _check_var(env_key: str, default_val: str) -> str: |
182 | | - """ |
183 | | - :param: env_key = the environment variable to check |
184 | | - :param: default_val = the default value if any to set if env variable not set |
185 | | - |
186 | | - :return: env_key if present or default_val if not |
187 | | - :throws: ValueError if both parameters are empty. |
188 | | - """ |
189 | | - env_value = os.environ.get(env_key, "") |
190 | | - # env value takes precedence |
191 | | - if env_value: |
192 | | - log.debug("""env key: %s specified. |
193 | | - Will override configuration file value if set.""", env_key) |
194 | | - return env_value |
195 | | - # check for optional inputs, if env and input is missing |
196 | | - if not env_value and not default_val: |
197 | | - raise ValueError(f"""{env_key} is not specified in env and is |
198 | | - missing from configuration - at least one should be set""") |
199 | | - # fall back to configuration file value if present |
200 | | - return default_val |
| 181 | + # @staticmethod |
| 182 | + # def _check_var(env_key: str, default_val: str) -> str: |
| 183 | + # """ |
| 184 | + # :param: env_key = the environment variable to check |
| 185 | + # :param: default_val = the default value if any to set if env variable not set |
| 186 | + |
| 187 | + # :return: env_key if present or default_val if not |
| 188 | + # :throws: ValueError if both parameters are empty. |
| 189 | + # """ |
| 190 | + # env_value = os.environ.get(env_key, "") |
| 191 | + # # env value takes precedence |
| 192 | + # if env_value: |
| 193 | + # log.debug("""env key: %s specified. |
| 194 | + # Will override configuration file value if set.""", env_key) |
| 195 | + # return env_value |
| 196 | + # # check for optional inputs, if env and input is missing |
| 197 | + # if not env_value and not default_val: |
| 198 | + # raise ValueError(f"""{env_key} is not specified in env and is |
| 199 | + # missing from configuration - at least one should be set""") |
| 200 | + # # fall back to configuration file value if present |
| 201 | + # return default_val |
0 commit comments