besapi 3.3.2__tar.gz → 3.3.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: besapi
3
- Version: 3.3.2
3
+ Version: 3.3.3
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
@@ -29,7 +29,7 @@ import requests
29
29
  from lxml import etree, objectify
30
30
  from pkg_resources import resource_filename
31
31
 
32
- __version__ = "3.3.2"
32
+ __version__ = "3.3.3"
33
33
 
34
34
  besapi_logger = logging.getLogger("besapi")
35
35
 
@@ -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"""
@@ -120,13 +123,44 @@ def setup_plugin_logging(log_file_name="", verbose=0, console=True):
120
123
  )
121
124
 
122
125
 
123
- # if __name__ == "__main__":
124
- # print(get_invoke_folder())
125
- # print(get_invoke_file_name())
126
- # setup_plugin_logging(console=True)
127
- # logging.error("test logging")
128
- # parser = setup_plugin_argparse()
129
- # # allow unknown args to be parsed instead of throwing an error:
130
- # args, _unknown = parser.parse_known_args()
126
+ def get_besapi_connection(args):
127
+ """get connection to besapi using either args or config file if args not provided"""
128
+
129
+ password = args.password
130
+
131
+ # if user was provided as arg but password was not:
132
+ if args.user and not password:
133
+ logging.warning("Password was not provided, provide REST API password.")
134
+ print("Password was not provided, provide REST API password:")
135
+ password = getpass.getpass()
136
+
137
+ # process args, setup connection:
138
+ rest_url = args.rest_url
139
+
140
+ # normalize url to https://HostOrIP:52311
141
+ if rest_url and rest_url.endswith("/api"):
142
+ rest_url = rest_url.replace("/api", "")
143
+
144
+ # attempt bigfix connection with provided args:
145
+ if args.user and password:
146
+ try:
147
+ bes_conn = besapi.besapi.BESConnection(args.user, password, rest_url)
148
+ # bes_conn.login()
149
+ except (
150
+ AttributeError,
151
+ ConnectionRefusedError,
152
+ besapi.besapi.requests.exceptions.ConnectionError,
153
+ ):
154
+ try:
155
+ # print(args.besserver)
156
+ bes_conn = besapi.besapi.BESConnection(
157
+ args.user, password, args.besserver
158
+ )
159
+ # handle case where args.besserver is None
160
+ # AttributeError: 'NoneType' object has no attribute 'startswith'
161
+ except AttributeError:
162
+ bes_conn = besapi.besapi.get_bes_conn_using_config_file()
163
+ else:
164
+ bes_conn = besapi.besapi.get_bes_conn_using_config_file()
131
165
 
132
- # logging.error(args)
166
+ return bes_conn
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: besapi
3
- Version: 3.3.2
3
+ Version: 3.3.3
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
@@ -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