besapi 3.9.6__tar.gz → 3.9.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {besapi-3.9.6/src/besapi.egg-info → besapi-3.9.8}/PKG-INFO +2 -1
- {besapi-3.9.6 → besapi-3.9.8}/setup.cfg +1 -0
- {besapi-3.9.6 → besapi-3.9.8}/src/besapi/besapi.py +39 -16
- {besapi-3.9.6 → besapi-3.9.8}/src/besapi/plugin_utilities.py +2 -0
- {besapi-3.9.6 → besapi-3.9.8/src/besapi.egg-info}/PKG-INFO +2 -1
- besapi-3.9.8/src/besapi.egg-info/requires.txt +7 -0
- {besapi-3.9.6 → besapi-3.9.8}/src/bescli/bescli.py +9 -0
- {besapi-3.9.6 → besapi-3.9.8}/tests/test_plugin_utilities_logging.py +17 -0
- besapi-3.9.6/src/besapi.egg-info/requires.txt +0 -4
- {besapi-3.9.6 → besapi-3.9.8}/LICENSE.txt +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/MANIFEST.in +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/README.md +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/pyproject.toml +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/setup.py +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/src/besapi/__init__.py +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/src/besapi/__main__.py +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/src/besapi/plugin_utilities_win.py +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/src/besapi/schemas/BES.xsd +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/src/besapi/schemas/BESAPI.xsd +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/src/besapi/schemas/BESActionSettings.xsd +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/src/besapi.egg-info/SOURCES.txt +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/src/besapi.egg-info/dependency_links.txt +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/src/besapi.egg-info/top_level.txt +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/src/bescli/__init__.py +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/src/bescli/__main__.py +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/tests/test_besapi.py +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/tests/test_plugin_utilities.py +0 -0
- {besapi-3.9.6 → besapi-3.9.8}/tests/tests.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: besapi
|
|
3
|
-
Version: 3.9.
|
|
3
|
+
Version: 3.9.8
|
|
4
4
|
Summary: Library for working with the BigFix REST API
|
|
5
5
|
Home-page: https://github.com/jgstew/besapi
|
|
6
6
|
Author: Matt Hansen, James Stewart
|
|
@@ -24,6 +24,7 @@ Requires-Dist: cmd2
|
|
|
24
24
|
Requires-Dist: lxml
|
|
25
25
|
Requires-Dist: requests
|
|
26
26
|
Requires-Dist: setuptools
|
|
27
|
+
Requires-Dist: pywin32; platform_system == "Windows"
|
|
27
28
|
Dynamic: license-file
|
|
28
29
|
|
|
29
30
|
# besapi
|
|
@@ -26,7 +26,7 @@ import lxml.etree
|
|
|
26
26
|
import lxml.objectify
|
|
27
27
|
import requests
|
|
28
28
|
|
|
29
|
-
__version__ = "3.9.
|
|
29
|
+
__version__ = "3.9.8"
|
|
30
30
|
|
|
31
31
|
besapi_logger = logging.getLogger("besapi")
|
|
32
32
|
|
|
@@ -195,7 +195,7 @@ def get_target_xml(targets=None):
|
|
|
195
195
|
- Array of Integers: ComputerID
|
|
196
196
|
"""
|
|
197
197
|
if targets is None or not targets:
|
|
198
|
-
|
|
198
|
+
besapi_logger.warning("No valid targeting found, will target no computers.")
|
|
199
199
|
# default if invalid:
|
|
200
200
|
return "<CustomRelevance>False</CustomRelevance>"
|
|
201
201
|
|
|
@@ -237,7 +237,7 @@ def get_target_xml(targets=None):
|
|
|
237
237
|
+ "</ComputerName>"
|
|
238
238
|
)
|
|
239
239
|
|
|
240
|
-
|
|
240
|
+
besapi_logger.warning("No valid targeting found, will target no computers.")
|
|
241
241
|
|
|
242
242
|
# default if invalid:
|
|
243
243
|
return "<CustomRelevance>False</CustomRelevance>"
|
|
@@ -354,8 +354,11 @@ class BESConnection:
|
|
|
354
354
|
self.username = username
|
|
355
355
|
self.session = requests.Session()
|
|
356
356
|
self.session.auth = (username, password)
|
|
357
|
-
|
|
358
|
-
#
|
|
357
|
+
|
|
358
|
+
# store if connection user is main operator
|
|
359
|
+
self.is_main_operator = None
|
|
360
|
+
|
|
361
|
+
self.webreports_info_xml = None
|
|
359
362
|
|
|
360
363
|
# use a sitepath context if none specified when required.
|
|
361
364
|
self.site_path = "master"
|
|
@@ -425,11 +428,11 @@ class BESConnection:
|
|
|
425
428
|
if not validate_xsd(data):
|
|
426
429
|
err_msg = "data being posted did not validate to XML schema. If expected, consider setting validate_xml to false."
|
|
427
430
|
if validate_xml:
|
|
428
|
-
|
|
431
|
+
besapi_logger.error(err_msg)
|
|
429
432
|
raise ValueError(err_msg)
|
|
430
433
|
|
|
431
434
|
# this is intended it validate_xml is None, but not used currently
|
|
432
|
-
|
|
435
|
+
besapi_logger.warning(err_msg)
|
|
433
436
|
|
|
434
437
|
self.last_connected = datetime.datetime.now()
|
|
435
438
|
return RESTResult(
|
|
@@ -446,11 +449,11 @@ class BESConnection:
|
|
|
446
449
|
if not validate_xsd(data):
|
|
447
450
|
err_msg = "data being put did not validate to XML schema. If expected, consider setting validate_xml to false."
|
|
448
451
|
if validate_xml:
|
|
449
|
-
|
|
452
|
+
besapi_logger.error(err_msg)
|
|
450
453
|
raise ValueError(err_msg)
|
|
451
454
|
|
|
452
455
|
# this is intended it validate_xml is None, but not used currently
|
|
453
|
-
|
|
456
|
+
besapi_logger.warning(err_msg)
|
|
454
457
|
|
|
455
458
|
return RESTResult(
|
|
456
459
|
self.session.put(self.url(path), data=data, verify=self.verify, **kwargs)
|
|
@@ -463,6 +466,21 @@ class BESConnection:
|
|
|
463
466
|
self.session.delete(self.url(path), verify=self.verify, **kwargs)
|
|
464
467
|
)
|
|
465
468
|
|
|
469
|
+
def am_i_main_operator(self):
|
|
470
|
+
"""Check if the current user is the main operator user."""
|
|
471
|
+
if self.is_main_operator is None:
|
|
472
|
+
try:
|
|
473
|
+
self.webreports_info_xml = self.get("webreports")
|
|
474
|
+
self.is_main_operator = True
|
|
475
|
+
except PermissionError:
|
|
476
|
+
self.is_main_operator = False
|
|
477
|
+
except Exception as err: # pylint: disable=broad-except
|
|
478
|
+
besapi_logger.error("Error checking if main operator: %s", err)
|
|
479
|
+
self.is_main_operator = None
|
|
480
|
+
|
|
481
|
+
if self.is_main_operator is not None:
|
|
482
|
+
return self.is_main_operator
|
|
483
|
+
|
|
466
484
|
def session_relevance_json(self, relevance, **kwargs):
|
|
467
485
|
"""Get Session Relevance Results in JSON.
|
|
468
486
|
|
|
@@ -738,8 +756,9 @@ class BESConnection:
|
|
|
738
756
|
besapi_logger.warning("User `%s` Already Exists!", new_user_name)
|
|
739
757
|
return result_user
|
|
740
758
|
besapi_logger.info("Creating User `%s`", new_user_name)
|
|
741
|
-
|
|
742
|
-
|
|
759
|
+
user_result = self.post("operators", lxml.etree.tostring(xml_parsed))
|
|
760
|
+
besapi_logger.debug("user creation result:\n%s", user_result)
|
|
761
|
+
|
|
743
762
|
return self.get_user(new_user_name)
|
|
744
763
|
|
|
745
764
|
def get_computergroup(self, group_name, site_path=None):
|
|
@@ -771,7 +790,11 @@ class BESConnection:
|
|
|
771
790
|
|
|
772
791
|
# print(lxml.etree.tostring(xml_parsed))
|
|
773
792
|
|
|
774
|
-
|
|
793
|
+
create_group_result = self.post(
|
|
794
|
+
f"computergroups/{site_path}", lxml.etree.tostring(xml_parsed)
|
|
795
|
+
)
|
|
796
|
+
|
|
797
|
+
besapi_logger.debug("group creation result:\n%s", create_group_result)
|
|
775
798
|
|
|
776
799
|
return self.get_computergroup(site_path, new_group_name)
|
|
777
800
|
|
|
@@ -796,7 +819,7 @@ class BESConnection:
|
|
|
796
819
|
raise ValueError("No file_name specified. Must be at least one character.")
|
|
797
820
|
|
|
798
821
|
if "Upload not found" in result.text:
|
|
799
|
-
|
|
822
|
+
besapi_logger.debug("WARNING: Upload not found!")
|
|
800
823
|
return None
|
|
801
824
|
|
|
802
825
|
return result
|
|
@@ -882,8 +905,8 @@ class BESConnection:
|
|
|
882
905
|
try:
|
|
883
906
|
content = self.get(resource_url.replace("http://", "https://"))
|
|
884
907
|
except PermissionError as err:
|
|
885
|
-
|
|
886
|
-
|
|
908
|
+
besapi_logger.error("Could not export item:")
|
|
909
|
+
besapi_logger.error(err)
|
|
887
910
|
|
|
888
911
|
# item_id = int(resource_url.split("/")[-1])
|
|
889
912
|
# site_name = resource_url.split("/")[-2]
|
|
@@ -1143,7 +1166,7 @@ class RESTResult:
|
|
|
1143
1166
|
if self.validate_xsd(request.text):
|
|
1144
1167
|
self.valid = True
|
|
1145
1168
|
else:
|
|
1146
|
-
|
|
1169
|
+
besapi_logger.debug(
|
|
1147
1170
|
"INFO: REST API Result does not appear to be XML, this could be expected."
|
|
1148
1171
|
)
|
|
1149
1172
|
self.valid = False
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: besapi
|
|
3
|
-
Version: 3.9.
|
|
3
|
+
Version: 3.9.8
|
|
4
4
|
Summary: Library for working with the BigFix REST API
|
|
5
5
|
Home-page: https://github.com/jgstew/besapi
|
|
6
6
|
Author: Matt Hansen, James Stewart
|
|
@@ -24,6 +24,7 @@ Requires-Dist: cmd2
|
|
|
24
24
|
Requires-Dist: lxml
|
|
25
25
|
Requires-Dist: requests
|
|
26
26
|
Requires-Dist: setuptools
|
|
27
|
+
Requires-Dist: pywin32; platform_system == "Windows"
|
|
27
28
|
Dynamic: license-file
|
|
28
29
|
|
|
29
30
|
# besapi
|
|
@@ -385,6 +385,15 @@ class BESCLInterface(Cmd):
|
|
|
385
385
|
# no matter what I try I can't get anything but exit code 0 on windows
|
|
386
386
|
return self.do_quit("")
|
|
387
387
|
|
|
388
|
+
def do_am_i_main_operator(self, _=None):
|
|
389
|
+
"""Check if the connection user is a main operator user."""
|
|
390
|
+
if not self.bes_conn:
|
|
391
|
+
self.do_login()
|
|
392
|
+
if not self.bes_conn:
|
|
393
|
+
self.poutput("ERROR: can't check without login")
|
|
394
|
+
else:
|
|
395
|
+
self.poutput(f"Am I Main Operator? {self.bes_conn.am_i_main_operator()}")
|
|
396
|
+
|
|
388
397
|
def do_query(self, statement):
|
|
389
398
|
"""Get Session Relevance Results."""
|
|
390
399
|
if not self.bes_conn:
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import os
|
|
3
|
+
import sys
|
|
3
4
|
import tempfile
|
|
4
5
|
|
|
5
6
|
import pytest
|
|
6
7
|
|
|
8
|
+
# Ensure the local `src/` is first on sys.path so tests import the workspace package
|
|
9
|
+
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
|
10
|
+
SRC = os.path.join(ROOT, "src")
|
|
11
|
+
if SRC not in sys.path:
|
|
12
|
+
sys.path.insert(0, SRC)
|
|
13
|
+
|
|
7
14
|
from besapi import plugin_utilities
|
|
8
15
|
|
|
9
16
|
|
|
@@ -59,3 +66,13 @@ def test_get_plugin_logging_config_debug_level(tmp_path):
|
|
|
59
66
|
|
|
60
67
|
# verbose>1 -> DEBUG
|
|
61
68
|
assert cfg.get("level") == logging.DEBUG
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_plugin_logging_config_registers_session_level(tmp_path):
|
|
72
|
+
"""Test that get_plugin_logging_config registers the custom SESSION log level
|
|
73
|
+
(99).
|
|
74
|
+
"""
|
|
75
|
+
log_file = tmp_path / "test_session.log"
|
|
76
|
+
plugin_utilities.get_plugin_logging_config(str(log_file), verbose=0, console=False)
|
|
77
|
+
# After calling, the level name for 99 should be 'SESSION'
|
|
78
|
+
assert logging.getLevelName(99) == "SESSION"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|