mirror of
https://github.com/YunoHost/yunorunner.git
synced 2024-09-03 20:05:52 +02:00
[enh] make auth works
This commit is contained in:
parent
262034ac17
commit
2bda81c59f
2 changed files with 9 additions and 5 deletions
4
cli.py
4
cli.py
|
@ -39,6 +39,10 @@ def request_api(path, domain, verb, data):
|
||||||
json=data,
|
json=data,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if response.status_code == 403:
|
||||||
|
print(f"Error: access refused because '{response.json()['status']}'")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# TODO: real error message
|
# TODO: real error message
|
||||||
assert response.status_code == 200, response.content
|
assert response.status_code == 200, response.content
|
||||||
assert response.content == b"ok", response.content
|
assert response.content == b"ok", response.content
|
||||||
|
|
10
run.py
10
run.py
|
@ -333,11 +333,11 @@ def require_token():
|
||||||
# run some method that checks the request
|
# run some method that checks the request
|
||||||
# for the client's authorization status
|
# for the client's authorization status
|
||||||
if "X-Token" not in request.headers:
|
if "X-Token" not in request.headers:
|
||||||
return json({'status': 'you need to provide a token to access the API, please refer to the README'}, 403)
|
return response.json({'status': 'you need to provide a token to access the API, please refer to the README'}, 403)
|
||||||
|
|
||||||
if not os.path.exists("tokens"):
|
if not os.path.exists("tokens"):
|
||||||
api_logger.warning("No tokens available and a user is trying to access the API")
|
api_logger.warning("No tokens available and a user is trying to access the API")
|
||||||
return json({'status': 'invalide token'}, 403)
|
return response.json({'status': 'invalide token'}, 403)
|
||||||
|
|
||||||
async with aiofiles.open('tokens', mode='r') as f:
|
async with aiofiles.open('tokens', mode='r') as f:
|
||||||
tokens = await f.read()
|
tokens = await f.read()
|
||||||
|
@ -347,10 +347,10 @@ def require_token():
|
||||||
|
|
||||||
if token not in tokens:
|
if token not in tokens:
|
||||||
api_logger.warning(f"someone tried to access the API using the {token} but it's not a valid token in the 'tokens' file")
|
api_logger.warning(f"someone tried to access the API using the {token} but it's not a valid token in the 'tokens' file")
|
||||||
return json({'status': 'invalide token'}, 403)
|
return response.json({'status': 'invalide token'}, 403)
|
||||||
|
|
||||||
response = await f(request, *args, **kwargs)
|
result = await f(request, *args, **kwargs)
|
||||||
return response
|
return result
|
||||||
return decorated_function
|
return decorated_function
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue