Skip to content

Commit

Permalink
feat(new): Added Forwarding Control Rule Resource (#37)
Browse files Browse the repository at this point in the history
* feat(new): Added Forwarding Control Rule Resource

* fix: Upgraded to Zscaler SDK Python v.0.5.2
  • Loading branch information
willguibr authored Jun 25, 2024
1 parent 3f6779c commit a0abe94
Show file tree
Hide file tree
Showing 22 changed files with 2,025 additions and 494 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ jobs:
id: release
uses: cycjimmy/semantic-release-action@v4
with:
semantic_version: 17.1.1
semantic_version: 23.1.1
extra_plugins: |
conventional-changelog-conventionalcommits@^4.4.0
@semantic-release/changelog@^5.0.1
@semantic-release/git@^9.0.0
@semantic-release/exec@^5.0.0
@semantic-release/git@^10.0.0
@semantic-release/exec@^6.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/zia-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ jobs:
matrix:
python-version: ["3.10"]
environment:
- ZIA_ZSCLOUD
# - ZIA_ZSCLOUD
- ZIA_ZS0
# - ZIA_ZS1
- ZIA_ZS1
- ZIA_ZS2
# - ZIA_ZS3
- ZIA_ZS3
environment: ${{ matrix.environment }}
steps:
- name: Checkout code
Expand Down
21 changes: 6 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@
[![License](https://img.shields.io/github/license/zscaler/ziacloud-ansible?color=blue)](https://github.com/zscaler/ziacloud-ansible/v2/blob/master/LICENSE)
[![Zscaler Community](https://img.shields.io/badge/zscaler-community-blue)](https://community.zscaler.com/)

<div style="display: flex; align-items: center;">
<a href="https://catalog.redhat.com/software/search?p=1&type=Ansible%20collection&partnerName=Zscaler">
<img src="https://catalog.redhat.com/img/svg/logo.svg" alt="RedHat logo" title="RedHat Ecosystem Catalog" height="20" style="margin-left: 20px;"/>
</a>
<a href="https://www.zscaler.com/">
<img src="https://www.zscaler.com/themes/custom/zscaler/logo.svg" alt="Zscaler logo" title="Zscaler" height="25" style="margin-left: 25px;" />
</a>
</div>

## Zscaler Support

-> **Disclaimer:** Please refer to our [General Support Statement](https://zscaler.github.io/ziacloud-ansible/support.html) before proceeding with the use of this collection. You can also refer to our [troubleshooting guide](https://zscaler.github.io/ziacloud-ansible/troubleshooting.html) for guidance on typical problems.
Expand All @@ -29,7 +20,7 @@ This collection contains modules and plugins to assist in automating the configu

## Tested Ansible Versions

This collection is tested with the most current Ansible releases. Ansible versions
This collection is tested with the most current Ansible releases. Ansible versions
before 2.15 are **not supported**.

## Python dependencies
Expand All @@ -40,21 +31,21 @@ The Python module dependencies are not automatically handled by `ansible-galaxy`

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

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

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

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

## Installation

Install this collection using the Ansible Galaxy CLI:

```bash
```sh
ansible-galaxy collection install zscaler.ziacloud
```

Expand Down
6 changes: 3 additions & 3 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ Then in your playbooks you can specify that you want to use the
collections:
- zscaler.ziacloud
* Ansible Galaxy: https://galaxy.ansible.com/ui/repo/published/zscaler/ziacloud/
* Red Hat Catalog: https://catalog.redhat.com/software/collection/zscaler/ziacloud
* GitHub repo: https://github.com/zscaler/ziacloud-ansible
* `Ansible Galaxy <https://galaxy.ansible.com/ui/repo/published/zscaler/ziacloud/>`_
* `Red Hat Catalog <https://catalog.redhat.com/software/collection/zscaler/ziacloud>`_
* `GitHub repo <https://github.com/zscaler/ziacloud-ansible>`_
77 changes: 44 additions & 33 deletions plugins/modules/zia_cloud_firewall_network_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,28 +228,23 @@

from ansible.module_utils._text import to_native
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.zscaler.ziacloud.plugins.module_utils.utils import (
deleteNone,
)
from ansible_collections.zscaler.ziacloud.plugins.module_utils.zia_client import (
ZIAClientHelper,
)


def normalize_service(service):
"""
Normalize ip source group data by setting computed values.
Normalize network service data by setting computed values.
"""
normalized = service.copy()

computed_values = [
"id",
"name",
"description",
"tag",
"type",
"src_tcp_ports",
"dest_tcp_ports",
"src_udp_ports",
"dest_udp_ports",
"is_name_l10n_tag",
"creatorContext",
"isNameL10nTag",
]
for attr in computed_values:
normalized.pop(attr, None)
Expand Down Expand Up @@ -312,35 +307,51 @@ def core(module):
existing_network_service.update(normalized_service)
existing_network_service["id"] = id

module.warn(f"Final payload being sent to SDK: {normalized_service}")
if state == "present":
if existing_network_service is not None:
if differences_detected:
"""Update"""
existing_network_service = client.firewall.update_network_service(
service_id=existing_network_service.get("id", ""),
name=existing_network_service.get("name", ""),
description=existing_network_service.get("description", ""),
type=existing_network_service.get("type", ""),
tag=existing_network_service.get("tag", ""),
src_tcp_ports=existing_network_service.get("src_tcp_ports", ""),
dest_tcp_ports=existing_network_service.get("dest_tcp_ports", ""),
src_udp_ports=existing_network_service.get("src_udp_ports", ""),
dest_udp_ports=existing_network_service.get("dest_udp_ports", ""),
).to_dict()
module.exit_json(changed=True, data=existing_network_service)
update_service = deleteNone(
dict(
service_id=existing_network_service.get("id"),
name=existing_network_service.get("name"),
description=existing_network_service.get("description"),
type=existing_network_service.get("type"),
tag=existing_network_service.get("tag"),
src_tcp_ports=existing_network_service.get("src_tcp_ports"),
dest_tcp_ports=existing_network_service.get("dest_tcp_ports"),
src_udp_ports=existing_network_service.get("src_udp_ports"),
dest_udp_ports=existing_network_service.get("dest_udp_ports"),
)
)
module.warn("Payload Update for SDK: {}".format(update_service))
update_service = client.firewall.update_network_service(
**update_service
).to_dict()
module.exit_json(changed=True, data=update_service)
else:
module.exit_json(changed=False, data=existing_network_service)
else:
module.warn("Creating new service as no existing service found")
"""Create"""
network_service = client.firewall.add_network_service(
name=network_service.get("name", ""),
tag=network_service.get("tag", ""),
type=network_service.get("type", ""),
src_tcp_ports=network_service.get("src_tcp_ports", ""),
dest_tcp_ports=network_service.get("dest_tcp_ports", ""),
src_udp_ports=network_service.get("src_udp_ports", ""),
dest_udp_ports=network_service.get("dest_udp_ports", ""),
description=network_service.get("description", ""),
create_service = deleteNone(
dict(
name=network_service.get("name"),
tag=network_service.get("tag"),
type=network_service.get("type"),
src_tcp_ports=network_service.get("src_tcp_ports"),
dest_tcp_ports=network_service.get("dest_tcp_ports"),
src_udp_ports=network_service.get("src_udp_ports"),
dest_udp_ports=network_service.get("dest_udp_ports"),
description=network_service.get("description"),
)
)
module.warn("Payload for SDK: {}".format(create_service))
create_service = client.firewall.add_network_service(
**create_service
).to_dict()
module.exit_json(changed=False, data=network_service)
module.exit_json(changed=True, data=create_service)
elif state == "absent":
if existing_network_service is not None:
service_type = existing_network_service.get("type")
Expand Down
Loading

0 comments on commit a0abe94

Please sign in to comment.