44 lines
735 B
Python
44 lines
735 B
Python
|
|
|
|
import gitea
|
|
|
|
|
|
class API:
|
|
|
|
__DEFAULT_API_PATH = "/api/v1"
|
|
|
|
def __init__(self, verify_ssl, ca_bundle):
|
|
|
|
self.__verify_ssl = verify_ssl
|
|
self.__ca_bundle = ca_bundle
|
|
|
|
@staticmethod
|
|
def _make_api_base_url(hostname, port):
|
|
|
|
base = f"https://{hostname}"
|
|
if port is not None:
|
|
base += f":{port}"
|
|
|
|
return base
|
|
|
|
def get(self, hostname, port, token) -> gitea.Gitea:
|
|
|
|
url = API._make_api_base_url(
|
|
hostname=hostname,
|
|
port=port
|
|
)
|
|
|
|
ssl_verify_arg = True
|
|
if self.__verify_ssl is not None:
|
|
ssl_verify_arg = self.__verify_ssl
|
|
if self.__ca_bundle is not None:
|
|
ssl_verify_arg = self.__ca_bundle
|
|
|
|
g = gitea.Gitea(
|
|
gitea_url=url,
|
|
token_text=token,
|
|
verify=ssl_verify_arg
|
|
)
|
|
|
|
return g
|