feat: Add an option to disable SSL certificate check

In case of particular self-signed SSL certificate, the requests
verification can fail.
To avoid that, an option was added to use the requests verify option.
pull/13/head
Etienne Monier 2022-03-08 11:27:06 +01:00
rodzic 69e786cdb2
commit d0bc054b30
1 zmienionych plików z 10 dodań i 2 usunięć

Wyświetl plik

@ -1,9 +1,10 @@
import json
import logging import logging
import json
from typing import List, Dict, Union from typing import List, Dict, Union
import requests
from frozendict import frozendict from frozendict import frozendict
import requests
import urllib3
from .apiobject import User, Organization, Repository, Team from .apiobject import User, Organization, Repository, Team
from .exceptions import NotFoundException, ConflictException, AlreadyExistsException from .exceptions import NotFoundException, ConflictException, AlreadyExistsException
@ -24,6 +25,7 @@ class Gitea:
gitea_url: str, gitea_url: str,
token_text=None, token_text=None,
auth=None, auth=None,
verify=True,
log_level="INFO" log_level="INFO"
): ):
""" Initializing Gitea-instance.""" """ Initializing Gitea-instance."""
@ -43,6 +45,12 @@ class Gitea:
if auth: if auth:
self.requests.auth = tuple(auth.split(":")) self.requests.auth = tuple(auth.split(":"))
# Manage SSL certification verification
self.requests.verify = verify
if not verify:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def __get_url(self, endpoint): def __get_url(self, endpoint):
url = self.url + "/api/v1" + endpoint url = self.url + "/api/v1" + endpoint
self.logger.debug("Url: %s" % url) self.logger.debug("Url: %s" % url)