Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #10 from numerai/servers
Browse files Browse the repository at this point in the history
Added a check for an API key.
  • Loading branch information
xanderdunn committed Apr 6, 2017
2 parents 45413bc + 727539d commit acecdd3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions server.py
Expand Up @@ -17,6 +17,7 @@
import concordance

PORT = os.environ.get("PORT", "5151")
API_KEY = os.environ.get("API_KEY", "h/52y/E7cm8Ih4F3cVdlBM4ZQxER+Apk6P0L7yR0lFU=")

originality_queue = Queue()
concordance_queue = Queue()
Expand All @@ -32,6 +33,14 @@ def queue_for_scoring():
user = request.forms.get("user")
submission_id = request.forms.get("submission_id")
competition_id = request.forms.get("competition_id")
api_key = request.forms.get("api_key")

if API_KEY is None:
logging.getLogger().critical("NO API KEY EXITING")
return
if api_key != API_KEY:
logging.getLogger().info("Recieved invalid post request with KEY {} submission id {}".format(api_key, submission_id))
return

logging.getLogger().info("Recieved request to score {} {}".format(user, submission_id))

Expand Down
4 changes: 3 additions & 1 deletion test_server.py
@@ -1,6 +1,7 @@
from database_manager import DatabaseManager
import requests
import datetime
import os


def fetch_competition(db):
Expand All @@ -13,11 +14,12 @@ def fetch_competition(db):

def test_server(db_manager, comp_id):
submissions = db_manager.get_everyone_elses_recent_submssions(comp_id, '')
api_key = os.environ.get("API_KEY", "h/52y/E7cm8Ih4F3cVdlBM4ZQxER+Apk6P0L7yR0lFU=")

for submission in submissions:
s_id = submission["submission_id"]
user = submission["username"]
requests.post("http://localhost:5151/", data={'user': user, 'submission_id': s_id, 'competition_id': comp_id})
requests.post("http://localhost:5151/", data={'user': user, 'submission_id': s_id, 'competition_id': comp_id, 'api_key':api_key})


def main():
Expand Down

0 comments on commit acecdd3

Please sign in to comment.