Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Updated requirements.txt and documentation #34

Merged
merged 5 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,24 @@ This collection contains modules and plugins to assist in automating the configu
This collection is tested with the most current Ansible releases. Ansible versions
before 2.15 are **not supported**.

## Python Version
## Python dependencies

The minimum python version for this collection is python `3.9`.

The Python module dependencies are not automatically handled by `ansible-galaxy`. To manually install these dependencies, you have the following options:

1. Utilize the `requirements.txt` file located [here](https://github.com/zscaler/ziacloud-ansible/blob/master/requirements.txt) to install all required packages:

```bash
pip install -r requirements.txt
```

2. Alternatively, install the [Zscaler SDK Python](https://pypi.org/project/zscaler-sdk-python/) package directly:

```bash
pip install zscaler-sdk-python
```

## Installation

Install this collection using the Ansible Galaxy CLI:
Expand Down
21 changes: 19 additions & 2 deletions docs/source/requirements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,26 @@
Requirements
==========================

The **Zscaler Internet Access Collection** has the following requirements in order to be successfully used:
The **Zscaler Internet Access Collection** has the following requirements in order to be successfully used.

* **zscaler-sdk-python**
Python dependencies
----------------------

The minimum python version for this collection is python `3.9`.

The Python module dependencies are not automatically handled by `ansible-galaxy`. To manually install these dependencies, you have the following options:

1. Utilize the `requirements.txt` file located `here <https://github.com/zscaler/ziacloud-ansible/blob/master/requirements.txt>`_ to install all required packages:

```bash
pip install -r requirements.txt
```

2. Alternatively, install the `Zscaler SDK Python <https://pypi.org/project/zscaler-sdk-python/>`_ package directly:

```bash
pip install zscaler-sdk-python
```

If you believe you have installed these dependencies but Ansible is not finding them, it is likely a
problem with where your local shell is searching for installed dependencies and where Ansible is
Expand Down
28 changes: 27 additions & 1 deletion plugins/modules/zia_cloud_firewall_filtering_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def normalize_rule(rule):
normalized = rule.copy()

computed_values = [
"exclude_src_countries",
# "exclude_src_countries",
]
for attr in computed_values:
normalized.pop(attr, None)
Expand Down Expand Up @@ -430,6 +430,17 @@ def core(module):
if rule_.get("name") == rule_name:
existing_rule = rule_

# Check for predefined or default rules before deletion
if state == "absent" and existing_rule is not None:
if existing_rule.get("default_rule", False) or existing_rule.get(
"predefined", False
):
module.warn("Default and predefined rules cannot be deleted.")
module.exit_json(
changed=False,
msg="Deletion of default or predefined rule is not allowed.",
)

# Normalize and compare existing and desired data
desired_rule = normalize_rule(rule)
current_rule = normalize_rule(existing_rule) if existing_rule else {}
Expand Down Expand Up @@ -477,6 +488,12 @@ def preprocess_rules(rule, params):
if key == "enabled" and "state" in current_rule:
current_value = current_rule["state"] == "ENABLED"

# Special handling for exclude_src_countries
if key == "exclude_src_countries":
# Ignore comparison if exclude_src_countries is not specified in the playbook
if module.params.get("exclude_src_countries") is None:
continue

# Handling None values for all attributes
if desired_value is None and key != "enabled":
# Explicitly setting to empty list or empty value based on type
Expand Down Expand Up @@ -599,6 +616,15 @@ def preprocess_rules(rule, params):
and existing_rule is not None
and existing_rule.get("id") is not None
):
# Check for predefined or default rules before deletion
if existing_rule.get("default_rule", False) or existing_rule.get(
"predefined", False
):
module.warn("Default and predefined rules cannot be deleted.")
module.exit_json(
changed=False,
msg="Deletion of default or predefined rule is not allowed.",
)
code = client.firewall.delete_rule(rule_id=existing_rule.get("id"))
if code > 299:
module.exit_json(changed=False, data=None)
Expand Down
13 changes: 8 additions & 5 deletions plugins/modules/zia_url_filtering_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
type: bool
order:
description: "Rule order number of the URL Filtering policy rule"
required: true
required: false
type: int
action:
description:
Expand Down Expand Up @@ -168,7 +168,7 @@
- If not set, rule will be applied to all methods"
type: list
elements: str
required: true
required: false
choices:
- OPTIONS
- GET
Expand Down Expand Up @@ -439,12 +439,15 @@ def normalize_rule(rule):
"""
Normalize rule data by setting computed values.
"""
if not rule:
return {}

normalized = rule.copy()

# Add 'profile_seq' to the list of computed values to be removed
computed_values = ["profile_seq"]
for attr in computed_values:
if "cbi_profile" in normalized and attr in normalized["cbi_profile"]:
if "cbi_profile" in normalized and isinstance(normalized["cbi_profile"], dict) and attr in normalized["cbi_profile"]:
normalized["cbi_profile"].pop(attr, None)

return normalized
Expand Down Expand Up @@ -718,7 +721,7 @@ def main():
name=dict(type="str", required=True),
description=dict(type="str", required=False),
enabled=dict(type="bool", required=False),
order=dict(type="int", required=True),
order=dict(type="int", required=False),
rank=dict(type="int", required=False, default=7),
locations=id_spec,
groups=id_spec,
Expand Down Expand Up @@ -777,7 +780,7 @@ def main():
request_methods=dict(
type="list",
elements="str",
required=True,
required=False,
choices=[
"OPTIONS",
"GET",
Expand Down
Loading