besapi 3.3.2__tar.gz → 3.4.1__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.3.2/src/besapi.egg-info → besapi-3.4.1}/PKG-INFO +1 -1
- {besapi-3.3.2 → besapi-3.4.1}/src/besapi/besapi.py +1 -1
- {besapi-3.3.2 → besapi-3.4.1}/src/besapi/plugin_utilities.py +71 -18
- {besapi-3.3.2 → besapi-3.4.1/src/besapi.egg-info}/PKG-INFO +1 -1
- {besapi-3.3.2 → besapi-3.4.1}/tests/tests.py +10 -0
- {besapi-3.3.2 → besapi-3.4.1}/LICENSE.txt +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/MANIFEST.in +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/README.md +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/pyproject.toml +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/setup.cfg +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/setup.py +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/src/besapi/__init__.py +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/src/besapi/__main__.py +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/src/besapi/schemas/BES.xsd +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/src/besapi/schemas/BESAPI.xsd +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/src/besapi/schemas/BESActionSettings.xsd +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/src/besapi.egg-info/SOURCES.txt +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/src/besapi.egg-info/dependency_links.txt +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/src/besapi.egg-info/requires.txt +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/src/besapi.egg-info/top_level.txt +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/src/bescli/__init__.py +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/src/bescli/__main__.py +0 -0
- {besapi-3.3.2 → besapi-3.4.1}/src/bescli/bescli.py +0 -0
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"""This is a set of utility functions for use in multiple plugins"""
|
|
2
2
|
|
|
3
3
|
import argparse
|
|
4
|
+
import getpass
|
|
4
5
|
import logging
|
|
5
6
|
import logging.handlers
|
|
6
7
|
import ntpath
|
|
7
8
|
import os
|
|
8
9
|
import sys
|
|
9
10
|
|
|
11
|
+
import besapi
|
|
12
|
+
|
|
10
13
|
|
|
11
14
|
def get_invoke_folder(verbose=0):
|
|
12
15
|
"""Get the folder the script was invoked from"""
|
|
@@ -83,27 +86,25 @@ def setup_plugin_argparse(plugin_args_required=False):
|
|
|
83
86
|
return arg_parser
|
|
84
87
|
|
|
85
88
|
|
|
86
|
-
def setup_plugin_logging(
|
|
89
|
+
def setup_plugin_logging(log_file_path="", verbose=0, console=True):
|
|
87
90
|
"""setup logging for plugin use"""
|
|
88
|
-
# get folder the script was invoked from:
|
|
89
|
-
invoke_folder = get_invoke_folder(verbose)
|
|
90
91
|
|
|
91
|
-
if not
|
|
92
|
-
|
|
92
|
+
if not log_file_path or log_file_path == "":
|
|
93
|
+
log_file_path = os.path.join(
|
|
94
|
+
get_invoke_folder(verbose), get_invoke_file_name(verbose) + ".log"
|
|
95
|
+
)
|
|
93
96
|
|
|
94
97
|
# set different log levels:
|
|
95
98
|
log_level = logging.WARNING
|
|
96
99
|
if verbose:
|
|
97
100
|
log_level = logging.INFO
|
|
101
|
+
print("INFO: Log File Path: %s", log_file_path)
|
|
98
102
|
if verbose > 1:
|
|
99
103
|
log_level = logging.DEBUG
|
|
100
104
|
|
|
101
|
-
# get path to put log file in:
|
|
102
|
-
log_filename = os.path.join(invoke_folder, log_file_name)
|
|
103
|
-
|
|
104
105
|
handlers = [
|
|
105
106
|
logging.handlers.RotatingFileHandler(
|
|
106
|
-
|
|
107
|
+
log_file_path, maxBytes=5 * 1024 * 1024, backupCount=1
|
|
107
108
|
)
|
|
108
109
|
]
|
|
109
110
|
|
|
@@ -120,13 +121,65 @@ def setup_plugin_logging(log_file_name="", verbose=0, console=True):
|
|
|
120
121
|
)
|
|
121
122
|
|
|
122
123
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
#
|
|
129
|
-
|
|
130
|
-
|
|
124
|
+
def get_besapi_connection(args):
|
|
125
|
+
"""get connection to besapi using either args or config file if args not provided"""
|
|
126
|
+
|
|
127
|
+
password = args.password
|
|
128
|
+
|
|
129
|
+
# if user was provided as arg but password was not:
|
|
130
|
+
if args.user and not password:
|
|
131
|
+
logging.warning("Password was not provided, provide REST API password.")
|
|
132
|
+
print("Password was not provided, provide REST API password:")
|
|
133
|
+
password = getpass.getpass()
|
|
134
|
+
|
|
135
|
+
if args.user:
|
|
136
|
+
logging.debug("REST API Password Length: %s", len(password))
|
|
137
|
+
|
|
138
|
+
# process args, setup connection:
|
|
139
|
+
rest_url = args.rest_url
|
|
140
|
+
|
|
141
|
+
# normalize url to https://HostOrIP:52311
|
|
142
|
+
if rest_url and rest_url.endswith("/api"):
|
|
143
|
+
rest_url = rest_url.replace("/api", "")
|
|
144
|
+
|
|
145
|
+
# attempt bigfix connection with provided args:
|
|
146
|
+
if args.user and password:
|
|
147
|
+
try:
|
|
148
|
+
bes_conn = besapi.besapi.BESConnection(args.user, password, rest_url)
|
|
149
|
+
except (
|
|
150
|
+
AttributeError,
|
|
151
|
+
ConnectionRefusedError,
|
|
152
|
+
besapi.besapi.requests.exceptions.ConnectionError,
|
|
153
|
+
):
|
|
154
|
+
logging.exception(
|
|
155
|
+
"connection to `%s` failed, attempting `%s` instead",
|
|
156
|
+
rest_url,
|
|
157
|
+
args.besserver,
|
|
158
|
+
)
|
|
159
|
+
try:
|
|
160
|
+
# print(args.besserver)
|
|
161
|
+
bes_conn = besapi.besapi.BESConnection(
|
|
162
|
+
args.user, password, args.besserver
|
|
163
|
+
)
|
|
164
|
+
# handle case where args.besserver is None
|
|
165
|
+
# AttributeError: 'NoneType' object has no attribute 'startswith'
|
|
166
|
+
except AttributeError:
|
|
167
|
+
logging.exception("----- ERROR: BigFix Connection Failed ------")
|
|
168
|
+
logging.exception(
|
|
169
|
+
"attempts to connect to BigFix using rest_url and besserver both failed"
|
|
170
|
+
)
|
|
171
|
+
return None
|
|
172
|
+
except BaseException as err:
|
|
173
|
+
# always log error and stop the current process
|
|
174
|
+
logging.exception("ERROR: %s", err)
|
|
175
|
+
logging.exception(
|
|
176
|
+
"----- ERROR: BigFix Connection Failed! Unknown reason ------"
|
|
177
|
+
)
|
|
178
|
+
return None
|
|
179
|
+
else:
|
|
180
|
+
logging.info(
|
|
181
|
+
"attempting connection to BigFix using config file method as user command arg was not provided"
|
|
182
|
+
)
|
|
183
|
+
bes_conn = besapi.besapi.get_bes_conn_using_config_file()
|
|
131
184
|
|
|
132
|
-
|
|
185
|
+
return bes_conn
|
|
@@ -25,6 +25,7 @@ if not args.test_pip:
|
|
|
25
25
|
sys.path.reverse()
|
|
26
26
|
|
|
27
27
|
import besapi
|
|
28
|
+
import besapi.plugin_utilities
|
|
28
29
|
|
|
29
30
|
print("besapi version: " + str(besapi.besapi.__version__))
|
|
30
31
|
|
|
@@ -151,4 +152,13 @@ if bigfix_cli.bes_conn:
|
|
|
151
152
|
bes_conn = besapi.besapi.get_bes_conn_using_config_file()
|
|
152
153
|
print("login succeeded:", bes_conn.login())
|
|
153
154
|
|
|
155
|
+
# test plugin_utilities:
|
|
156
|
+
print(besapi.plugin_utilities.get_invoke_folder())
|
|
157
|
+
print(besapi.plugin_utilities.get_invoke_file_name())
|
|
158
|
+
# the following doesn't seem to work in python 3.7:
|
|
159
|
+
# besapi.plugin_utilities.setup_plugin_logging(console=True)
|
|
160
|
+
parser = besapi.plugin_utilities.setup_plugin_argparse(plugin_args_required=False)
|
|
161
|
+
# allow unknown args to be parsed instead of throwing an error:
|
|
162
|
+
args, _unknown = parser.parse_known_args()
|
|
163
|
+
|
|
154
164
|
sys.exit(0)
|
|
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
|