besapi 4.0.1__tar.gz → 4.0.2__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-4.0.1/src/besapi.egg-info → besapi-4.0.2}/PKG-INFO +1 -1
- {besapi-4.0.1 → besapi-4.0.2}/src/besapi/besapi.py +70 -1
- {besapi-4.0.1 → besapi-4.0.2/src/besapi.egg-info}/PKG-INFO +1 -1
- {besapi-4.0.1 → besapi-4.0.2}/src/bescli/bescli.py +17 -3
- {besapi-4.0.1 → besapi-4.0.2}/tests/test_besapi.py +24 -0
- {besapi-4.0.1 → besapi-4.0.2}/LICENSE.txt +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/MANIFEST.in +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/README.md +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/pyproject.toml +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/setup.cfg +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/setup.py +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/src/besapi/__init__.py +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/src/besapi/__main__.py +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/src/besapi/plugin_utilities.py +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/src/besapi/plugin_utilities_win.py +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/src/besapi/schemas/BES.xsd +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/src/besapi/schemas/BESAPI.xsd +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/src/besapi/schemas/BESActionSettings.xsd +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/src/besapi.egg-info/SOURCES.txt +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/src/besapi.egg-info/dependency_links.txt +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/src/besapi.egg-info/requires.txt +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/src/besapi.egg-info/top_level.txt +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/src/bescli/__init__.py +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/src/bescli/__main__.py +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/tests/test_plugin_utilities.py +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/tests/test_plugin_utilities_logging.py +0 -0
- {besapi-4.0.1 → besapi-4.0.2}/tests/tests.py +0 -0
|
@@ -12,6 +12,7 @@ Library for communicating with the BES (BigFix) REST API.
|
|
|
12
12
|
|
|
13
13
|
import configparser
|
|
14
14
|
import datetime
|
|
15
|
+
import getpass
|
|
15
16
|
import hashlib
|
|
16
17
|
import importlib.resources
|
|
17
18
|
import json
|
|
@@ -20,6 +21,7 @@ import os
|
|
|
20
21
|
import random
|
|
21
22
|
import site
|
|
22
23
|
import string
|
|
24
|
+
import sys
|
|
23
25
|
import urllib.parse
|
|
24
26
|
|
|
25
27
|
import lxml.etree
|
|
@@ -27,7 +29,7 @@ import lxml.objectify
|
|
|
27
29
|
import requests
|
|
28
30
|
import urllib3.poolmanager
|
|
29
31
|
|
|
30
|
-
__version__ = "4.0.
|
|
32
|
+
__version__ = "4.0.2"
|
|
31
33
|
|
|
32
34
|
besapi_logger = logging.getLogger("besapi")
|
|
33
35
|
|
|
@@ -304,6 +306,73 @@ def get_bes_conn_using_config_file(conf_file=None):
|
|
|
304
306
|
return None
|
|
305
307
|
|
|
306
308
|
|
|
309
|
+
def get_bes_conn_interactive(
|
|
310
|
+
user=None, password=None, root_server=None, force_prompt=False
|
|
311
|
+
):
|
|
312
|
+
"""Get BESConnection using interactive prompts."""
|
|
313
|
+
|
|
314
|
+
if not (force_prompt or sys.__stdin__.isatty()):
|
|
315
|
+
logging.error("No TTY available for interactive login!")
|
|
316
|
+
return None
|
|
317
|
+
|
|
318
|
+
print(
|
|
319
|
+
"Attempting BESAPI Connection using interactive prompts. Use Ctrl-C to cancel."
|
|
320
|
+
)
|
|
321
|
+
try:
|
|
322
|
+
if not user:
|
|
323
|
+
user = str(input("User [%s]: " % getpass.getuser())).strip()
|
|
324
|
+
if not user:
|
|
325
|
+
user = getpass.getuser()
|
|
326
|
+
|
|
327
|
+
if not root_server:
|
|
328
|
+
root_server = str(
|
|
329
|
+
input("Root Server (ex. %s): " % "https://localhost:52311")
|
|
330
|
+
).strip()
|
|
331
|
+
if not root_server or root_server == "":
|
|
332
|
+
print("Root Server is required, try again!")
|
|
333
|
+
return get_bes_conn_interactive(
|
|
334
|
+
user=user,
|
|
335
|
+
password=password,
|
|
336
|
+
root_server=None,
|
|
337
|
+
force_prompt=force_prompt,
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
if not password:
|
|
341
|
+
password = str(
|
|
342
|
+
getpass.getpass(f"Password for {user}@{root_server}: ")
|
|
343
|
+
).strip()
|
|
344
|
+
|
|
345
|
+
if not password or password == "":
|
|
346
|
+
print("Password is required, try again!")
|
|
347
|
+
return get_bes_conn_interactive(
|
|
348
|
+
user=user,
|
|
349
|
+
password=None,
|
|
350
|
+
root_server=root_server,
|
|
351
|
+
force_prompt=force_prompt,
|
|
352
|
+
)
|
|
353
|
+
except (KeyboardInterrupt, EOFError):
|
|
354
|
+
print("\nLogin cancelled.")
|
|
355
|
+
return None
|
|
356
|
+
|
|
357
|
+
try:
|
|
358
|
+
return BESConnection(user, password, root_server)
|
|
359
|
+
except requests.exceptions.HTTPError as err:
|
|
360
|
+
print("Bad Password, Try again!")
|
|
361
|
+
logging.debug(err)
|
|
362
|
+
return get_bes_conn_interactive(
|
|
363
|
+
user=user, password=None, root_server=root_server, force_prompt=force_prompt
|
|
364
|
+
)
|
|
365
|
+
except requests.exceptions.ConnectionError as err:
|
|
366
|
+
print("Bad Root Server Specified, Try again!")
|
|
367
|
+
logging.debug("Connection Error: %s", err)
|
|
368
|
+
return get_bes_conn_interactive(
|
|
369
|
+
user=user, password=password, root_server=None, force_prompt=force_prompt
|
|
370
|
+
)
|
|
371
|
+
except Exception as e: # pylint: disable=broad-except
|
|
372
|
+
logging.error("Error occurred while establishing BESConnection: %s", e)
|
|
373
|
+
return None
|
|
374
|
+
|
|
375
|
+
|
|
307
376
|
# https://docs.python-requests.org/en/latest/user/advanced/#transport-adapters
|
|
308
377
|
class HTTPAdapterBlocksize(requests.adapters.HTTPAdapter):
|
|
309
378
|
"""Custom HTTPAdapter for requests to override blocksize
|
|
@@ -216,6 +216,20 @@ class BESCLInterface(Cmd):
|
|
|
216
216
|
self.pfeedback(" - attempt login using config parameters - ")
|
|
217
217
|
self.do_login()
|
|
218
218
|
|
|
219
|
+
def do_login_new(self, user=None):
|
|
220
|
+
"""Login to BigFix Server."""
|
|
221
|
+
if not user or str(user).strip() == "":
|
|
222
|
+
user = self.BES_USER_NAME
|
|
223
|
+
self.bes_conn = besapi.get_bes_conn_interactive(
|
|
224
|
+
user=user,
|
|
225
|
+
password=self.BES_PASSWORD,
|
|
226
|
+
root_server=self.BES_ROOT_SERVER,
|
|
227
|
+
)
|
|
228
|
+
if self.bes_conn:
|
|
229
|
+
self.pfeedback("Login Successful!")
|
|
230
|
+
(self.BES_USER_NAME, self.BES_PASSWORD) = self.bes_conn.session.auth
|
|
231
|
+
self.BES_ROOT_SERVER = self.bes_conn.rootserver
|
|
232
|
+
|
|
219
233
|
def do_login(self, user=None):
|
|
220
234
|
"""Login to BigFix Server."""
|
|
221
235
|
|
|
@@ -227,7 +241,7 @@ class BESCLInterface(Cmd):
|
|
|
227
241
|
if not user:
|
|
228
242
|
user = getpass.getuser()
|
|
229
243
|
|
|
230
|
-
self.BES_USER_NAME = user
|
|
244
|
+
self.BES_USER_NAME = user.strip()
|
|
231
245
|
if not self.CONFPARSER.has_section("besapi"):
|
|
232
246
|
self.CONFPARSER.add_section("besapi")
|
|
233
247
|
self.CONFPARSER.set("besapi", "BES_USER_NAME", user)
|
|
@@ -237,14 +251,14 @@ class BESCLInterface(Cmd):
|
|
|
237
251
|
if not root_server:
|
|
238
252
|
root_server = str(input("Root Server [%s]: " % self.BES_ROOT_SERVER))
|
|
239
253
|
|
|
240
|
-
self.BES_ROOT_SERVER = root_server
|
|
254
|
+
self.BES_ROOT_SERVER = root_server.strip()
|
|
241
255
|
|
|
242
256
|
else:
|
|
243
257
|
root_server = str(
|
|
244
258
|
input("Root Server (ex. %s): " % "https://server.institution.edu:52311")
|
|
245
259
|
)
|
|
246
260
|
if root_server:
|
|
247
|
-
self.BES_ROOT_SERVER = root_server
|
|
261
|
+
self.BES_ROOT_SERVER = root_server.strip()
|
|
248
262
|
if not self.CONFPARSER.has_section("besapi"):
|
|
249
263
|
self.CONFPARSER.add_section("besapi")
|
|
250
264
|
self.CONFPARSER.set("besapi", "BES_ROOT_SERVER", root_server)
|
|
@@ -316,6 +316,30 @@ def test_bes_conn_json():
|
|
|
316
316
|
pytest.skip("Skipping BESConnection test, no config file or login failed.")
|
|
317
317
|
|
|
318
318
|
|
|
319
|
+
def test_bes_conn_upload_always():
|
|
320
|
+
"""Test the BESConnection class with JSON output."""
|
|
321
|
+
file_name = "LICENSE.txt"
|
|
322
|
+
file_path = "../" + file_name
|
|
323
|
+
if not os.path.isfile(os.path.abspath(file_path)):
|
|
324
|
+
# handle case where not running from src or tests folder.
|
|
325
|
+
file_path = "./" + file_name
|
|
326
|
+
assert os.path.isfile(os.path.abspath(file_path))
|
|
327
|
+
|
|
328
|
+
bes_conn = besapi.plugin_utilities.get_besapi_connection(None)
|
|
329
|
+
if bes_conn and bes_conn.login():
|
|
330
|
+
# test upload
|
|
331
|
+
# Example Header:: Content-Disposition: attachment; filename="file.xml"
|
|
332
|
+
headers = {"Content-Disposition": f'attachment; filename="{file_name}"'}
|
|
333
|
+
with open(file_path, "rb") as f:
|
|
334
|
+
result = bes_conn.post(bes_conn.url("upload"), data=f, headers=headers)
|
|
335
|
+
print(result)
|
|
336
|
+
assert result is not None
|
|
337
|
+
assert result.besobj.FileUpload.Available == 1
|
|
338
|
+
assert result.besdict["FileUpload"]["Available"] == "1"
|
|
339
|
+
else:
|
|
340
|
+
pytest.skip("Skipping BESConnection upload test, login failed.")
|
|
341
|
+
|
|
342
|
+
|
|
319
343
|
def test_plugin_utilities_logging():
|
|
320
344
|
"""Test the plugin_utilities module."""
|
|
321
345
|
print(besapi.plugin_utilities.get_invoke_folder())
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|