Skip to content

Commit

Permalink
Use f raw string
Browse files Browse the repository at this point in the history
  • Loading branch information
cbartz committed Nov 16, 2023
1 parent fe35943 commit b8c35c0
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,22 +445,21 @@ def _configure_aproxy(self, aproxy_proxy: str) -> None:
)
default_ip = stdout.strip()

nft_input = f"define default-ip = {default_ip}"
nft_input += r"""
define private-ips = { 10.0.0.0/8, 127.0.0.1/8, 172.16.0.0/12, 192.168.0.0/16 }
nft_input = rf"""define default-ip = {default_ip}
define private-ips = {{ 10.0.0.0/8, 127.0.0.1/8, 172.16.0.0/12, 192.168.0.0/16 }}
table ip aproxy
flush table ip aproxy
table ip aproxy {
chain prerouting {
table ip aproxy {{
chain prerouting {{
type nat hook prerouting priority dstnat; policy accept;
ip daddr != $private-ips tcp dport { 80, 443 } counter dnat to $default-ip:8443
}
ip daddr != $private-ips tcp dport {{ 80, 443 }} counter dnat to $default-ip:8443
}}
chain output {
chain output {{
type nat hook output priority -100; policy accept;
ip daddr != $private-ips tcp dport { 80, 443 } counter dnat to $default-ip:8443
}
}
ip daddr != $private-ips tcp dport {{ 80, 443 }} counter dnat to $default-ip:8443
}}
}}
"""
execute_command(["nft", "-f", "-"], input=nft_input.encode("utf-8"))

Expand Down

0 comments on commit b8c35c0

Please sign in to comment.