Skip to content

Commit

Permalink
[confgen] add a hacky approach to overwrite child config dns setups
Browse files Browse the repository at this point in the history
  • Loading branch information
lirundong committed Feb 6, 2024
1 parent dcaeec5 commit 7b73d6c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions conf-gen/generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def generate_conf(
if gen_info.get("base"):
gen = SingBoxGenerator.from_base(
base_object=generators[gen_info["base"]],
dns=gen_info["dns"],
inbounds=gen_info["inbounds"],
route=gen_info["route"],
experimental=gen_info["experimental"],
Expand Down
10 changes: 9 additions & 1 deletion conf-gen/generator/sing_box_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,16 @@ def _build_route(self):

# TODO: Make this method more general and robust.
@classmethod
def from_base(cls, base_object: Self, inbounds, route, experimental):
def from_base(cls, base_object: Self, dns, inbounds, route, experimental):
new_object = copy(base_object)
# TODO: Define a former behavior of replacements and overwrites.
# `dns` only overwrites or appends DNS servers.
if dns.get("servers"):
old_servers = {s["tag"]: s for s in base_object.dns["servers"]}
for new_server in dns["servers"]:
tag = new_server["tag"]
old_servers.setdefault(tag, {}).clear()
old_servers[tag].update(new_server)
new_object.inbounds = inbounds
new_object.route.update(route)
if experimental is None:
Expand Down
5 changes: 5 additions & 0 deletions conf-gen/source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,11 @@ generates:
- name: sing-box-clients
type: sing-box
base: *SING_BOX_CONF_BASE
dns:
servers:
- address: tls://1.12.12.12
detour: DIRECT
tag: DIRECT
inbounds:
- tag: tun
type: tun
Expand Down

0 comments on commit 7b73d6c

Please sign in to comment.