Skip to content

Commit

Permalink
Merge pull request #145 from launchableinc/proxy-support
Browse files Browse the repository at this point in the history
Add proxy support in `record commit` command
  • Loading branch information
kohsuke authored Feb 17, 2021
2 parents 69e2253 + a16618d commit 355c746
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
24 changes: 21 additions & 3 deletions launchable/commands/record/commit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

import click
from urllib.parse import urlparse

from ...utils.env_keys import REPORT_ERROR_KEY
from ...utils.http_client import get_base_url
Expand Down Expand Up @@ -44,9 +44,27 @@ def exec_jar(source):
exit("You need to install Java or try --executable docker")

base_url = get_base_url()

https_proxy = os.environ("HTTPS_PROXY")
proxy_option = _build_proxy_option(https_proxy) if https_proxy else ""

os.system(
"{} -jar {} ingest:commit -endpoint {} {}"
.format(java, jar_file_path, "{}/intake/".format(base_url), source))
"{} {} -jar {} ingest:commit -endpoint {} {}"
.format(java, proxy_option, jar_file_path, "{}/intake/".format(base_url), source))


def _build_proxy_option(https_proxy: str) -> str:
if not https_proxy.startswith("https"):
https_proxy = "https://" + https_proxy
proxy_url = urlparse(https_proxy)

options = []
if proxy_url.hostname:
options.append("-Dhttps.proxyHost={}".format(proxy_url.hostname))
if proxy_url.port:
options.append("-Dhttps.proxyPort={}".format(proxy_url.port))

return "{} ".format(" ".join(options)) if len(options) else ""


def exec_docker(source):
Expand Down
Binary file modified launchable/jar/exe_deploy.jar
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/commands/record/test_commit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import unittest
from launchable.commands.record.commit import _build_proxy_option

class CommitTest(unittest.TestCase):
def test_proxy_options(self):
self.assertEqual(_build_proxy_option("https://some_proxy:1234"), "-Dhttps.proxyHost=some_proxy -Dhttps.proxyPort=1234 ")
self.assertEqual(_build_proxy_option("some_proxy:1234"), "-Dhttps.proxyHost=some_proxy -Dhttps.proxyPort=1234 ")
self.assertEqual(_build_proxy_option("some_proxy"), "-Dhttps.proxyHost=some_proxy ")
self.assertEqual(_build_proxy_option("https://some_proxy"), "-Dhttps.proxyHost=some_proxy ")

0 comments on commit 355c746

Please sign in to comment.