Skip to content

Commit 986a49f

Browse files
Refactor handling of proto parameter
1 parent b21ac81 commit 986a49f

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

netjsonconfig/backends/openwrt/converters/firewall.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,9 @@ def to_netjson_loop(self, block, result, index):
168168
def __netjson_rule(self, rule):
169169
if "enabled" in rule:
170170
rule["enabled"] = rule.pop("enabled") == "1"
171+
171172
if "proto" in rule:
172-
proto = rule.pop("proto")
173-
if not isinstance(proto, list):
174-
if proto == "tcpudp":
175-
rule["proto"] = ["tcp", "udp"]
176-
else:
177-
rule["proto"] = [proto]
173+
rule["proto"] = self.__netjson_generic_proto(rule["proto"])
178174

179175
return self.type_cast(rule)
180176

@@ -199,7 +195,7 @@ def __netjson_forwarding(self, forwarding):
199195

200196
def __netjson_redirect(self, redirect):
201197
if "proto" in redirect:
202-
redirect["proto"] = self.__netjson_redirect_proto(redirect["proto"])
198+
redirect["proto"] = self.__netjson_generic_proto(redirect["proto"])
203199

204200
if "weekdays" in redirect:
205201
redirect["weekdays"] = self.__netjson_redirect_weekdays(
@@ -225,7 +221,7 @@ def __netjson_redirect(self, redirect):
225221

226222
return self.type_cast(redirect)
227223

228-
def __netjson_redirect_proto(self, proto):
224+
def __netjson_generic_proto(self, proto):
229225
if isinstance(proto, list):
230226
return proto.copy()
231227
else:

0 commit comments

Comments
 (0)