From 9b2755f0e0272b7a30a7f45ea36160ae34a3e81c Mon Sep 17 00:00:00 2001 From: Gary Robinson Date: Thu, 5 Oct 2017 12:11:16 +0100 Subject: [PATCH 01/10] Fixed user configuration source --- nexpose/nexpose.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nexpose/nexpose.py b/nexpose/nexpose.py index 5526f60..e71bde9 100644 --- a/nexpose/nexpose.py +++ b/nexpose/nexpose.py @@ -1607,9 +1607,10 @@ def GetUserConfiguration(self, user_or_id): # Because of a bug in the API not all expected information is returned in the UserConfiguration object # Retrieve the information using an undocumented method - xml_data = self.ExecuteGet('ajax/user_config.txml', {'userid': user_or_id}) - config.has_access_to_all_sites = get_attribute(xml_data, 'allSites') == 'true' - config.has_access_to_all_assetgroups = get_attribute(xml_data, 'allGroups') == 'true' + xml_data = self.ExecuteGet('/data/user/configuration', {'userid': user_or_id}) + user = xml_data.find('User') + config.has_access_to_all_sites = user.attrib['allSites'] + config.has_access_to_all_assetgroups = user.attrib['allGroups'] config.accessible_sites = [int(get_attribute(xml_site, 'id')) for xml_site in xml_data.findall('Sites/site')] config.accessible_assetgroups = [int(get_attribute(xml_assetgroup, 'id')) for xml_assetgroup in xml_data.findall('Groups/group')] # Groups/group or Groups/Group From 2f97bff4a8cb15f2aecdcb0922105ee205a6bc20 Mon Sep 17 00:00:00 2001 From: Gary Robinson Date: Thu, 5 Oct 2017 16:09:58 +0100 Subject: [PATCH 02/10] Updated private API reference and changed encoding for urllib and python 3 --- nexpose/nexpose.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nexpose/nexpose.py b/nexpose/nexpose.py index e71bde9..56a90dc 100644 --- a/nexpose/nexpose.py +++ b/nexpose/nexpose.py @@ -105,7 +105,7 @@ def ExecuteWithPostData_FORM(session_id, uri, sub_url, timeout, post_data): post_data = as_string(post_data) else: headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8" - post_data = urllib.parse.urlencode(utf8_encoded(post_data)) + post_data = urllib.parse.urlencode(utf8_encoded(post_data)).encode(encoding="utf-8") return ExecuteWebRequest(uri + sub_url, post_data, headers, timeout, lambda: 'POST') @@ -1221,7 +1221,7 @@ def ExecuteMaintenanceCommand(self, target_task, command, extra_parameters): parameters = dict(extra_parameters) parameters['cmd'] = command parameters['targetTask'] = target_task - result = self.ExecuteFormPost('admin/global/maintenance/maintCmd.txml', parameters) + result = self.ExecuteFormPost('data/maintenance/command', parameters) return _HasSucceeded(result) def ExecuteMaintenanceCommandAndRestartOnSuccess(self, target_task, command, extra_parameters): From 5b1b308bf225a1a4c535652afe23022c730515a0 Mon Sep 17 00:00:00 2001 From: Gary Robinson Date: Fri, 6 Oct 2017 14:33:54 +0100 Subject: [PATCH 03/10] Updated NexposeCriteriaField metaclass variable for python 3 --- nexpose/nexpose_criteria_fields.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/nexpose/nexpose_criteria_fields.py b/nexpose/nexpose_criteria_fields.py index de56c3c..b41b577 100644 --- a/nexpose/nexpose_criteria_fields.py +++ b/nexpose/nexpose_criteria_fields.py @@ -12,23 +12,23 @@ def xrange_inclusive(start, included_stop): return range(start, included_stop + 1) +class MetaNex(type): + @property + def Code(cls): + return cls._Code if cls._Code else cls.Name -class NexposeCriteriaField(object): - _Code = None - ValidOperators = [] # Note: this list shouldn't be empty - ValidValues = None # None indicates that any value is accepted + @property + def Name(cls): + return cls.__name__ - class __metaclass__(type): - @property - def Code(cls): - return cls._Code if cls._Code else cls.Name + def __str__(cls): + return cls.Name - @property - def Name(cls): - return cls.__name__ - def __str__(cls): - return cls.Name +class NexposeCriteriaField(object, metaclass=MetaNex): # python 3 + _Code = None + ValidOperators = [] # Note: this list shouldn't be empty + ValidValues = None # None indicates that any value is accepted class ASSET(NexposeCriteriaField): From b9fad1d769ff0d31c3896e29a884eea4bfee9663 Mon Sep 17 00:00:00 2001 From: Gary Robinson Date: Fri, 6 Oct 2017 14:34:12 +0100 Subject: [PATCH 04/10] Updated NexposeCriteriaField metaclass variable for python 3 --- nexpose/nexpose_criteria_fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nexpose/nexpose_criteria_fields.py b/nexpose/nexpose_criteria_fields.py index b41b577..11044cb 100644 --- a/nexpose/nexpose_criteria_fields.py +++ b/nexpose/nexpose_criteria_fields.py @@ -25,7 +25,7 @@ def __str__(cls): return cls.Name -class NexposeCriteriaField(object, metaclass=MetaNex): # python 3 +class NexposeCriteriaField(object, metaclass=MetaNex): # python 3 _Code = None ValidOperators = [] # Note: this list shouldn't be empty ValidValues = None # None indicates that any value is accepted From b0131cabd41b5e9a00c9d7ab83c7fe7c8583a27b Mon Sep 17 00:00:00 2001 From: Gary Robinson Date: Fri, 6 Oct 2017 14:56:01 +0100 Subject: [PATCH 05/10] Pass E302 --- nexpose/nexpose_criteria_fields.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nexpose/nexpose_criteria_fields.py b/nexpose/nexpose_criteria_fields.py index 11044cb..b91d2c1 100644 --- a/nexpose/nexpose_criteria_fields.py +++ b/nexpose/nexpose_criteria_fields.py @@ -12,6 +12,7 @@ def xrange_inclusive(start, included_stop): return range(start, included_stop + 1) + class MetaNex(type): @property def Code(cls): From c0706d222518f369cc45ec5db3524078b2debeeb Mon Sep 17 00:00:00 2001 From: Gary Robinson Date: Fri, 6 Oct 2017 15:17:43 +0100 Subject: [PATCH 06/10] Ignore E999 Flake8 violation for Python 2 --- nexpose/nexpose_criteria_fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nexpose/nexpose_criteria_fields.py b/nexpose/nexpose_criteria_fields.py index b91d2c1..39ae332 100644 --- a/nexpose/nexpose_criteria_fields.py +++ b/nexpose/nexpose_criteria_fields.py @@ -26,7 +26,7 @@ def __str__(cls): return cls.Name -class NexposeCriteriaField(object, metaclass=MetaNex): # python 3 +class NexposeCriteriaField(object, metaclass=MetaNex): # flake8: noqa: E999 _Code = None ValidOperators = [] # Note: this list shouldn't be empty ValidValues = None # None indicates that any value is accepted From bb4f925a788d0373090c725322dcd41a08e5d84d Mon Sep 17 00:00:00 2001 From: Gary Robinson Date: Fri, 6 Oct 2017 15:27:42 +0100 Subject: [PATCH 07/10] Added NOQA --- nexpose/nexpose_criteria_fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nexpose/nexpose_criteria_fields.py b/nexpose/nexpose_criteria_fields.py index 39ae332..e1c649d 100644 --- a/nexpose/nexpose_criteria_fields.py +++ b/nexpose/nexpose_criteria_fields.py @@ -26,7 +26,7 @@ def __str__(cls): return cls.Name -class NexposeCriteriaField(object, metaclass=MetaNex): # flake8: noqa: E999 +class NexposeCriteriaField(object, metaclass=MetaNex): # NOQA _Code = None ValidOperators = [] # Note: this list shouldn't be empty ValidValues = None # None indicates that any value is accepted From 8b3bcbed38e33c799adb388058de6479572f82e2 Mon Sep 17 00:00:00 2001 From: Gary Robinson Date: Fri, 6 Oct 2017 16:14:40 +0100 Subject: [PATCH 08/10] Updated metaclass naming and used with_metaclass --- nexpose/nexpose_criteria_fields.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nexpose/nexpose_criteria_fields.py b/nexpose/nexpose_criteria_fields.py index e1c649d..3fb244e 100644 --- a/nexpose/nexpose_criteria_fields.py +++ b/nexpose/nexpose_criteria_fields.py @@ -6,6 +6,7 @@ from .nexpose_criteria_operators import * from .nexpose_criteria_constants import * from future import standard_library +from future.utils import with_metaclass standard_library.install_aliases() @@ -13,7 +14,7 @@ def xrange_inclusive(start, included_stop): return range(start, included_stop + 1) -class MetaNex(type): +class MetaNexposeCriteriaField(type): @property def Code(cls): return cls._Code if cls._Code else cls.Name @@ -26,7 +27,7 @@ def __str__(cls): return cls.Name -class NexposeCriteriaField(object, metaclass=MetaNex): # NOQA +class NexposeCriteriaField(with_metaclass(MetaNexposeCriteriaField, object)): _Code = None ValidOperators = [] # Note: this list shouldn't be empty ValidValues = None # None indicates that any value is accepted From b7f5afa6f60f3cc83ea6cd9dc4658b49d585bb2c Mon Sep 17 00:00:00 2001 From: Gary Robinson Date: Sat, 7 Oct 2017 18:40:19 +0100 Subject: [PATCH 09/10] Fixed old metaclass syntax --- nexpose/nexpose_criteria_operators.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/nexpose/nexpose_criteria_operators.py b/nexpose/nexpose_criteria_operators.py index 786d74d..dbbb603 100644 --- a/nexpose/nexpose_criteria_operators.py +++ b/nexpose/nexpose_criteria_operators.py @@ -3,17 +3,21 @@ unicode_literals) from builtins import object from future import standard_library +from future.utils import with_metaclass + standard_library.install_aliases() +class MetaNexposeCriteriaOperator(type): + @property + def Code(cls): + return cls.__name__ + + def __str__(cls): + return cls.Code -class NexposeCriteriaOperator(object): - class __metaclass__(type): - @property - def Code(cls): - return cls.__name__ - def __str__(cls): - return cls.Code +class NexposeCriteriaOperator(with_metaclass(MetaNexposeCriteriaOperator, object)): + pass class AND(NexposeCriteriaOperator): From 434a80515180c6f78485dad3b1d3e865b887d1b4 Mon Sep 17 00:00:00 2001 From: Gary Robinson Date: Sat, 7 Oct 2017 19:08:27 +0100 Subject: [PATCH 10/10] PEP8 --- nexpose/nexpose_criteria_operators.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nexpose/nexpose_criteria_operators.py b/nexpose/nexpose_criteria_operators.py index dbbb603..915906c 100644 --- a/nexpose/nexpose_criteria_operators.py +++ b/nexpose/nexpose_criteria_operators.py @@ -7,6 +7,7 @@ standard_library.install_aliases() + class MetaNexposeCriteriaOperator(type): @property def Code(cls):