This instance will be upgraded to Heptapod 0.31.0rc on 2022-05-19 at 11:00 UTC+2 (a few minutes of down time)

Commit d5e055d5 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Project: new api_request() method

Amazingly, the `owner_api_request()` shortcut was all we needed
for a long time, but we'll now will need to be able to pass the
user explicitely.
parent a2feeb18f2de
...@@ -97,8 +97,8 @@ class Project(object): ...@@ -97,8 +97,8 @@ class Project(object):
def owner_api_hg_heptapod_config(self): def owner_api_hg_heptapod_config(self):
return self.owner_api_get(subpath='hg_heptapod_config') return self.owner_api_get(subpath='hg_heptapod_config')
def owner_api_request(self, method, subpath='', **kwargs): def api_request(self, method, user, subpath='', **kwargs):
"""Perform a simple API HTTP request as the owner. """Perform a simple API HTTP request as the given user.
`method` is the HTTP method to use, same as in `requests.request`. `method` is the HTTP method to use, same as in `requests.request`.
...@@ -110,37 +110,44 @@ class Project(object): ...@@ -110,37 +110,44 @@ class Project(object):
All kwargs are passed to `requests.request()` All kwargs are passed to `requests.request()`
""" """
headers = kwargs.pop('headers', {}) headers = kwargs.pop('headers', {})
headers['Private-Token'] = self.owner_token headers['Private-Token'] = user.token
return requests.request(method, return requests.request(method,
'/'.join((self.api_url, subpath)), '/'.join((self.api_url, subpath)),
headers=headers, headers=headers,
**kwargs) **kwargs)
def owner_api_request(self, method, *args, **kwargs):
"""Perform a simple API HTTP request as the owner.
See :meth:`api_request` for more details.
"""
return self.api_request(method, self.owner_user, *args, **kwargs)
def owner_api_get(self, **kwargs): def owner_api_get(self, **kwargs):
"""Perform a simple HTTP API GET as the owner. """Perform a simple HTTP API GET as the owner.
See `owner_api_request` for details. See :meth:`api_request` for details.
""" """
return self.owner_api_request('GET', **kwargs) return self.owner_api_request('GET', **kwargs)
def owner_api_put(self, **kwargs): def owner_api_put(self, **kwargs):
"""Perform a simple HTTP API PUT as the owner. """Perform a simple HTTP API PUT as the owner.
See `owner_api_request` for details. See :meth:`api_request` for details.
""" """
return self.owner_api_request('PUT', **kwargs) return self.owner_api_request('PUT', **kwargs)
def owner_api_post(self, **kwargs): def owner_api_post(self, **kwargs):
"""Perform a simple HTTP API POST as the owner. """Perform a simple HTTP API POST as the owner.
See `owner_api_request` for details. See :meth:`api_request` for details.
""" """
return self.owner_api_request('POST', **kwargs) return self.owner_api_request('POST', **kwargs)
def owner_api_delete(self, **kwargs): def owner_api_delete(self, **kwargs):
"""Perform a simple HTTP API DELETE as the owner. """Perform a simple HTTP API DELETE as the owner.
See `owner_api_request` for details. See :meth:`api_request` for details.
""" """
return self.owner_api_request('DELETE', **kwargs) return self.owner_api_request('DELETE', **kwargs)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment