glpi-api 0.5.0__tar.gz → 0.6.0__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: glpi-api
3
- Version: 0.5.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é
@@ -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
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: glpi-api
3
- Version: 0.5.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é
@@ -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
@@ -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, use_headers=use_headers)
145
+ session_token = self._init_session(apptoken, auth, user_agent,
146
+ use_headers=use_headers)
145
147
 
146
148
  # Set required headers.
147
- self.session.headers = {
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)):
@@ -728,7 +735,7 @@ class GLPI:
728
735
  400: _glpi_error,
729
736
  401: _glpi_error
730
737
  }.get(response.status_code, _unknown_error)(response)
731
-
738
+
732
739
  @_catch_errors
733
740
  def add_sub_items(self, itemtype, item_id, sub_itemtype, *items):
734
741
  """`API documentation
@@ -783,11 +790,11 @@ class GLPI:
783
790
  400: _glpi_error,
784
791
  401: _glpi_error
785
792
  }.get(response.status_code, _unknown_error)(response)
786
-
793
+
787
794
  @_catch_errors
788
795
  def update_sub_items(self, itemtype, item_id, sub_itemtype, *items):
789
796
  """`API documentation
790
- Same method used as get-sub-items, same parameters
797
+ Same method used as get-sub-items, same parameters
791
798
  <https://github.com/glpi-project/glpi/blob/master/apirest.md#get-sub-items>`__
792
799
 
793
800
  Updates a collection of rows of the ``sub_itemtype`` for the identified
@@ -843,11 +850,11 @@ class GLPI:
843
850
  400: lambda r: _glpi_error(r) if r.json()[0] != 'ERROR_GLPI_DELETE' else r.json()[1],
844
851
  401: _glpi_error
845
852
  }.get(response.status_code, _unknown_error)(response)
846
-
853
+
847
854
  @_catch_errors
848
855
  def delete_sub_items(self, itemtype, item_id, sub_itemtype, *items):
849
856
  """`API documentation
850
- Same method used as get-sub-items, same parameters
857
+ Same method used as get-sub-items, same parameters
851
858
  <https://github.com/glpi-project/glpi/blob/master/apirest.md#get-sub-items>`__
852
859
 
853
860
  deletes a collection of rows of the ``sub_itemtype`` for the identified
@@ -4,7 +4,7 @@ from setuptools import setup
4
4
 
5
5
  setup(
6
6
  name='glpi-api',
7
- version='0.5.0',
7
+ version='0.6.0',
8
8
  author='François Ménabé',
9
9
  author_email='francois.menabe@gmail.fr',
10
10
  url='https://github.com/unistra/python-glpi-api',
File without changes
File without changes
File without changes