diff --git a/Dockerfile b/Dockerfile index a3d2f7f..f3ed878 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,10 @@ FROM python:3.11 -RUN useradd --create-home --home /code pyapp -USER pyapp -WORKDIR /code +COPY pyproject.toml requirements.txt README.md LICENSE ./ +COPY ./src /src -ENV VIRTUAL_ENV=/code/venv -RUN python -m venv $VIRTUAL_ENV -ENV PATH="$VIRTUAL_ENV/bin:$PATH" +RUN pip install --no-cache-dir --editable .[test] -COPY --chown=app pyproject.toml requirements.txt ./ -RUN mkdir src -RUN pip install --editable .[test] +WORKDIR /src/ -COPY --chown=pyapp . . +ENV PYTHONPATH=/src diff --git a/src/examples/unittests.pac b/src/examples/unittests.pac index 3ec6dce..f8f65ff 100644 --- a/src/examples/unittests.pac +++ b/src/examples/unittests.pac @@ -1,35 +1,60 @@ function FindProxyForURL(url, host) { + /* + Description: For the unittests, hopefully no real script should look like this. ;) + Version: 1.0 + */ host = host.toLowerCase(); if ( localHostOrDomainIs(host, "example.com") || localHostOrDomainIs(host, "foo.example.com") || localHostOrDomainIs(host, "foo.example.net") - ) { return "PROXY domain-overlaps.example.com"; } + ) { + /* here domains overlap with the default route */ + return "PROXY domain-overlaps.example.com"; + } if ( localHostOrDomainIs(host, "example.net") || localHostOrDomainIs(host, "bar.example.com") || localHostOrDomainIs(host, "bar.example.net") - ) { return "PROXY mixed.example.com"; } + ) { + /* a proxy for mixed matches, this should be split up */ + return "PROXY mixed.example.com"; + } if ( dnsDomainIs(host, ".example.com") - ) { return "DIRECT"; } + ) { + /* take the direct route */ + return "DIRECT"; + } if ( host.substring(0, 3) === "10." || host.substring(host.length - 8) === ".102.123" || host === "10" - ) { return "PROXY string.example.com"; } + ) { + /* a proxy for string matches */ + return "PROXY string.example.com"; + } if ( dnsResolve(host) === "192.0.0.170" || dnsResolve(host) === "192.0.0.171" || dnsResolve(host) === "127.0.0.1" - ) { return "PROXY ip.example.com"; } + ) { + /* a proxy for IPs */ + return "PROXY ip.example.com"; + } if ( isInNet(host, "20.10.10.0", "255.255.255.0") || dnsResolve(host) === "130.131.132.133" - ) { return "PROXY mixed.example.com"; } + ) { + /* a proxy for mixed matches, this should be split up */ + return "PROXY mixed.example.com"; + } if ( isInNet(host, "93.184.0.0", "255.255.0.0") || isInNet(host, "2001:db8:85a3:8d3::", "ffff:ffff:ffff:ffff::") - ) { return "PROXY netmask.example.com"; } + ) { + /* a proxy for netmask */ + return "PROXY netmask.example.com"; + } return "PROXY default.example.com"; } \ No newline at end of file diff --git a/src/pypacer/pypacer.py b/src/pypacer/pypacer.py index 4ee4d1c..4e4b113 100644 --- a/src/pypacer/pypacer.py +++ b/src/pypacer/pypacer.py @@ -27,6 +27,8 @@ def _get_javascript(self) -> str: return template.render( default=self._get_default_proxy_route(), proxies=proxies, + description=self.config.description, + version=self.config.version ) def output(self) -> str: diff --git a/src/pypacer/template.js.jinja b/src/pypacer/template.js.jinja index 070335e..8b7fdde 100644 --- a/src/pypacer/template.js.jinja +++ b/src/pypacer/template.js.jinja @@ -1,4 +1,8 @@ function FindProxyForURL(url, host) { + /* + Description: {{ description }} + Version: {{ version }} + */ host = host.toLowerCase(); {%- for proxy in proxies %} if ( @@ -13,7 +17,10 @@ function FindProxyForURL(url, host) { {%- else -%}host === "{{ target.target }}" {%- endif -%} {%- endfor %} - ) { return "{{ proxy.route }}"; } + ) { + /* {{ proxy.description }} */ + return "{{ proxy.route }}"; + } {%- endfor %} return "{{ default }}"; }