| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 824cda6 commit 97c4619
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1432,6 +1432,86 @@ def execute(self, request: str | graphql.Source, *args: Any, **kwargs: Any) -> A | |||
| 1432 | 1432 | ||
| 1433 | 1433 | return result | |
| 1434 | 1434 | ||
| 1435 | + @classmethod | ||
| 1436 | + def from_config( | ||
| 1437 | + cls, | ||
| 1438 | + gitlab_id: str | None = None, | ||
| 1439 | + config_files: list[str] | None = None, | ||
| 1440 | + **kwargs: Any, | ||
| 1441 | + ) -> Gitlab: | ||
| 1442 | + """Create a Gitlab connection from configuration files. | ||
| 1443 | + | ||
| 1444 | + Args: | ||
| 1445 | + gitlab_id: ID of the configuration section. | ||
| 1446 | + config_files list[str]: List of paths to configuration files. | ||
| 1447 | + | ||
| 1448 | + kwargs: | ||
| 1449 | + session requests.Session: Custom requests Session | ||
| 1450 | + | ||
| 1451 | + Returns: | ||
| 1452 | + A Gitlab connection. | ||
| 1453 | + | ||
| 1454 | + Raises: | ||
| 1455 | + gitlab.config.GitlabDataError: If the configuration is not correct. | ||
| 1456 | + """ | ||
| 1457 | + config = gitlab.config.GitlabConfigParser( | ||
| 1458 | + gitlab_id=gitlab_id, config_files=config_files | ||
| 1459 | + ) | ||
| 1460 | + return cls( | ||
| 1461 | + config.url, | ||
| 1462 | + private_token=config.private_token, | ||
| 1463 | + oauth_token=config.oauth_token, | ||
| 1464 | + job_token=config.job_token, | ||
| 1465 | + ssl_verify=config.ssl_verify, | ||
| 1466 | + timeout=config.timeout, | ||
| 1467 | + http_username=config.http_username, | ||
| 1468 | + http_password=config.http_password, | ||
| 1469 | + api_version=config.api_version, | ||
| 1470 | + per_page=config.per_page, | ||
| 1471 | + pagination=config.pagination, | ||
| 1472 | + order_by=config.order_by, | ||
| 1473 | + user_agent=config.user_agent, | ||
| 1474 | + retry_transient_errors=config.retry_transient_errors, | ||
| 1475 | + keep_base_url=config.keep_base_url, | ||
| 1476 | + **kwargs, | ||
| 1477 | + ) | ||
| 1478 | + | ||
| 1479 | + def _set_auth_info(self) -> None: | ||
| 1480 | + tokens = [ | ||
| 1481 | + token | ||
| 1482 | + for token in [self.private_token, self.oauth_token, self.job_token] | ||
| 1483 | + if token | ||
| 1484 | + ] | ||
| 1485 | + if len(tokens) > 1: | ||
| 1486 | + raise ValueError( | ||
| 1487 | + "Only one of private_token, oauth_token or job_token should " | ||
| 1488 | + "be defined" | ||
| 1489 | + ) | ||
| 1490 | + if (self.http_username and not self.http_password) or ( | ||
| 1491 | + not self.http_username and self.http_password | ||
| 1492 | + ): | ||
| 1493 | + raise ValueError("Both http_username and http_password should be defined") | ||
| 1494 | + if tokens and self.http_username: | ||
| 1495 | + raise ValueError( | ||
| 1496 | + "Only one of token authentications or http " | ||
| 1497 | + "authentication should be defined" | ||
| 1498 | + ) | ||
| 1499 | + | ||
| 1500 | + self._auth: requests.auth.AuthBase | None = None | ||
| 1501 | + if self.private_token: | ||
| 1502 | + self._auth = _backends.PrivateTokenAuth(self.private_token) | ||
| 1503 | + | ||
| 1504 | + if self.oauth_token: | ||
| 1505 | + self._auth = _backends.OAuthTokenAuth(self.oauth_token) | ||
| 1506 | + | ||
| 1507 | + if self.job_token: | ||
| 1508 | + self._auth = _backends.JobTokenAuth(self.job_token) | ||
| 1509 | + | ||
| 1510 | + if self.http_username and self.http_password: | ||
| 1511 | + self._auth = requests.auth.HTTPBasicAuth( | ||
| 1512 | + self.http_username, self.http_password | ||
| 1513 | + ) | ||
| 1514 | + | ||
| 1435 | 1515 | ||
| 1436 | 1516 | class AsyncGraphQL(_BaseGraphQL): | |
| 1437 | 1517 | def __init__( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments