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

Segregate filter plugins #578

Merged
merged 38 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4015773
vlan expander saved
KB-perByte Aug 4, 2023
b1b06a0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 4, 2023
cf19cd0
add a trivial changelog
KB-perByte Aug 4, 2023
72fcf27
add a test considering it breaks others
KB-perByte Aug 4, 2023
33e6562
some more test fixes
KB-perByte Aug 4, 2023
f9abf6d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 4, 2023
0f4e1ca
vlan_parser fix
KB-perByte Aug 4, 2023
37024d2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 4, 2023
b38af8c
add parse_xml
KB-perByte Aug 8, 2023
25b20d6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2023
80a2662
Merge branch 'main' into vlan_expander
KB-perByte Aug 8, 2023
bfd6442
add type5_pw
KB-perByte Aug 8, 2023
4c837ca
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2023
f4be1d2
thy formalities
KB-perByte Aug 8, 2023
6d7ce91
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2023
be69a3e
add parse_cli_textfsm
KB-perByte Aug 8, 2023
515d687
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2023
f37409e
update parse_xml
KB-perByte Aug 9, 2023
b546f32
fix parse_xml
KB-perByte Aug 9, 2023
84f4b98
add parse_cli
KB-perByte Aug 9, 2023
b2c33b2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 9, 2023
7ebf840
fix doc and sanity
KB-perByte Aug 9, 2023
198aa4f
add hash_salt
KB-perByte Aug 9, 2023
d7e00e6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 9, 2023
3f47b4e
add test hash_salt
KB-perByte Aug 9, 2023
4a44981
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 9, 2023
2cb0638
add comp_type5
KB-perByte Aug 9, 2023
81d4b15
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 9, 2023
81151e4
fix Unit test
KB-perByte Aug 9, 2023
5cb3a7b
fix sanity
KB-perByte Aug 9, 2023
dcbca0b
update test to assert on skip
KB-perByte Aug 9, 2023
29d4d02
workflow fix
KB-perByte Aug 10, 2023
4f85f3d
add original authors
KB-perByte Aug 10, 2023
32d6784
update all docs
KB-perByte Aug 10, 2023
fd11a76
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 10, 2023
d5d40fd
Fix Filter errors
KB-perByte Aug 10, 2023
7dd52dc
generate docs
KB-perByte Aug 10, 2023
bcb2b74
update security issues
KB-perByte Aug 22, 2023
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
5 changes: 3 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- run: >-
python -c "assert set([
python -c "assert 'failure' not in
set([
'${{ needs.ansible-lint.result }}',
'${{ needs.changelog.result }}',
'${{ needs.sanity.result }}',
'${{ needs.unit-galaxy.result }}',
'${{ needs.unit-source.result }}'
]) == {'success'}"
])
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,6 @@ venv.bak/

# mypy
.mypy_cache/

# vs code configuration
.vscode/
22 changes: 8 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,15 @@ Name | Description
### Filter plugins
Name | Description
--- | ---
[ansible.netcommon.comp_type5](https://github.com/ansible-collections/ansible.netcommon/blob/main/docs/ansible.netcommon.comp_type5_filter.rst)|comp_type5 filter plugin.
[ansible.netcommon.hash_salt](https://github.com/ansible-collections/ansible.netcommon/blob/main/docs/ansible.netcommon.hash_salt_filter.rst)|hash_salt filter plugin.
[ansible.netcommon.parse_cli](https://github.com/ansible-collections/ansible.netcommon/blob/main/docs/ansible.netcommon.parse_cli_filter.rst)|parse_cli filter plugin.
[ansible.netcommon.parse_cli_textfsm](https://github.com/ansible-collections/ansible.netcommon/blob/main/docs/ansible.netcommon.parse_cli_textfsm_filter.rst)|parse_cli_textfsm filter plugin.
[ansible.netcommon.parse_xml](https://github.com/ansible-collections/ansible.netcommon/blob/main/docs/ansible.netcommon.parse_xml_filter.rst)|parse_xml filter plugin.
[ansible.netcommon.pop_ace](https://github.com/ansible-collections/ansible.netcommon/blob/main/docs/ansible.netcommon.pop_ace_filter.rst)|Remove ace entries from a acl source of truth.

### Network filter plugins
Filters for working with output from network devices

Name | Description
--- | ---
ansible.netcommon.comp_type5|ansible.netcommon comp_type5 filter plugin
ansible.netcommon.hash_salt|ansible.netcommon hash_salt filter plugin
ansible.netcommon.parse_cli|ansible.netcommon parse_cli filter plugin
ansible.netcommon.parse_cli_textfsm|ansible.netcommon parse_cli_textfsm filter plugin
ansible.netcommon.parse_xml|ansible.netcommon parse_xml filter plugin
ansible.netcommon.type5_pw|ansible.netcommon type5_pw filter plugin
ansible.netcommon.vlan_expander|ansible.netcommon vlan_expander filter plugin
ansible.netcommon.vlan_parser|Input: Unsorted list of vlan integers
[ansible.netcommon.type5_pw](https://github.com/ansible-collections/ansible.netcommon/blob/main/docs/ansible.netcommon.type5_pw_filter.rst)|type5_pw filter plugin.
[ansible.netcommon.vlan_expander](https://github.com/ansible-collections/ansible.netcommon/blob/main/docs/ansible.netcommon.vlan_expander_filter.rst)|vlan_expander filter plugin.
[ansible.netcommon.vlan_parser](https://github.com/ansible-collections/ansible.netcommon/blob/main/docs/ansible.netcommon.vlan_parser_filter.rst)|vlan_parser filter plugin.

### Httpapi plugins
Name | Description
Expand Down
10 changes: 10 additions & 0 deletions changelogs/fragments/vlan_extender.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
trivial:
- vlan_expander - Filter plugin updated as individual plugin.
- vlan_parser - Filter plugin updated as individual plugin.
- type5_pw - Filter plugin updated as individual plugin.
- parse_xml - Filter plugin updated as individual plugin.
- comp_type5 - Filter plugin updated as individual plugin.
- hash_salt - Filter plugin updated as individual plugin.
- parse_cli - Filter plugin updated as individual plugin.
- parse_cli_textfsm - Filter plugin updated as individual plugin.
108 changes: 108 additions & 0 deletions plugins/filter/comp_type5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#
# -*- coding: utf-8 -*-
# Copyright 2023 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#

"""
The comp_type5 filter plugin
"""
from __future__ import absolute_import, division, print_function


__metaclass__ = type

DOCUMENTATION = """
name: comp_type5
author: Ansible Network Community (@ansible-network)
version_added: "5.1.0"
short_description: comp_type5 filter plugin.
description:
- The filter plugin extends vlans when data.
- Using the parameters below - C(password | ansible.netcommon.comp_type5(template.yml))
notes:
- The filter plugin extends vlans when data provided in range or comma separated.
options:
unencrypted_password:
description:
- The unencrypted text.
type: str
required: True
encrypted_password:
description:
- The encrypted text.
type: str
required: True
return_original:
description:
- Return the original text.
type: bool
"""

EXAMPLES = r"""
# Using comp_type5

# playbook

- name: Set the facts
ansible.builtin.set_fact:
unencrypted_password: "cisco@123"
encrypted_password: "$1$avs$uSTOEMh65qzvpb9yBMpzd/"

- name: Invoke comp_type5
ansible.builtin.debug:
msg: "{{ unencrypted_password | ansible.netcommon.comp_type5(encrypted_password, False ) }}"

# Task Output
# -----------
#
# TASK [Set the facts]
# ok: [35.155.113.92] => changed=false
# ansible_facts:
# encrypted_password: $1$avs$uSTOEMh65qzvpb9yBMpzd/
# unencrypted_password: cisco@123

# TASK [Invoke comp_type5]
# ok: [35.155.113.92] =>
# msg: true
"""

from ansible.errors import AnsibleFilterError
from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import (
AnsibleArgSpecValidator,
)

from ansible_collections.ansible.netcommon.plugins.plugin_utils.comp_type5 import comp_type5


try:
from jinja2.filters import pass_environment
except ImportError:
from jinja2.filters import environmentfilter as pass_environment


@pass_environment
def _comp_type5(*args, **kwargs):
"""Extend vlan data"""

keys = [
"unencrypted_password",
"encrypted_password",
"return_original",
]
data = dict(zip(keys, args[1:]))
data.update(kwargs)
aav = AnsibleArgSpecValidator(data=data, schema=DOCUMENTATION, name="comp_type5")
valid, errors, updated_data = aav.validate()
if not valid:
raise AnsibleFilterError(errors)
return comp_type5(**updated_data)


class FilterModule(object):
"""comp_type5"""

def filters(self):
"""a mapping of filter names to functions"""
return {"comp_type5": _comp_type5}
96 changes: 96 additions & 0 deletions plugins/filter/hash_salt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#
# -*- coding: utf-8 -*-
# Copyright 2023 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#

"""
The hash_salt filter plugin
"""
from __future__ import absolute_import, division, print_function


__metaclass__ = type

DOCUMENTATION = """
name: hash_salt
author: Ansible Network Community (@ansible-network)
version_added: "5.1.0"
short_description: hash_salt filter plugin.
description:
- The filter plugin extends vlans when data.
- Using the parameters below - C(password | ansible.netcommon.hash_salt(template.yml))
notes:
- The filter plugin extends vlans when data provided in range or comma separated.
options:
password:
description:
- This source data on which hash_salt invokes.
- For example C(password | ansible.netcommon.hash_salt),
in this case C(password) represents this option.
type: str
required: True
"""

EXAMPLES = r"""
# Using hash_salt

# playbook

- name: Set the facts
ansible.builtin.set_fact:
password: "$1$avs$uSTOEMh65qzvpb9yBMpzd/"

- name: Invoke hash_salt
ansible.builtin.debug:
msg: "{{ password | ansible.netcommon.hash_salt() }}"


# Task Output
# -----------
#
# TASK [The lookup]
# ok: [host] => changed=false
# ansible_facts:
# password: $1$avs$uSTOEMh65qzvpb9yBMpzd/

# TASK [Invoke hash_salt]
# ok: [host] =>
# msg: avs
"""

from ansible.errors import AnsibleFilterError
from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import (
AnsibleArgSpecValidator,
)

from ansible_collections.ansible.netcommon.plugins.plugin_utils.hash_salt import hash_salt


try:
from jinja2.filters import pass_environment
except ImportError:
from jinja2.filters import environmentfilter as pass_environment


@pass_environment
def _hash_salt(*args, **kwargs):
"""Extend vlan data"""

keys = ["password"]
data = dict(zip(keys, args[1:]))
data.update(kwargs)
aav = AnsibleArgSpecValidator(data=data, schema=DOCUMENTATION, name="hash_salt")
valid, errors, updated_data = aav.validate()
if not valid:
raise AnsibleFilterError(errors)
return hash_salt(**updated_data)


class FilterModule(object):
"""hash_salt"""

def filters(self):
"""a mapping of filter names to functions"""
return {"hash_salt": _hash_salt}
Loading
Loading