2024-06-17 23:45:40 -07:00
|
|
|
|
|
|
|
|
|
|
|
import gitea
|
|
|
|
|
|
|
|
|
|
|
|
class API:
|
|
|
|
|
|
|
|
__DEFAULT_API_PATH = "/api/v1"
|
|
|
|
|
2024-06-18 00:57:09 -07:00
|
|
|
def __init__(self, verify_ssl, ca_bundle):
|
2024-06-17 23:45:40 -07:00
|
|
|
|
2024-06-18 00:57:09 -07:00
|
|
|
self.__verify_ssl = verify_ssl
|
|
|
|
self.__ca_bundle = ca_bundle
|
2024-06-17 23:45:40 -07:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _make_api_base_url(hostname, port):
|
|
|
|
|
|
|
|
base = f"https://{hostname}"
|
|
|
|
if port is not None:
|
|
|
|
base += f":{port}"
|
|
|
|
|
|
|
|
return base
|
|
|
|
|
2024-06-18 00:57:09 -07:00
|
|
|
def get(self, hostname, port, token) -> gitea.Gitea:
|
2024-06-17 23:45:40 -07:00
|
|
|
|
|
|
|
url = API._make_api_base_url(
|
|
|
|
hostname=hostname,
|
|
|
|
port=port
|
|
|
|
)
|
|
|
|
|
2024-06-18 00:57:09 -07:00
|
|
|
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
|
|
|
|
|
2024-06-17 23:45:40 -07:00
|
|
|
g = gitea.Gitea(
|
|
|
|
gitea_url=url,
|
2024-06-18 00:57:09 -07:00
|
|
|
token_text=token,
|
|
|
|
verify=ssl_verify_arg
|
2024-06-17 23:45:40 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
return g
|