Skip to content

Commit

Permalink
feat(panos_security_rule): Add audit comment (#229)
Browse files Browse the repository at this point in the history
Fixes #228.
  • Loading branch information
ntwrkguru authored Jun 14, 2021
1 parent b4a0b1a commit bae2483
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ ENV/
# PyCharm / IntelliJ
.idea

# VS Code
.vscode

# Configtree diagram generated by sphinx
docs/_diagrams

Expand Down
12 changes: 11 additions & 1 deletion plugins/modules/panos_security_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@
description:
- Exclude this rule from the listed firewalls in Panorama.
type: bool
audit_comment:
description:
- Add an audit comment to the rule being defined.
type: str
"""

EXAMPLES = """
Expand Down Expand Up @@ -338,7 +342,7 @@

try:
from panos.errors import PanDeviceError
from panos.policies import SecurityRule
from panos.policies import RuleAuditComment, SecurityRule
except ImportError:
try:
from pandevice.errors import PanDeviceError
Expand Down Expand Up @@ -410,6 +414,7 @@ def main():
location=dict(choices=["top", "bottom", "before", "after"]),
existing_rule=dict(),
commit=dict(type="bool", default=False),
audit_comment=dict(type="str"),
# TODO(gfreeman) - remove this in the next role release.
devicegroup=dict(),
),
Expand Down Expand Up @@ -481,6 +486,7 @@ def main():
location = module.params["location"]
existing_rule = module.params["existing_rule"]
commit = module.params["commit"]
audit_comment = module.params["audit_comment"]

# Retrieve the current rules.
try:
Expand All @@ -499,6 +505,10 @@ def main():
if module.params["state"] == "present":
changed |= helper.apply_position(new_rule, location, existing_rule, module)

# Add the audit comment, if applicable.
if changed and audit_comment and not module.check_mode:
new_rule.opstate.audit_comment.update(audit_comment)

# Optional commit.
if changed and commit:
helper.commit(module)
Expand Down

0 comments on commit bae2483

Please sign in to comment.