cdot65 / pan-scm-sdk

Python SDK for Palo Alto Networks Strata Cloud Manager.
https://cdot65.github.io/pan-scm-sdk/
Apache License 2.0
1 stars 1 forks source link

Implement Filters #35

Closed cdot65 closed 1 week ago

cdot65 commented 2 weeks ago

Checklist for This Pull Request

🚨Please adhere to the guidelines for contributing to this repository.

Pull Request Description

The goal of this PR is to implement the filtering capabilities when using the list() method. The behavior changes are as follows:

  1. Increase the default return values to 10,000 to prevent pagination from filtering responses
  2. Retrieve 10000 instances of an object from the SCM API
  3. use the filters, provided as kwargs on the list method, to return only matches
  4. multiple filters are supported with an "and" logical operation

Examples:

In [1]: from scm.config.objects import Address

In [2]: from scm.client import Scm

In [3]: client = Scm(
   ...:     client_id="automation@1234567890.iam.panserviceaccount.com",
   ...:     client_secret="12345678-abcd-efgh-1234-12345678",
   ...:     tsg_id="1234567890",
   ...: )

In [4]: address_client = Address(client)

In [5]: all_addresses = address_client.list(folder='Texas')

In [6]: len(all_addresses)
Out[6]: 3

In [7]: filtered_by_tag = address_client.list(folder='Texas', tags=['Automation'])

In [8]: len(filtered_by_tag)
Out[8]: 2

In [9]: for each in filtered_by_tag:
   ...:     print(f"Name: {each.name}")
   ...:     print(f"Tag: {each.tag}")
   ...: 
Name: test_network1
Tag: ['Automation']
Name: test_network2
Tag: ['Automation']

What does this pull request accomplish?

Are there any breaking changes included?

Is there anything the reviewers should know?

Thank you for your contributions!

codecov[bot] commented 2 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

:white_check_mark: All tests successful. No failed tests found.

Files with missing lines Coverage Δ
scm/config/objects/address.py 100.00% <100.00%> (ø)
scm/config/objects/address_group.py 100.00% <100.00%> (ø)
scm/config/objects/application.py 100.00% <100.00%> (ø)
scm/config/objects/application_group.py 100.00% <100.00%> (ø)
scm/config/objects/service.py 100.00% <100.00%> (ø)
scm/config/security/anti_spyware_profile.py 100.00% <100.00%> (ø)
scm/config/security/decryption_profile.py 100.00% <100.00%> (ø)
scm/config/security/dns_security_profile.py 100.00% <100.00%> (ø)
scm/config/security/security_rule.py 100.00% <100.00%> (ø)
...onfig/security/vulnerability_protection_profile.py 100.00% <100.00%> (ø)
... and 11 more