diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index df587304..d15101c7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -55,7 +55,6 @@ repos: # Lint: Checks that non-binary executables have a proper shebang. - id: check-executables-have-shebangs - # pre-commit.ci config reference: https://pre-commit.ci/#configuration ci: autoupdate_schedule: monthly diff --git a/batchspawner/singleuser.py b/batchspawner/singleuser.py index d2bd338e..a56d67db 100644 --- a/batchspawner/singleuser.py +++ b/batchspawner/singleuser.py @@ -7,6 +7,8 @@ from jupyterhub.utils import random_port, url_path_join from jupyterhub.services.auth import HubAuth +import requests + def main(argv=None): port = random_port() @@ -14,10 +16,22 @@ def main(argv=None): hub_auth.client_ca = os.environ.get("JUPYTERHUB_SSL_CLIENT_CA", "") hub_auth.certfile = os.environ.get("JUPYTERHUB_SSL_CERTFILE", "") hub_auth.keyfile = os.environ.get("JUPYTERHUB_SSL_KEYFILE", "") - hub_auth._api_request( - method="POST", - url=url_path_join(hub_auth.api_url, "batchspawner"), + + url = url_path_join(hub_auth.api_url, "batchspawner") + headers = {"Authorization": f"token {hub_auth.api_token}"} + + # internal_ssl kwargs + kwargs = {} + if hub_auth.certfile and hub_auth.keyfile: + kwargs["cert"] = (hub_auth.certfile, hub_auth.keyfile) + if hub_auth.client_ca: + kwargs["verify"] = hub_auth.client_ca + + r = requests.post( + url, + headers={"Authorization": f"token {hub_auth.api_token}"}, json={"port": port}, + **kwargs, ) cmd_path = which(sys.argv[1])