glpi-api 0.5.0__py3-none-any.whl → 0.7.0__py3-none-any.whl
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.
- {glpi_api-0.5.0.dist-info → glpi_api-0.7.0.dist-info}/METADATA +11 -2
- glpi_api-0.7.0.dist-info/RECORD +6 -0
- {glpi_api-0.5.0.dist-info → glpi_api-0.7.0.dist-info}/WHEEL +1 -1
- glpi_api.py +23 -17
- glpi_api-0.5.0.dist-info/RECORD +0 -6
- {glpi_api-0.5.0.dist-info → glpi_api-0.7.0.dist-info}/LICENSE +0 -0
- {glpi_api-0.5.0.dist-info → glpi_api-0.7.0.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.2
|
2
2
|
Name: glpi-api
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.7.0
|
4
4
|
Summary: Wrap calls to GLPI REST API.
|
5
5
|
Home-page: https://github.com/unistra/python-glpi-api
|
6
6
|
Author: François Ménabé
|
@@ -12,6 +12,15 @@ Classifier: Development Status :: 5 - Production/Stable
|
|
12
12
|
Classifier: Programming Language :: Python :: 3
|
13
13
|
License-File: LICENSE
|
14
14
|
Requires-Dist: requests
|
15
|
+
Dynamic: author
|
16
|
+
Dynamic: author-email
|
17
|
+
Dynamic: classifier
|
18
|
+
Dynamic: description
|
19
|
+
Dynamic: home-page
|
20
|
+
Dynamic: keywords
|
21
|
+
Dynamic: license
|
22
|
+
Dynamic: requires-dist
|
23
|
+
Dynamic: summary
|
15
24
|
|
16
25
|
********
|
17
26
|
glpi-api
|
@@ -0,0 +1,6 @@
|
|
1
|
+
glpi_api.py,sha256=TR4bfSklkoRAvjqvYttYDj9vBR9ZrvyZALc6ozq5rwY,36738
|
2
|
+
glpi_api-0.7.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
3
|
+
glpi_api-0.7.0.dist-info/METADATA,sha256=1E-nF1eqvqX50A57_D0jY1nFbqq7kwx2u_UkQr0W1Gs,833
|
4
|
+
glpi_api-0.7.0.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
5
|
+
glpi_api-0.7.0.dist-info/top_level.txt,sha256=YOkX5fKd6VWRx_-iMUfVJN15Xobw1VQ-mUF8HKWK2l0,9
|
6
|
+
glpi_api-0.7.0.dist-info/RECORD,,
|
glpi_api.py
CHANGED
@@ -33,7 +33,7 @@ class GLPIError(Exception):
|
|
33
33
|
"""Exception raised by this module."""
|
34
34
|
|
35
35
|
@contextmanager
|
36
|
-
def connect(url, apptoken, auth, verify_certs=True, use_headers=True):
|
36
|
+
def connect(url, apptoken, auth, verify_certs=True, use_headers=True, user_agent=None):
|
37
37
|
"""Context manager that authenticate to GLPI when enter and kill application
|
38
38
|
session in GLPI when leaving:
|
39
39
|
|
@@ -127,7 +127,8 @@ class GLPI:
|
|
127
127
|
SSL certificates and passing authentication parameters as GET parameters
|
128
128
|
(instead of headers).
|
129
129
|
"""
|
130
|
-
def __init__(self, url, apptoken, auth, verify_certs=True, use_headers=True
|
130
|
+
def __init__(self, url, apptoken, auth, verify_certs=True, use_headers=True,
|
131
|
+
user_agent=None):
|
131
132
|
"""Connect to GLPI and retrieve session token which is put in a
|
132
133
|
``requests`` session as attribute.
|
133
134
|
"""
|
@@ -141,14 +142,18 @@ class GLPI:
|
|
141
142
|
self.session.verify = False
|
142
143
|
|
143
144
|
# Connect and retrieve token.
|
144
|
-
session_token = self._init_session(apptoken, auth,
|
145
|
+
session_token = self._init_session(apptoken, auth, user_agent,
|
146
|
+
use_headers=use_headers)
|
145
147
|
|
146
148
|
# Set required headers.
|
147
|
-
|
149
|
+
headers = {
|
148
150
|
'Content-Type': 'application/json',
|
149
151
|
'Session-Token': session_token,
|
150
152
|
'App-Token': apptoken
|
151
153
|
}
|
154
|
+
if user_agent:
|
155
|
+
headers['User-Agent'] = user_agent
|
156
|
+
self.session.headers = headers
|
152
157
|
|
153
158
|
# Use for caching field id/uid map.
|
154
159
|
self._fields = {}
|
@@ -158,7 +163,7 @@ class GLPI:
|
|
158
163
|
return '/'.join(str(part) for part in [self.url.strip('/'), *endpoints])
|
159
164
|
|
160
165
|
@_catch_errors
|
161
|
-
def _init_session(self, apptoken, auth, use_headers=True):
|
166
|
+
def _init_session(self, apptoken, auth, user_agent, use_headers=True):
|
162
167
|
"""API documentation
|
163
168
|
<https://github.com/glpi-project/glpi/blob/master/apirest.md#init-session>`__
|
164
169
|
|
@@ -170,6 +175,8 @@ class GLPI:
|
|
170
175
|
'Content-Type': 'application/json',
|
171
176
|
'App-Token': apptoken
|
172
177
|
}
|
178
|
+
if user_agent:
|
179
|
+
init_headers['User-Agent'] = user_agent
|
173
180
|
params = {}
|
174
181
|
|
175
182
|
if isinstance(auth, (list, tuple)):
|
@@ -507,7 +514,7 @@ class GLPI:
|
|
507
514
|
}.get(response.status_code, _unknown_error)(response)
|
508
515
|
|
509
516
|
@_catch_errors
|
510
|
-
def get_multiple_items(self, *items):
|
517
|
+
def get_multiple_items(self, *items, **kwargs):
|
511
518
|
"""`API documentation
|
512
519
|
<https://github.com/glpi-project/glpi/blob/master/apirest.md#get-multiple-items>`__
|
513
520
|
|
@@ -531,8 +538,10 @@ class GLPI:
|
|
531
538
|
for idx, item in enumerate(items)
|
532
539
|
for key, value in item.items()}
|
533
540
|
|
541
|
+
params = _convert_bools(kwargs)
|
542
|
+
params.update(format_items(items))
|
534
543
|
response = self.session.get(self._set_method('getMultipleItems'),
|
535
|
-
params=
|
544
|
+
params=params)
|
536
545
|
return {
|
537
546
|
200: lambda r: r.json(),
|
538
547
|
400: _glpi_error,
|
@@ -728,7 +737,7 @@ class GLPI:
|
|
728
737
|
400: _glpi_error,
|
729
738
|
401: _glpi_error
|
730
739
|
}.get(response.status_code, _unknown_error)(response)
|
731
|
-
|
740
|
+
|
732
741
|
@_catch_errors
|
733
742
|
def add_sub_items(self, itemtype, item_id, sub_itemtype, *items):
|
734
743
|
"""`API documentation
|
@@ -783,11 +792,11 @@ class GLPI:
|
|
783
792
|
400: _glpi_error,
|
784
793
|
401: _glpi_error
|
785
794
|
}.get(response.status_code, _unknown_error)(response)
|
786
|
-
|
795
|
+
|
787
796
|
@_catch_errors
|
788
797
|
def update_sub_items(self, itemtype, item_id, sub_itemtype, *items):
|
789
798
|
"""`API documentation
|
790
|
-
Same method used as get-sub-items, same parameters
|
799
|
+
Same method used as get-sub-items, same parameters
|
791
800
|
<https://github.com/glpi-project/glpi/blob/master/apirest.md#get-sub-items>`__
|
792
801
|
|
793
802
|
Updates a collection of rows of the ``sub_itemtype`` for the identified
|
@@ -843,11 +852,11 @@ class GLPI:
|
|
843
852
|
400: lambda r: _glpi_error(r) if r.json()[0] != 'ERROR_GLPI_DELETE' else r.json()[1],
|
844
853
|
401: _glpi_error
|
845
854
|
}.get(response.status_code, _unknown_error)(response)
|
846
|
-
|
855
|
+
|
847
856
|
@_catch_errors
|
848
857
|
def delete_sub_items(self, itemtype, item_id, sub_itemtype, *items):
|
849
858
|
"""`API documentation
|
850
|
-
Same method used as get-sub-items, same parameters
|
859
|
+
Same method used as get-sub-items, same parameters
|
851
860
|
<https://github.com/glpi-project/glpi/blob/master/apirest.md#get-sub-items>`__
|
852
861
|
|
853
862
|
deletes a collection of rows of the ``sub_itemtype`` for the identified
|
@@ -895,12 +904,9 @@ class GLPI:
|
|
895
904
|
be deleted for some reasons) and purge the created but incomplete document.
|
896
905
|
"""
|
897
906
|
with open(filepath, 'rb') as fhandler:
|
898
|
-
response =
|
907
|
+
response = self.session.post(
|
899
908
|
url=self._set_method('Document'),
|
900
|
-
headers={
|
901
|
-
'Session-Token': self.session.headers['Session-Token'],
|
902
|
-
'App-Token': self.session.headers['App-Token']
|
903
|
-
},
|
909
|
+
headers={'Content-Type': None},
|
904
910
|
files={
|
905
911
|
'uploadManifest': (
|
906
912
|
None,
|
glpi_api-0.5.0.dist-info/RECORD
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
glpi_api.py,sha256=5VhHjOPxBnobuGpTjFEeQwcnlaAL7QmemR74EYEXN10,36519
|
2
|
-
glpi_api-0.5.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
3
|
-
glpi_api-0.5.0.dist-info/METADATA,sha256=OBZNx2L3e9MEb6S36g6zkrbqaZCCbRSPh6CIPmhKgNo,660
|
4
|
-
glpi_api-0.5.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
5
|
-
glpi_api-0.5.0.dist-info/top_level.txt,sha256=YOkX5fKd6VWRx_-iMUfVJN15Xobw1VQ-mUF8HKWK2l0,9
|
6
|
-
glpi_api-0.5.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|