8000 feat(api): added support for tls client authentication against revers… by mgrechukh · Pull Request #3111 · python-gitlab/python-gitlab · GitHub
[go: up one dir, main page]

Skip to content

feat(api): added support for tls client authentication against revers… #3111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions gitlab/client.py
8000 8000
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
or 52x responses. Defaults to False.
keep_base_url: keep user-provided base URL for pagination if it
differs from response headers
tls_client_cert: provide client TLS certificate
tls_client_key: provide client TLS key

Keyword Args:
requests.Session session: HTTP Requests Session
Expand All @@ -98,6 +100,8 @@
user_agent: str = gitlab.const.USER_AGENT,
retry_transient_errors: bool = False,
keep_base_url: bool = False,
tls_client_cert: Optional[str] = None,
tls_client_key: Optional[str] = None,
**kwargs: Any,
) -> None:
self._api_version = str(api_version)
Expand All @@ -109,6 +113,7 @@
self.timeout = timeout
self.retry_transient_errors = retry_transient_errors
self.keep_base_url = keep_base_url

#: Headers that will be used in request to GitLab
self.headers = {"User-Agent": user_agent}

Expand All @@ -129,6 +134,13 @@
self._backend = _backend(**kwargs)
self.session = self._backend.client

if tls_client_cert and tls_client_key:
self.session.cert = (tls_client_cert, tls_client_key)

Check warning on line 138 in gitlab/client.py

View check run for this annotation

Codecov / codecov/patch

gitlab/client.py#L138

Added line #L138 was not covered by tests
elif tls_client_cert or tls_client_key:
raise ValueError(

Check warning on line 140 in gitlab/client.py

View check run for this annotation

Codecov / codecov/patch

gitlab/client.py#L140

Added line #L140 was not covered by tests
"tls_client_cert and tls_client_key must be provided together"
)

self.per_page = per_page
self.pagination = pagination
self.order_by = order_by
Expand Down Expand Up @@ -304,6 +316,8 @@
user_agent=config.user_agent,
retry_transient_errors=config.retry_transient_errors,
keep_base_url=config.keep_base_url,
tls_client_cert=config.tls_client_cert,
tls_client_key=config.tls_client_key,
**kwargs,
)

Expand Down Expand Up @@ -360,6 +374,9 @@
pagination=options.get("pagination") or config.pagination,
order_by=options.get("order_by") or config.order_by,
user_agent=options.get("user_agent") or config.user_agent,
keep_base_url=config.keep_base_url,
tls_client_cert=config.tls_client_cert,
tls_client_key=config.tls_client_key,
)

@staticmethod
Expand Down
20 changes: 20 additions & 0 deletions gitlab/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ def __init__(
self.url: Optional[str] = None
self.user_agent: str = USER_AGENT
self.keep_base_url: bool = False
self.tls_client_cert: Optional[str] = None
self.tls_client_key: Optional[str] = None

self._files = _get_config_files(config_files)
if self._files:
Expand Down Expand Up @@ -245,6 +247,24 @@ def _parse_config(self) -> None:
except _CONFIG_PARSER_ERRORS:
pass

try:
self.tls_client_cert = _config.get("global", "tls_client_cert")
except _CONFIG_PARSER_ERRORS:
pass
try:
self.tls_client_cert = _config.get(self.gitlab_id, "tls_client_cert")
except _CONFIG_PARSER_ERRORS:
pass

try:
self.tls_client_key = _config.get("global", "tls_client_key")
except _CONFIG_PARSER_ERRORS:
pass
try:
self.tls_client_key = _config.get(self.gitlab_id, "tls_client_key")
except _CONFIG_PARSER_ERRORS:
pass

try:
self.retry_transient_errors = _config.getboolean(
"global", "retry_transient_errors"
Expand Down
0