Compare commits
4 Commits
acbd11369e
...
6f3434e8db
| Author | SHA1 | Date | |
|---|---|---|---|
| 6f3434e8db | |||
| 0155644b65 | |||
| 3d920fd5e5 | |||
| 660b8e8463 |
@@ -4,13 +4,15 @@ on: [push]
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Build:
|
Build:
|
||||||
runs-on: windows
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: python
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
uses: actions/checkout@main
|
uses: actions/checkout@main
|
||||||
- name: Building the package
|
- name: Building the package
|
||||||
run: |
|
run: |
|
||||||
powershell mv ${{ gitea.workspace }}\GLPIAPI.py ${{ gitea.workspace }}\build\src\GLPIAPI\
|
mv ${{ gitea.workspace }}\GLPIAPI.py ${{ gitea.workspace }}\build\src\GLPIAPI\
|
||||||
cd ${{ gitea.workspace }}\build
|
cd ${{ gitea.workspace }}\build
|
||||||
python -m build
|
python -m build
|
||||||
- name: Publish package
|
- name: Publish package
|
||||||
|
|||||||
56
GLPIAPI.py
56
GLPIAPI.py
@@ -102,7 +102,49 @@ class GLPIAPI:
|
|||||||
return itemID, search["data"], search["totalcount"]
|
return itemID, search["data"], search["totalcount"]
|
||||||
|
|
||||||
return None, None, 0
|
return None, None, 0
|
||||||
|
|
||||||
|
def GetItems(self, itemType, fieldName=None, fieldValue=None):
|
||||||
|
'''
|
||||||
|
Search for items of a specific item type in GLPI. A filter can be set using fieldName and fieldValue :
|
||||||
|
fieldName: must be the name of the field as visible in GLPI
|
||||||
|
fieldValue: a string
|
||||||
|
If only itemType is set, it will search for all items
|
||||||
|
|
||||||
|
Return a tuple with item id (in a list if there are more than 1), item data (in a list of dict items) and item count (int).
|
||||||
|
If the query does not succeed it will return a tuple with the http status code instead of item data (e.g. None, 400, 0).
|
||||||
|
'''
|
||||||
|
searchAll = False
|
||||||
|
if(fieldName != None and fieldValue != None):
|
||||||
|
fieldId = list(self.GetSearchOptions(itemType, fieldName))[0]
|
||||||
|
# Recherche en fonction de l'utilisateur de l'appareil
|
||||||
|
search_parameter = f'is_deleted=0&criteria[0][field]={fieldId}&withindexes=true&criteria[0][searchtype]=contains&criteria[0][value]=^{fieldValue}$'
|
||||||
|
else:
|
||||||
|
searchAll = True
|
||||||
|
|
||||||
|
if(searchAll):
|
||||||
|
searchUri = f"{self.Server}/apirest.php/search/{itemType}/?range=0-9999999&is_deleted=0"
|
||||||
|
else:
|
||||||
|
searchUri = f"{self.Server}/apirest.php/search/{itemType}?{search_parameter}"
|
||||||
|
|
||||||
|
search = requests.get(searchUri, headers=self.Headers)
|
||||||
|
|
||||||
|
if(search.status_code == 200):
|
||||||
|
search = search.json()
|
||||||
|
if(search["totalcount"] == 1):
|
||||||
|
itemID = list(search["data"].keys())[0]
|
||||||
|
data = search["data"][itemID]
|
||||||
|
|
||||||
|
return itemID, data, search["totalcount"]
|
||||||
|
elif(search["totalcount"] > 1):
|
||||||
|
if(searchAll):
|
||||||
|
idFieldNumber = list(self.GetSearchOptions(itemType, 'id'))[0]
|
||||||
|
itemID = [i[idFieldNumber] for i in search["data"]]
|
||||||
|
else:
|
||||||
|
itemID = list(search["data"].keys())
|
||||||
|
return itemID, search["data"], search["totalcount"]
|
||||||
|
|
||||||
|
return None, search.status, 0
|
||||||
|
|
||||||
def GetUsers(self, username=None, email=None):
|
def GetUsers(self, username=None, email=None):
|
||||||
'''
|
'''
|
||||||
Search for users in GLPI based on one of the possibles parameters :
|
Search for users in GLPI based on one of the possibles parameters :
|
||||||
@@ -141,7 +183,19 @@ class GLPIAPI:
|
|||||||
return userID, search["data"], search["totalcount"]
|
return userID, search["data"], search["totalcount"]
|
||||||
|
|
||||||
return None, None, 0
|
return None, None, 0
|
||||||
|
|
||||||
|
def GetSearchOptions(self, itemType, fieldName=None):
|
||||||
|
queryUri = f"{self.Server}/apirest.php/listSearchOptions/{itemType}"
|
||||||
|
searchOptions = requests.get(queryUri, headers=self.Headers)
|
||||||
|
if(searchOptions.status_code == 200):
|
||||||
|
searchOptions = searchOptions.json()
|
||||||
|
if(fieldName != None):
|
||||||
|
for k,v in searchOptions.items():
|
||||||
|
if(v['name'].lower() == fieldName.lower()):
|
||||||
|
return {k : searchOptions[k]}
|
||||||
|
return searchOptions
|
||||||
|
return searchOptions.status_code
|
||||||
|
|
||||||
def UploadFile(self, file, path):
|
def UploadFile(self, file, path):
|
||||||
manifest = {
|
manifest = {
|
||||||
"input": {
|
"input": {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "GLPIAPI"
|
name = "GLPIAPI"
|
||||||
version = "1.0.3"
|
version = "1.0.4"
|
||||||
description = "A module python to make it easier to use GLPI API"
|
description = "A module python to make it easier to use GLPI API"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
Reference in New Issue
Block a user