MCPcopy Create free account
hub / github.com/Python3WebSpider/ProxyPool / decorator

Function decorator

proxypool/processors/server.py:24–36  ·  view source on GitHub ↗
(*args, **kwargs)

Source from the content-addressed store, hash-verified

22def 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected