diff --git a/README.md b/README.md index e07cb8c..446877a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/connecthaloapi.py b/connecthaloapi.py index 7e124e6..0fd725f 100644 --- a/connecthaloapi.py +++ b/connecthaloapi.py @@ -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): diff --git a/haloget.py b/haloget.py index 5764628..2da5def 100644 --- a/haloget.py +++ b/haloget.py @@ -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) diff --git a/halopost.py b/halopost.py index c27aeb2..eeba807 100644 --- a/halopost.py +++ b/halopost.py @@ -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) + diff --git a/pyhaloapi.py b/pyhaloapi.py index 24353ef..058e877 100644 --- a/pyhaloapi.py +++ b/pyhaloapi.py @@ -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