Skip to content

Commit d139d60

Browse files
committed
feat(feat): Add class method to create Gitlab connection from configuration files
This commit introduces a new class method from_config to the GraphQL class. This method allows users to create a Gitlab connection object by reading configuration files. Users can specify the ID and paths of the configuration files, and the method will parse the connection information (e.g., URL, tokens, SSL verification, etc.) from the files to create a pre-configured Gitlab object. This feature provides a more convenient and configurable way to manage GitLab connections, especially useful for scenarios requiring connections to multiple GitLab instances or aiming to separate connection configurations from the codebase. Example usage (assuming the configuration file is gitlab.ini): ```python gl = GraphQL.from_config(config_files=['gitlab.ini']) ``` Internally, this method utilizes gitlab.config.GitlabConfigParser to handle the parsing of the configuration files.
1 parent 4891b1e commit d139d60

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

gitlab/client.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,49 @@ def __init__(
13351335
keep_base_url: bool = False,
13361336
**kwargs: Any,
13371337
) -> None:
1338+
self._api_version = str(api_version)
1339+
self._server_version: str | None = None
1340+
self._server_revision: str | None = None
1341+
self._base_url = utils.get_base_url(url)
1342+
self._url = f"{self._base_url}/api/v{api_version}"
1343+
#: Timeout to use for requests to gitlab server
1344+
self.timeout = timeout
1345+
self.retry_transient_errors = retry_transient_errors
1346+
self.keep_base_url = keep_base_url
1347+
#: Headers that will be used in request to GitLab
1348+
self.headers = {"User-Agent": user_agent}
1349+
1350+
#: Whether SSL certificates should be validated
1351+
self.ssl_verify = ssl_verify
1352+
1353+
self.private_token = private_token
1354+
self.http_username = http_username
1355+
self.http_password = http_password
1356+
self.oauth_token = oauth_token
1357+
self.job_token = job_token
1358+
self._set_auth_info()
1359+
1360+
#: Create a session object for requests
1361+
_backend: type[_backends.DefaultBackend] = kwargs.pop(
1362+
"backend", _backends.DefaultBackend
1363+
)
1364+
self._backend = _backend(**kwargs)
1365+
self.session = self._backend.client
1366+
1367+
self.per_page = per_page
1368+
self.pagination = pagination
1369+
self.order_by = order_by
1370+
1371+
# We only support v4 API at this time
1372+
if self._api_version not in ("4",):
1373+
raise ModuleNotFoundError(f"gitlab.v{self._api_version}.objects")
1374+
# NOTE: We must delay import of gitlab.v4.objects until now or
1375+
# otherwise it will cause circular import errors
1376+
from gitlab.v4 import objects
1377+
1378+
self._objects = objects
1379+
self.user: objects.CurrentUser | None = None
1380+
13381381
super().__init__(
13391382
url=url,
13401383
token=token,

0 commit comments

Comments
 (0)