besapi 3.9.7__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.
Files changed (27) hide show
  1. {besapi-3.9.7/src/besapi.egg-info → besapi-3.9.8}/PKG-INFO +1 -1
  2. {besapi-3.9.7 → besapi-3.9.8}/src/besapi/besapi.py +33 -15
  3. {besapi-3.9.7 → besapi-3.9.8/src/besapi.egg-info}/PKG-INFO +1 -1
  4. {besapi-3.9.7 → besapi-3.9.8}/src/bescli/bescli.py +9 -0
  5. {besapi-3.9.7 → besapi-3.9.8}/LICENSE.txt +0 -0
  6. {besapi-3.9.7 → besapi-3.9.8}/MANIFEST.in +0 -0
  7. {besapi-3.9.7 → besapi-3.9.8}/README.md +0 -0
  8. {besapi-3.9.7 → besapi-3.9.8}/pyproject.toml +0 -0
  9. {besapi-3.9.7 → besapi-3.9.8}/setup.cfg +0 -0
  10. {besapi-3.9.7 → besapi-3.9.8}/setup.py +0 -0
  11. {besapi-3.9.7 → besapi-3.9.8}/src/besapi/__init__.py +0 -0
  12. {besapi-3.9.7 → besapi-3.9.8}/src/besapi/__main__.py +0 -0
  13. {besapi-3.9.7 → besapi-3.9.8}/src/besapi/plugin_utilities.py +0 -0
  14. {besapi-3.9.7 → besapi-3.9.8}/src/besapi/plugin_utilities_win.py +0 -0
  15. {besapi-3.9.7 → besapi-3.9.8}/src/besapi/schemas/BES.xsd +0 -0
  16. {besapi-3.9.7 → besapi-3.9.8}/src/besapi/schemas/BESAPI.xsd +0 -0
  17. {besapi-3.9.7 → besapi-3.9.8}/src/besapi/schemas/BESActionSettings.xsd +0 -0
  18. {besapi-3.9.7 → besapi-3.9.8}/src/besapi.egg-info/SOURCES.txt +0 -0
  19. {besapi-3.9.7 → besapi-3.9.8}/src/besapi.egg-info/dependency_links.txt +0 -0
  20. {besapi-3.9.7 → besapi-3.9.8}/src/besapi.egg-info/requires.txt +0 -0
  21. {besapi-3.9.7 → besapi-3.9.8}/src/besapi.egg-info/top_level.txt +0 -0
  22. {besapi-3.9.7 → besapi-3.9.8}/src/bescli/__init__.py +0 -0
  23. {besapi-3.9.7 → besapi-3.9.8}/src/bescli/__main__.py +0 -0
  24. {besapi-3.9.7 → besapi-3.9.8}/tests/test_besapi.py +0 -0
  25. {besapi-3.9.7 → besapi-3.9.8}/tests/test_plugin_utilities.py +0 -0
  26. {besapi-3.9.7 → besapi-3.9.8}/tests/test_plugin_utilities_logging.py +0 -0
  27. {besapi-3.9.7 → 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.7
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
@@ -26,7 +26,7 @@ import lxml.etree
26
26
  import lxml.objectify
27
27
  import requests
28
28
 
29
- __version__ = "3.9.7"
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
- logging.warning("No valid targeting found, will target no computers.")
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
- logging.warning("No valid targeting found, will target no computers.")
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
- # store info on operator used to login
358
- # self.operator_info = {}
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
- logging.error(err_msg)
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
- logging.warning(err_msg)
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
- logging.error(err_msg)
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
- logging.warning(err_msg)
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
 
@@ -739,7 +757,7 @@ class BESConnection:
739
757
  return result_user
740
758
  besapi_logger.info("Creating User `%s`", new_user_name)
741
759
  user_result = self.post("operators", lxml.etree.tostring(xml_parsed))
742
- logging.debug("user creation result:\n%s", user_result)
760
+ besapi_logger.debug("user creation result:\n%s", user_result)
743
761
 
744
762
  return self.get_user(new_user_name)
745
763
 
@@ -776,7 +794,7 @@ class BESConnection:
776
794
  f"computergroups/{site_path}", lxml.etree.tostring(xml_parsed)
777
795
  )
778
796
 
779
- logging.debug("group creation result:\n%s", create_group_result)
797
+ besapi_logger.debug("group creation result:\n%s", create_group_result)
780
798
 
781
799
  return self.get_computergroup(site_path, new_group_name)
782
800
 
@@ -801,7 +819,7 @@ class BESConnection:
801
819
  raise ValueError("No file_name specified. Must be at least one character.")
802
820
 
803
821
  if "Upload not found" in result.text:
804
- logging.debug("WARNING: Upload not found!")
822
+ besapi_logger.debug("WARNING: Upload not found!")
805
823
  return None
806
824
 
807
825
  return result
@@ -887,8 +905,8 @@ class BESConnection:
887
905
  try:
888
906
  content = self.get(resource_url.replace("http://", "https://"))
889
907
  except PermissionError as err:
890
- logging.error("Could not export item:")
891
- logging.error(err)
908
+ besapi_logger.error("Could not export item:")
909
+ besapi_logger.error(err)
892
910
 
893
911
  # item_id = int(resource_url.split("/")[-1])
894
912
  # site_name = resource_url.split("/")[-2]
@@ -1148,7 +1166,7 @@ class RESTResult:
1148
1166
  if self.validate_xsd(request.text):
1149
1167
  self.valid = True
1150
1168
  else:
1151
- logging.debug(
1169
+ besapi_logger.debug(
1152
1170
  "INFO: REST API Result does not appear to be XML, this could be expected."
1153
1171
  )
1154
1172
  self.valid = False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: besapi
3
- Version: 3.9.7
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
@@ -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:
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