foo
This commit is contained in:
parent
44e4e4eb42
commit
39a4adab92
4 changed files with 27 additions and 6 deletions
|
|
@ -32,11 +32,25 @@ class AuthentikApi: # TODO: check if can be replaced with apispec generated api
|
|||
raise AuthentikError()
|
||||
|
||||
@staticmethod
|
||||
def __paginate(res: requests.Response): # TODO: test this
|
||||
def post(url, data=[]):
|
||||
try:
|
||||
res = requests.post(f"{AUTHENTIK_BASEURL}{url}", headers={
|
||||
"Authorization": f"Bearer {AuthentikApi.__token()}"}, data=data)
|
||||
AuthentikApi.__handleError(res)
|
||||
if ("pagination" in res.json()):
|
||||
return AuthentikApi.__paginate(res)
|
||||
return res.json()
|
||||
except AuthentikError as err:
|
||||
raise err
|
||||
except:
|
||||
raise AuthentikError()
|
||||
|
||||
@staticmethod
|
||||
def __paginate(res: requests.Response): # TODO: test this
|
||||
results = res.json()["results"]
|
||||
for page in range(1, res.json()["pagination"]["total_pages"]):
|
||||
res = requests.get(
|
||||
f"{res.request.url}", headers=res.request.headers, params={'page': page})
|
||||
AuthentikApi.__handleError(res)
|
||||
results.append(res.json()["results"])
|
||||
return results
|
||||
return results
|
||||
|
|
|
|||
Reference in a new issue