Skip to content

Commit

Permalink
control: Replace host parameters in exported clients
Browse files Browse the repository at this point in the history
  • Loading branch information
shramov committed Dec 7, 2024
1 parent c91ef91 commit 0413aa5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions python/test/test_logic_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ async def test_resolve(asyncloop, path_srcdir):
channel:
url: control://;tll.channel.processor=processor;tll.channel.resolve=resolve;name=logic
service: test
hostname: host
hostname: ::1
service-tags: 'a,b'
''')

Expand All @@ -202,11 +202,11 @@ async def test_resolve(asyncloop, path_srcdir):

tproc, tinput = mock.io('processor', 'resolve')

tcp = asyncloop.Channel(f'child-export+tcp://::1:{ports.TCP6};mode=server;name=tcp;tll.resolve.export=yes')
tcp = asyncloop.Channel(f'child-export+tcp://*:{ports.TCP6};mode=server;name=tcp;tll.resolve.export=yes')
tcp.open()

m = await tinput.recv()
assert tinput.unpack(m).as_dict() == {'service': 'test', 'tags': ['a', 'b'], 'host': 'host'}
assert tinput.unpack(m).as_dict() == {'service': 'test', 'tags': ['a', 'b'], 'host': '::1'}

tproc.post({'channel': 'tcp', 'state': 'Active'}, name='StateUpdate')
for name in ('tcp', 'tcp/first', 'tcp/first/second'):
Expand Down
6 changes: 6 additions & 0 deletions src/logic/control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,16 @@ int Control::_post_export(ChannelExport &channel, std::string_view name, const t
data.set_service(_service);
data.set_channel(name);
std::map<std::string, tll::ConstConfig> curl;

for (auto & [name, cfg] : client.browse("**")) {
if (name.substr(0, strlen("children.")) != "children.")
curl.emplace(name, cfg);
}
tll::Config hostname;
hostname.set(_hostname);
for (auto & [k, _]: client.browse("replace.host.**"))
curl[std::string(k.substr(strlen("replace.host.")))] = hostname;

data.get_config().resize(curl.size());
auto di = data.get_config().begin();
for (auto & [name, cfg] : curl) {
Expand Down

0 comments on commit 0413aa5

Please sign in to comment.