(*args, **kwargs)
| 22 | def auth_required(func): |
| 23 | @functools.wraps(func) |
| 24 | def decorator(*args, **kwargs): |
| 25 | # conditional decorator, when setting API_KEY is set, otherwise just ignore this decorator |
| 26 | if API_KEY == "": |
| 27 | return func(*args, **kwargs) |
| 28 | if request.headers.get('API-KEY', None) is not None: |
| 29 | api_key = request.headers.get('API-KEY') |
| 30 | else: |
| 31 | return {"message": "Please provide an API key in header"}, 400 |
| 32 | # Check if API key is correct and valid |
| 33 | if request.method == "GET" and hmac.compare_digest(api_key, API_KEY): |
| 34 | return func(*args, **kwargs) |
| 35 | else: |
| 36 | return {"message": "The provided API key is not valid"}, 403 |
| 37 | |
| 38 | return decorator |
| 39 |
nothing calls this directly
no outgoing calls
no test coverage detected