|
17 | 17 |
|
18 | 18 | HELPER_ATTRIBUTES = ["job_token", "http_password", "private_token", "oauth_token"]
|
19 | 19 |
|
| 20 | +_CONFIG_PARSER_ERRORS = (configparser.NoOptionError, configparser.NoSectionError) |
| 21 | + |
20 | 22 |
|
21 | 23 | def _resolve_file(filepath: Union[Path, str]) -> str:
|
22 | 24 | resolved = Path(filepath).resolve(strict=True)
|
@@ -148,108 +150,102 @@ def _parse_config(self) -> None:
|
148 | 150 | # Value Error means the option exists but isn't a boolean.
|
149 | 151 | # Get as a string instead as it should then be a local path to a
|
150 | 152 | # CA bundle.
|
151 |
| - try: |
152 |
| - self.ssl_verify = _config.get("global", "ssl_verify") |
153 |
| - except Exception: # pragma: no cover |
154 |
| - pass |
155 |
| - except Exception: |
| 153 | + self.ssl_verify = _config.get("global", "ssl_verify") |
| 154 | + except _CONFIG_PARSER_ERRORS: |
156 | 155 | pass
|
157 | 156 | try:
|
158 | 157 | self.ssl_verify = _config.getboolean(self.gitlab_id, "ssl_verify")
|
159 | 158 | except ValueError:
|
160 | 159 | # Value Error means the option exists but isn't a boolean.
|
161 | 160 | # Get as a string instead as it should then be a local path to a
|
162 | 161 | # CA bundle.
|
163 |
| - try: |
164 |
| - self.ssl_verify = _config.get(self.gitlab_id, "ssl_verify") |
165 |
| - except Exception: # pragma: no cover |
166 |
| - pass |
167 |
| - except Exception: |
| 162 | + self.ssl_verify = _config.get(self.gitlab_id, "ssl_verify") |
| 163 | + except _CONFIG_PARSER_ERRORS: |
168 | 164 | pass
|
169 | 165 |
|
170 | 166 | try:
|
171 | 167 | self.timeout = _config.getint("global", "timeout")
|
172 |
| - except Exception: |
| 168 | + except _CONFIG_PARSER_ERRORS: |
173 | 169 | pass
|
174 | 170 | try:
|
175 | 171 | self.timeout = _config.getint(self.gitlab_id, "timeout")
|
176 |
| - except Exception: |
| 172 | + except _CONFIG_PARSER_ERRORS: |
177 | 173 | pass
|
178 | 174 |
|
179 | 175 | try:
|
180 | 176 | self.private_token = _config.get(self.gitlab_id, "private_token")
|
181 |
| - except Exception: |
| 177 | + except _CONFIG_PARSER_ERRORS: |
182 | 178 | pass
|
183 | 179 |
|
184 | 180 | try:
|
185 | 181 | self.oauth_token = _config.get(self.gitlab_id, "oauth_token")
|
186 |
| - except Exception: |
| 182 | + except _CONFIG_PARSER_ERRORS: |
187 | 183 | pass
|
188 | 184 |
|
189 | 185 | try:
|
190 | 186 | self.job_token = _config.get(self.gitlab_id, "job_token")
|
191 |
| - except Exception: |
| 187 | + except _CONFIG_PARSER_ERRORS: |
192 | 188 | pass
|
193 | 189 |
|
194 | 190 | try:
|
195 | 191 | self.http_username = _config.get(self.gitlab_id, "http_username")
|
196 | 192 | self.http_password = _config.get(
|
197 | 193 | self.gitlab_id, "http_password"
|
198 | 194 | ) # pragma: no cover
|
199 |
| - except Exception: |
| 195 | + except _CONFIG_PARSER_ERRORS: |
200 | 196 | pass
|
201 | 197 |
|
202 | 198 | self._get_values_from_helper()
|
203 | 199 |
|
204 | 200 | try:
|
205 | 201 | self.api_version = _config.get("global", "api_version")
|
206 |
| - except Exception: |
| 202 | + except _CONFIG_PARSER_ERRORS: |
207 | 203 | pass
|
208 | 204 | try:
|
209 | 205 | self.api_version = _config.get(self.gitlab_id, "api_version")
|
210 |
| - except Exception: |
| 206 | + except _CONFIG_PARSER_ERRORS: |
211 | 207 | pass
|
212 | 208 | if self.api_version not in ("4",):
|
213 | 209 | raise GitlabDataError(f"Unsupported API version: {self.api_version}")
|
214 | 210 |
|
215 | 211 | for section in ["global", self.gitlab_id]:
|
216 | 212 | try:
|
217 | 213 | self.per_page = _config.getint(section, "per_page")
|
218 |
| - except Exception: |
| 214 | + except _CONFIG_PARSER_ERRORS: |
219 | 215 | pass
|
220 | 216 | if self.per_page is not None and not 0 <= self.per_page <= 100:
|
221 | 217 | raise GitlabDataError(f"Unsupported per_page number: {self.per_page}")
|
222 | 218 |
|
223 | 219 | try:
|
224 | 220 | self.pagination = _config.get(self.gitlab_id, "pagination")
|
225 |
| - except Exception: |
| 221 | + except _CONFIG_PARSER_ERRORS: |
226 | 222 | pass
|
227 | 223 |
|
228 | 224 | try:
|
229 | 225 | self.order_by = _config.get(self.gitlab_id, "order_by")
|
230 |
| - except Exception: |
| 226 | + except _CONFIG_PARSER_ERRORS: |
231 | 227 | pass
|
232 | 228 |
|
233 | 229 | try:
|
234 | 230 | self.user_agent = _config.get("global", "user_agent")
|
235 |
| - except Exception: |
| 231 | + except _CONFIG_PARSER_ERRORS: |
236 | 232 | pass
|
237 | 233 | try:
|
238 | 234 | self.user_agent = _config.get(self.gitlab_id, "user_agent")
|
239 |
| - except Exception: |
| 235 | + except _CONFIG_PARSER_ERRORS: |
240 | 236 | pass
|
241 | 237 |
|
242 | 238 | try:
|
243 | 239 | self.retry_transient_errors = _config.getboolean(
|
244 | 240 | "global", "retry_transient_errors"
|
245 | 241 | )
|
246 |
| - except Exception: |
| 242 | + except _CONFIG_PARSER_ERRORS: |
247 | 243 | pass
|
248 | 244 | try:
|
249 | 245 | self.retry_transient_errors = _config.getboolean(
|
250 | 246 | self.gitlab_id, "retry_transient_errors"
|
251 | 247 | )
|
252 |
| - except Exception: |
| 248 | + except _CONFIG_PARSER_ERRORS: |
253 | 249 | pass
|
254 | 250 |
|
255 | 251 | def _get_values_from_helper(self) -> None:
|
|
0 commit comments