Commit 51530759 authored by Chris Hines's avatar Chris Hines
Browse files

add endpoints to enable ip detection

parent 381595e9
......@@ -22,6 +22,20 @@ class ShareGetAPI(Resource):
data = json.loads(sd.value)
return data
class ShareGetComponentAPI(Resource):
def get(self, component, key):
import json
logger = logging.getLogger()
logger.debug("get data for key {}".format(key))
try:
sd = ShareData.query.get(key)
except:
return {}
logger.debug(sd.value)
data = json.loads(sd.value)
return data[component]
class ShareStoreAPI(Resource):
......@@ -50,5 +64,15 @@ class ShareStoreAPI(Resource):
logger.debug(traceback.format_exc())
return key
class GetIP(Resource):
def get(self):
if not request.headers.getlist("X-Forwarded-For"):
ip = request.remote_addr
else:
ip = request.headers.getlist("X-Forwarded-For")[0]
return ip
api.add_resource(ShareStoreAPI, '/share/', endpoint='share_store_ep')
api.add_resource(ShareGetAPI, '/share/<key>', endpoint='share_get_ep')
api.add_resource(ShareGetComponentAPI, '/sharecomp/<component>/<key>', endpoint='share_get_component_ep')
api.add_resource(GetIP, '/getip/', endpoint='getip_ep')
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