Skip to content

Commit

Permalink
add descriptions and version to pac-file and rollback changes in dock…
Browse files Browse the repository at this point in the history
…erfile
  • Loading branch information
heikoschmidt committed Mar 11, 2024
1 parent 3e01b9b commit 158e1f0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
15 changes: 5 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
39 changes: 32 additions & 7 deletions src/examples/unittests.pac
Original file line number Diff line number Diff line change
@@ -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";
}
2 changes: 2 additions & 0 deletions src/pypacer/pypacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion src/pypacer/template.js.jinja
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
function FindProxyForURL(url, host) {
/*
Description: {{ description }}
Version: {{ version }}
*/
host = host.toLowerCase();
{%- for proxy in proxies %}
if (
Expand All @@ -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 }}";
}

0 comments on commit 158e1f0

Please sign in to comment.