Skip to content

Commit

Permalink
#99 spec generation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gevorg-Khachatryaan authored and Gevorg-Khachatryaan committed Feb 16, 2022
1 parent 3baba47 commit d755447
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions plugins/module_utils/prism/pbrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def _build_spec_protocol(self, payload, config):
protocol_type = None
protocol_parameters = {}
if config.get("tcp"):
tcp = {}
protocol_type = "TCP"
src_port_range_list = []
if "*" not in config["tcp"]["src"]:
Expand All @@ -97,11 +98,14 @@ def _build_spec_protocol(self, payload, config):
port = port.split("-")
dest_port_range_list.append({"start_port": int(port[0]), "end_port": int(port[-1])})
if src_port_range_list:
protocol_parameters["tcp"]["source_port_range_list"] = src_port_range_list
tcp["source_port_range_list"] = src_port_range_list
if dest_port_range_list:
protocol_parameters["tcp"]["destination_port_range_list"] = dest_port_range_list
tcp["destination_port_range_list"] = dest_port_range_list
if tcp:
protocol_parameters["tcp"] = tcp

elif config.get("udp"):
udp = {}
protocol_type = "UDP"
src_port_range_list = []
if "*" not in config["udp"]["src"]:
Expand All @@ -114,22 +118,24 @@ def _build_spec_protocol(self, payload, config):
port = port.split("-")
dest_port_range_list.append({"start_port": int(port[0]), "end_port": int(port[-1])})
if src_port_range_list:
protocol_parameters["udp"]["source_port_range_list"] = src_port_range_list
udp["source_port_range_list"] = src_port_range_list
if dest_port_range_list:
protocol_parameters["udp"]["destination_port_range_list"] = dest_port_range_list
udp["destination_port_range_list"] = dest_port_range_list
if udp:
protocol_parameters["udp"] = udp

elif config.get("icmp"):
protocol_type = "ICMP"
if config["icmp"].get("code"):
protocol_parameters["icmp"]["icmp_code"] = config["icmp"]["code"]
protocol_parameters["icmp"] = {"icmp_code": config["icmp"]["code"]}
if config["icmp"].get("type"):
protocol_parameters["icmp"]["icmp_type"] = config["icmp"]["type"]

elif config.get("number"):
protocol_type = "PROTOCOL_NUMBER"
protocol_parameters["protocol_number"] = config["number"]

elif config.get("any"):
else:
protocol_type = "ALL"

payload["spec"]["resources"]["protocol_type"] = protocol_type
Expand Down

0 comments on commit d755447

Please sign in to comment.