Skip to content

Commit

Permalink
feat(panos_application_filter): Add network resource module state sup…
Browse files Browse the repository at this point in the history
…port; corrected type of `category`, `subcategory`, `technology` and `risk` to `list`
  • Loading branch information
shinmog committed Jul 26, 2022
1 parent e82093d commit 16e9431
Showing 1 changed file with 21 additions and 47 deletions.
68 changes: 21 additions & 47 deletions plugins/modules/panos_application_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
- paloaltonetworks.panos.fragments.transitional_provider
- paloaltonetworks.panos.fragments.vsys
- paloaltonetworks.panos.fragments.device_group
- paloaltonetworks.panos.fragments.state
- paloaltonetworks.panos.fragments.network_resource_module_state
options:
name:
description:
Expand All @@ -53,19 +53,23 @@
category:
description:
- Application category
type: str
type: list
elements: str
subcategory:
description:
- Application subcategory
type: str
type: list
elements: str
technology:
description:
- Application technology
type: str
type: list
elements: str
risk:
description:
- Risk (1-5) of the application
type: str
type: list
elements: str
choices: ['1', '2', '3', '4', '5']
evasive:
description:
Expand Down Expand Up @@ -115,10 +119,10 @@
panos_application_filter:
provider: '{{ provider }}'
name: 'custom-apps'
category: 'business-systems'
subcategory: 'auth-service'
technology: 'client-server'
risk: '1'
category: ['business-systems']
subcategory: ['auth-service']
technology: ['client-server']
risk: ['1']
- name: Remove custom application
panos_application_filter:
Expand All @@ -137,11 +141,9 @@
)

try:
from panos.errors import PanDeviceError
from panos.objects import ApplicationFilter
except ImportError:
try:
from pandevice.errors import PanDeviceError
from pandevice.objects import ApplicationFilter
except ImportError:
pass
Expand All @@ -152,13 +154,14 @@ def main():
vsys=True,
device_group=True,
with_classic_provider_spec=True,
with_state=True,
argument_spec=dict(
with_network_resource_module_state=True,
sdk_cls=ApplicationFilter,
sdk_params=dict(
name=dict(type="str", required=True),
category=dict(type="str"),
subcategory=dict(type="str"),
technology=dict(type="str"),
risk=dict(choices=["1", "2", "3", "4", "5"]),
category=dict(type="list", elements="str"),
subcategory=dict(type="list", elements="str"),
technology=dict(type="list", elements="str"),
risk=dict(type="list", elements="str", choices=["1", "2", "3", "4", "5"]),
evasive=dict(type="bool"),
excessive_bandwidth_use=dict(type="bool"),
prone_to_misuse=dict(type="bool"),
Expand All @@ -178,36 +181,7 @@ def main():
supports_check_mode=True,
)

parent = helper.get_pandevice_parent(module)

spec = {
"name": module.params["name"],
"category": module.params["category"],
"subcategory": module.params["subcategory"],
"technology": module.params["technology"],
"risk": module.params["risk"],
"evasive": module.params["evasive"],
"excessive_bandwidth_use": module.params["excessive_bandwidth_use"],
"prone_to_misuse": module.params["prone_to_misuse"],
"is_saas": module.params["is_saas"],
"transfers_files": module.params["transfers_files"],
"tunnels_other_apps": module.params["tunnels_other_apps"],
"used_by_malware": module.params["used_by_malware"],
"has_known_vulnerabilities": module.params["has_known_vulnerabilities"],
"pervasive": module.params["pervasive"],
"tag": module.params["tag"],
}

try:
listing = ApplicationFilter.refreshall(parent, add=False)
except PanDeviceError as e:
module.fail_json(msg="Failed refresh: {0}".format(e))

obj = ApplicationFilter(**spec)
parent.add(obj)

changed, diff = helper.apply_state(obj, listing, module)
module.exit_json(changed=changed, diff=diff)
helper.process(module)


if __name__ == "__main__":
Expand Down

0 comments on commit 16e9431

Please sign in to comment.