Skip to content

Commit

Permalink
Updated plugin
Browse files Browse the repository at this point in the history
Python 3 compatiblity
  • Loading branch information
jayp193 authored Sep 11, 2020
1 parent e5a9cdc commit ee2e873
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions httpapi_plugins/aruba_central.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python3
#!/usr/bin/python
'''
Ansible httpapi plugin to connect with Aruba Central
'''
Expand All @@ -25,9 +25,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


import requests
import json
import requests
from ansible.module_utils._text import to_text
from ansible.plugins.httpapi import HttpApiBase

Expand Down Expand Up @@ -62,12 +61,13 @@ def __init__(self, *args, **kwargs):
def login(self, username, password):
try:
access_token = self.get_option("access_token").decode("UTF-8")
except AttributeError:
access_token = self.get_option("access_token")
except Exception:
raise Exception("Missing access token! Please provide"
" ansible_httpapi_session_key in the inventory!")
self.access_token = access_token
self.connection._auth = {"Authorization": "Bearer " +
self.access_token}
self.connection._auth = {"Authorization": "Bearer " + self.access_token}

def send_file(self, path, method, filename):
if not self.connection._connected:
Expand Down Expand Up @@ -104,14 +104,18 @@ def send_request(self, data, headers, **message_kwargs):
path=path,
method=method)
try:
if "Accept" in headers and headers["Accept"] == "application/json":
if "Accept" in headers and headers["Accept"] == "multipart/form-data":
response_data = to_text(response_data.read())
elif "Content-Type" in headers and headers["Content-Type"] == "application/json":
response_data = json.loads(to_text(response_data.read()))
else:
response_data = response_data.read()

except ValueError:
response_data = response_data.read()
except AttributeError as arr:
raise Exception(str(response) + str(arr))
raise str(response) + str(arr)

return self.handle_response(response, response_data)

def handle_response(self, response, response_data):
Expand Down

0 comments on commit ee2e873

Please sign in to comment.