glpi-api 0.4.0__py3-none-any.whl → 0.6.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.4.0.dist-info → glpi_api-0.6.0.dist-info}/METADATA +12 -3
- glpi_api-0.6.0.dist-info/RECORD +6 -0
- {glpi_api-0.4.0.dist-info → glpi_api-0.6.0.dist-info}/WHEEL +1 -1
- glpi_api.py +103 -5
- glpi_api-0.4.0.dist-info/RECORD +0 -6
- {glpi_api-0.4.0.dist-info → glpi_api-0.6.0.dist-info}/LICENSE +0 -0
- {glpi_api-0.4.0.dist-info → glpi_api-0.6.0.dist-info}/top_level.txt +0 -0
@@ -1,10 +1,10 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.2
|
2
2
|
Name: glpi-api
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.6.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é
|
7
|
-
Author-email: francois.menabe@
|
7
|
+
Author-email: francois.menabe@gmail.fr
|
8
8
|
License: GPLv3+
|
9
9
|
Keywords: rest,api,glpi
|
10
10
|
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
|
@@ -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=I2q6ISLNib_--WiRaqx1ASfvcnrDU8JBLHlut6IW7fY,36794
|
2
|
+
glpi_api-0.6.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
3
|
+
glpi_api-0.6.0.dist-info/METADATA,sha256=7wZFajZbtznfwvAQPz5wtNkYToHdSiR4fFNosp5E-gQ,833
|
4
|
+
glpi_api-0.6.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
5
|
+
glpi_api-0.6.0.dist-info/top_level.txt,sha256=YOkX5fKd6VWRx_-iMUfVJN15Xobw1VQ-mUF8HKWK2l0,9
|
6
|
+
glpi_api-0.6.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)):
|
@@ -729,6 +736,35 @@ class GLPI:
|
|
729
736
|
401: _glpi_error
|
730
737
|
}.get(response.status_code, _unknown_error)(response)
|
731
738
|
|
739
|
+
@_catch_errors
|
740
|
+
def add_sub_items(self, itemtype, item_id, sub_itemtype, *items):
|
741
|
+
"""`API documentation
|
742
|
+
Same method used as get-sub-items, same parameter
|
743
|
+
<https://github.com/glpi-project/glpi/blob/master/apirest.md#get-sub-items>`__
|
744
|
+
|
745
|
+
Add a collection of rows of the ``sub_itemtype`` for the identified
|
746
|
+
item of type ``itemtype`` and id ``item_id``. ``kwargs`` contains
|
747
|
+
additional parameters allowed by the API.
|
748
|
+
|
749
|
+
.. code::
|
750
|
+
|
751
|
+
# Add a operatingsystem of a computer.
|
752
|
+
>>> In [241]: glpi.add_sub_items('Computer',1,'Item_OperatingSystem',{'items_id': 1 ,'itemtype':'Computer','operatingsystems_id':1 })
|
753
|
+
[{'id': 261,
|
754
|
+
'itemtype': 'Computer',
|
755
|
+
'items_id': 1,
|
756
|
+
...
|
757
|
+
"""
|
758
|
+
url = self._set_method(itemtype, item_id, sub_itemtype)
|
759
|
+
response = self.session.post(url,
|
760
|
+
json={'input': items})
|
761
|
+
return {
|
762
|
+
201: lambda r: r.json(),
|
763
|
+
207: lambda r: r.json()[1],
|
764
|
+
400: _glpi_error,
|
765
|
+
401: _glpi_error
|
766
|
+
}.get(response.status_code, _unknown_error)(response)
|
767
|
+
|
732
768
|
@_catch_errors
|
733
769
|
def update(self, itemtype, *items):
|
734
770
|
"""`API documentation
|
@@ -749,11 +785,42 @@ class GLPI:
|
|
749
785
|
json={'input': items})
|
750
786
|
return {
|
751
787
|
200: lambda r: r.json(),
|
788
|
+
201: lambda r: r.json(),
|
752
789
|
207: lambda r: r.json()[1],
|
753
790
|
400: _glpi_error,
|
754
791
|
401: _glpi_error
|
755
792
|
}.get(response.status_code, _unknown_error)(response)
|
756
793
|
|
794
|
+
@_catch_errors
|
795
|
+
def update_sub_items(self, itemtype, item_id, sub_itemtype, *items):
|
796
|
+
"""`API documentation
|
797
|
+
Same method used as get-sub-items, same parameters
|
798
|
+
<https://github.com/glpi-project/glpi/blob/master/apirest.md#get-sub-items>`__
|
799
|
+
|
800
|
+
Updates a collection of rows of the ``sub_itemtype`` for the identified
|
801
|
+
item of type ``itemtype`` and id ``item_id``. ``kwargs`` contains
|
802
|
+
additional parameters allowed by the API.
|
803
|
+
|
804
|
+
.. code::
|
805
|
+
|
806
|
+
# update the operatingsystem a computer.
|
807
|
+
>>> In [241]: glpi.update_sub_items('Computer',1,'Item_OperatingSystem' {'id': 1 ,'itemtype':'Computer','operatingsystem_id':1 })
|
808
|
+
[{'id': 261,
|
809
|
+
'itemtype': 'Computer',
|
810
|
+
'items_id': 1,
|
811
|
+
...
|
812
|
+
"""
|
813
|
+
url = self._set_method(itemtype, item_id, sub_itemtype)
|
814
|
+
response = self.session.put(url,
|
815
|
+
json={'input': items})
|
816
|
+
return {
|
817
|
+
200: lambda r: r.json(),
|
818
|
+
201: lambda r: r.json(),
|
819
|
+
207: lambda r: r.json(),
|
820
|
+
400: _glpi_error,
|
821
|
+
401: _glpi_error
|
822
|
+
}.get(response.status_code, _unknown_error)(response)
|
823
|
+
|
757
824
|
@_catch_errors
|
758
825
|
def delete(self, itemtype, *items, **kwargs):
|
759
826
|
"""`API documentation <https://github.com
|
@@ -784,6 +851,37 @@ class GLPI:
|
|
784
851
|
401: _glpi_error
|
785
852
|
}.get(response.status_code, _unknown_error)(response)
|
786
853
|
|
854
|
+
@_catch_errors
|
855
|
+
def delete_sub_items(self, itemtype, item_id, sub_itemtype, *items):
|
856
|
+
"""`API documentation
|
857
|
+
Same method used as get-sub-items, same parameters
|
858
|
+
<https://github.com/glpi-project/glpi/blob/master/apirest.md#get-sub-items>`__
|
859
|
+
|
860
|
+
deletes a collection of rows of the ``sub_itemtype`` for the identified
|
861
|
+
item of type ``itemtype`` and id ``item_id``. ``kwargs`` contains
|
862
|
+
additional parameters allowed by the API.
|
863
|
+
|
864
|
+
.. code::
|
865
|
+
|
866
|
+
# delete the operatingsystem a computer.
|
867
|
+
>>> In [241]: glpi.delete_sub_items('Computer',1,'Item_OperatingSystem' {'id': 1 ,'itemtype':'Computer','operatingsystem_id':1 })
|
868
|
+
[{'id': 261,
|
869
|
+
'itemtype': 'Computer',
|
870
|
+
'items_id': 1,
|
871
|
+
...
|
872
|
+
"""
|
873
|
+
url = self._set_method(itemtype, item_id, sub_itemtype)
|
874
|
+
response = self.session.delete(url,
|
875
|
+
json={'input': items})
|
876
|
+
return {
|
877
|
+
200: lambda r: r.json(),
|
878
|
+
204: lambda r: r.json(),
|
879
|
+
207: lambda r: r.json()[1],
|
880
|
+
400: lambda r: _glpi_error(r) if r.json()[0] != 'ERROR_GLPI_DELETE' else r.json()[1],
|
881
|
+
401: _glpi_error
|
882
|
+
}.get(response.status_code, _unknown_error)(response)
|
883
|
+
|
884
|
+
|
787
885
|
@_catch_errors
|
788
886
|
def upload_document(self, name, filepath):
|
789
887
|
"""`API documentation
|
glpi_api-0.4.0.dist-info/RECORD
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
glpi_api.py,sha256=uVAwXRbXFF1rAH4DSppBS-wTorKQor7bjEDHbCLmcDg,32766
|
2
|
-
glpi_api-0.4.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
3
|
-
glpi_api-0.4.0.dist-info/METADATA,sha256=UmfIPEK9-3GWhUGqOdRDm86imuwe-4HTfJVwIyTooGY,662
|
4
|
-
glpi_api-0.4.0.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
5
|
-
glpi_api-0.4.0.dist-info/top_level.txt,sha256=YOkX5fKd6VWRx_-iMUfVJN15Xobw1VQ-mUF8HKWK2l0,9
|
6
|
-
glpi_api-0.4.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|