Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ This is a framework design, all web queries get built and passed up the framewor
Any GET web request will occur in the haloget.py
Any POST web requests will occur in the halopost.py

Parameters should specifically match the API parameters of Halo itself
Parameters should specifically match the API parameters of Halo itself

Token will refresh automatically after expiry time using the ClientID/ClientSecret as documented.

### Supported Endpoints

The module currently implements helper functions for several common Halo API endpoints:

- **GET**: `getclients`, `getusers`, `getagents`, `getassets`, `gettickets`
- **POST (SET)**: `setclients`, `setusers`, `settickets`

### Adding new endpoints

#### GET endpoints
Expand Down
10 changes: 7 additions & 3 deletions connecthaloapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ def halowebrequest(method,urlpath,postbody=None):
print(haloResponse.text)

def haloget(resource, query=None):
if isinstance(query,dict):
query = '&'.join(f'{key}={value}' for key, value in query.items())
if isinstance(query, dict) and query:
query = '&'.join(
f"{key}={'true' if value is True else 'false' if value is False else value}"
for key, value in query.items()
if value is not None
)
ApiCall = resource + '?' + query
else:
ApiCall = resource
return halowebrequest('GET',ApiCall)
return halowebrequest('GET', ApiCall)

def halopost(resource,data):
if not isinstance(data,list):
Expand Down
16 changes: 16 additions & 0 deletions haloget.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,20 @@ def gettickets(id=None,showallobjects=None,search=None):
if search: parametersDict['search'] = search
# return results
return haloget(resource,parametersDict)

def getagents(id=None, me=False, **kwargs):
parametersDict = {k: v for k, v in kwargs.items() if v is not None}
resource = '/api/agent'
if id:
resource = f'{resource}/{id}'
elif me:
resource = f'{resource}/me'
return haloget(resource, parametersDict)

def getassets(id=None, **kwargs):
parametersDict = {k: v for k, v in kwargs.items() if v is not None}
resource = '/api/asset'
if id:
resource = f'{resource}/{id}'
return haloget(resource, parametersDict)

22 changes: 21 additions & 1 deletion halopost.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,32 @@ def setclients(client):
resource = '/api/client'
postBody = client
for listItem in postBody:
if not listItem['id']:
if not listItem.get('id'):
print('Client ID must be specified when updating a client')
return False
else:
return halopost(resource,postBody)

def setusers(user):
resource = '/api/users'
postBody = user
for listItem in postBody:
if not listItem.get('id'):
print('User ID must be specified when updating a user')
return False
else:
return halopost(resource, postBody)

def settickets(ticket):
resource = '/api/tickets'
postBody = ticket
for listItem in postBody:
if not listItem.get('id'):
print('Ticket ID must be specified when updating a ticket')
return False
else:
return halopost(resource, postBody)




4 changes: 2 additions & 2 deletions pyhaloapi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from connecthaloapi import connect
from haloget import getclients, gettickets, getusers
from halopost import setclients
from haloget import getclients, gettickets, getusers, getagents, getassets
from halopost import setclients, setusers, settickets