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

[Refactor python-gvm API] Step 2: Detach ReportFormat, Ticket, Roles #470

Merged
merged 20 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ad13873
Detach Tickets class to TicketsMixin
y0urself May 20, 2021
1baa919
Detach ReportFormats into ReportFormatsMixin
y0urself May 20, 2021
dbb0edc
Merge branch 'master' of https://github.com/greenbone/python-gvm into…
y0urself May 20, 2021
6cb2b35
Activate coverage branching
y0urself May 20, 2021
bb21874
Detach Roles into RolesMixin
y0urself May 20, 2021
f80ef2e
Moved ReportFormat tests into new structure
y0urself May 20, 2021
d2652e9
Moved Roles tests into new structure
y0urself May 20, 2021
98b93d3
Moved Ticket tests into new structure
y0urself May 20, 2021
d7e7a6d
Increase Coverage for filter tests, filter->filter_string
y0urself May 20, 2021
96c7c01
Improve create_audit/task, increase their coverage, filter->filter_st…
y0urself May 20, 2021
28db732
Increase coverage of alerts
y0urself May 20, 2021
fdab070
Increase coverage of targets, filter->filter_string
y0urself May 20, 2021
5fee72b
Increate TLS Certificate coverage, filter->filter_string
y0urself May 20, 2021
60bac74
Increase Portranges coverage, PortList: filter->filter_string
y0urself May 20, 2021
74e2df0
Removed if-condition that is senseless, filter->filter_string
y0urself May 20, 2021
1c345fa
Added CHangelog entries
y0urself May 20, 2021
051a27f
208->214 to test correct version
y0urself May 20, 2021
39a894e
Merge branch 'master' into detach-rest
y0urself May 20, 2021
6a90511
Apply suggestions
y0urself May 21, 2021
a3bacf6
Merge branch 'detach-rest' of https://github.com/y0urself/python-gvm …
y0urself May 21, 2021
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ commands:
command: poetry run pip install codecov
- run:
name: Run unit tests
command: poetry run coverage run -m unittest
command: poetry run coverage run --branch -m unittest
- run:
name: Upload coverage to Codecov
command: poetry run codecov
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ and this project adheres to [Calendar Versioning](https://calver.org)html).
* Introduced new explicit API calls for SecInfo: `get_nvt()`, `get_nvt_list()`, `get_cpe()`, `get_cpe_list()`, `get_cve()`, `get_cve_list()`, `get_cert_bund_advisory()`, `get_cert_bund_advisory_list()`, `get_dnf_cert_advisory()`, `get_dnf_cert_advisory_list()`, `get_oval_definition()`, `get_oval_definition_list()`. [#456](https://github.com/greenbone/python-gvm/pull/456)

### Changed
* Changed `filter` to `filter_string` in getter functions. [#470](https://github.com/greenbone/python-gvm/pull/470)
* Detached the ReportFormats API calls from the GMP class into a new `ReportFormatsMixin`. [#470](https://github.com/greenbone/python-gvm/pull/470)
* Detached the Roles API calls from the GMP class into a new `RolesMixin`. [#470](https://github.com/greenbone/python-gvm/pull/470)
* Detached the Tickets API calls from the GMP class into a new `TicketsMixin`. [#470](https://github.com/greenbone/python-gvm/pull/470)
* Detached the HostsOrdering Type from the GMP types class. [#469](https://github.com/greenbone/python-gvm/pull/469)
* Detached the TicketStatus Type from the GMP types class. [#469](https://github.com/greenbone/python-gvm/pull/469)
* Detached the Schedules API calls from the GMP class into a new `SchedulesMixin`. [#469](https://github.com/greenbone/python-gvm/pull/469)
Expand Down
6 changes: 6 additions & 0 deletions gvm/protocols/gmpv208/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@
from gvm.protocols.gmpv208.entities.results import ResultsMixin
from gvm.protocols.gmpv208.entities.report_formats import (
ReportFormatType,
ReportFormatsMixin,
get_report_format_id_from_string,
)
from gvm.protocols.gmpv208.entities.roles import RolesMixin
from gvm.protocols.gmpv208.entities.scan_configs import ScanConfigsMixin
from gvm.protocols.gmpv208.entities.scanners import (
ScannersMixin,
Expand All @@ -121,6 +123,7 @@
)
from gvm.protocols.gmpv208.entities.tasks import TasksMixin
from gvm.protocols.gmpv208.entities.tickets import (
TicketsMixin,
TicketStatus,
get_ticket_status_from_string,
)
Expand Down Expand Up @@ -150,11 +153,14 @@ class Gmp(
PermissionsMixin,
PoliciesMixin,
PortListMixin,
ReportFormatsMixin,
ReportsMixin,
ResultsMixin,
RolesMixin,
TagsMixin,
TargetsMixin,
TasksMixin,
TicketsMixin,
TLSCertificateMixin,
ScanConfigsMixin,
ScannersMixin,
Expand Down
18 changes: 12 additions & 6 deletions gvm/protocols/gmpv208/entities/audits.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,15 @@ def create_audit(
)
cmd.add_element("hosts_ordering", hosts_ordering.value)

if alert_ids:
if is_list_like(alert_ids):
# parse all given alert id's
if alert_ids is not None:
if not is_list_like(alert_ids):
raise InvalidArgumentType(
function=self.modify_task.__name__,
argument='alert_ids',
arg_type='list',
)

if not len(alert_ids) == 0:
for alert in alert_ids:
cmd.add_element("alert", attrs={"id": str(alert)})

Expand Down Expand Up @@ -204,7 +210,7 @@ def delete_audit(
def get_audits(
self,
*,
filter: Optional[str] = None,
filter_string: Optional[str] = None,
filter_id: Optional[str] = None,
trash: Optional[bool] = None,
details: Optional[bool] = None,
Expand All @@ -213,7 +219,7 @@ def get_audits(
"""Request a list of audits

Arguments:
filter: Filter term to use for the query
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: Whether to get the trashcan audits instead
details: Whether to include full audit details
Expand All @@ -226,7 +232,7 @@ def get_audits(
cmd = XmlCommand("get_tasks")
cmd.set_attribute("usage_type", "audit")

add_filter(cmd, filter, filter_id)
add_filter(cmd, filter_string, filter_id)

if trash is not None:
cmd.set_attribute("trash", to_bool(trash))
Expand Down
8 changes: 3 additions & 5 deletions gvm/protocols/gmpv208/entities/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# pylint: disable=redefined-builtin

from enum import Enum
from typing import Any, Optional

Expand Down Expand Up @@ -175,15 +173,15 @@ def delete_filter(
def get_filters(
self,
*,
filter: Optional[str] = None,
filter_string: Optional[str] = None,
filter_id: Optional[str] = None,
trash: Optional[bool] = None,
alerts: Optional[bool] = None,
) -> Any:
"""Request a list of filters

Arguments:
filter: Filter term to use for the query
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: Whether to get the trashcan filters instead
alerts: Whether to include list of alerts that use the filter.
Expand All @@ -193,7 +191,7 @@ def get_filters(
"""
cmd = XmlCommand("get_filters")

add_filter(cmd, filter, filter_id)
add_filter(cmd, filter_string, filter_id)

if trash is not None:
cmd.set_attribute("trash", to_bool(trash))
Expand Down
6 changes: 3 additions & 3 deletions gvm/protocols/gmpv208/entities/port_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def delete_port_range(self, port_range_id: str) -> Any:
def get_port_lists(
self,
*,
filter: Optional[str] = None,
filter_string: Optional[str] = None,
filter_id: Optional[str] = None,
details: Optional[bool] = None,
targets: Optional[bool] = None,
Expand All @@ -216,7 +216,7 @@ def get_port_lists(
"""Request a list of port lists

Arguments:
filter: Filter term to use for the query
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
details: Whether to include full port list details
targets: Whether to include targets using this port list
Expand All @@ -227,7 +227,7 @@ def get_port_lists(
"""
cmd = XmlCommand("get_port_lists")

add_filter(cmd, filter, filter_id)
add_filter(cmd, filter_string, filter_id)

if details is not None:
cmd.set_attribute("details", to_bool(details))
Expand Down
Loading