Skip to content

Commit

Permalink
Merge pull request #470 from y0urself/detach-rest
Browse files Browse the repository at this point in the history
[Refactor python-gvm API] Step 2: Detach ReportFormat, Ticket, Roles
  • Loading branch information
y0urself authored May 21, 2021
2 parents af96e13 + a3bacf6 commit 1471912
Show file tree
Hide file tree
Showing 70 changed files with 1,457 additions and 918 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Configuration for coverage.py
[run]
branch = True
omit =
tests/*
*/__init__.py
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

0 comments on commit 1471912

Please sign in to comment.