From 0dd7bc2ae59952d2a0e8f3111f781c973a513f77 Mon Sep 17 00:00:00 2001 From: virusdefender Date: Sat, 29 Oct 2016 16:02:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8token=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ docker-compose.example.yml | 2 +- server/config.py | 1 + server/run.sh | 1 + server/utils.py | 11 ++++++----- token.example.txt | 0 6 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 token.example.txt diff --git a/.gitignore b/.gitignore index 942a17c..20a4137 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,5 @@ docker-compose.yml rsyncd.passwd node_modules/ + +token.txt diff --git a/docker-compose.example.yml b/docker-compose.example.yml index 37a3502..1e20ec6 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -19,8 +19,8 @@ services: - $PWD/tests/test_case:/test_case:ro - /data/log:/log - $PWD/server:/code:ro + - $PWD/token.txt:/token.txt environment: - - judger_token=token - service_discovery_url=https://virusdefender.net/service.php - service_url=http://1.2.3.4:12358 ports: diff --git a/server/config.py b/server/config.py index b1291d3..62e2509 100644 --- a/server/config.py +++ b/server/config.py @@ -22,3 +22,4 @@ SPJ_SRC_DIR = "/spj" SPJ_EXE_DIR = "/spj" COUNTER_FILE_PATH = "/tmp/counter" +TOKEN_FILE_PATH = "/token.txt" diff --git a/server/run.sh b/server/run.sh index fb6a82e..f57a3ef 100644 --- a/server/run.sh +++ b/server/run.sh @@ -3,4 +3,5 @@ chown compiler:compiler /spj echo 0 > /tmp/counter core=$(grep --count ^processor /proc/cpuinfo) n=$(($core*4)) +chmod 400 /token.txt /tmp/counter gunicorn --workers $n --threads $n --error-logfile /log/gunicorn.log --time 600 --bind 0.0.0.0:8080 server:wsgiapp \ No newline at end of file diff --git a/server/utils.py b/server/utils.py index 1b3cb8a..633b17a 100644 --- a/server/utils.py +++ b/server/utils.py @@ -8,7 +8,7 @@ import fcntl import hashlib import os -from config import COUNTER_FILE_PATH +from config import COUNTER_FILE_PATH, TOKEN_FILE_PATH from exception import JudgeClientError @@ -58,10 +58,11 @@ def server_info(): def get_token(): - token = os.environ.get("OJ_WEB_SERVER_ENV_judger_token") or os.environ.get("judger_token") - if not token: - raise JudgeClientError("judger_token not set") - return token + try: + with open(TOKEN_FILE_PATH, "r") as f: + return f.read() + except IOError: + raise JudgeClientError("token.txt not found") token = hashlib.sha256(get_token()).hexdigest() diff --git a/token.example.txt b/token.example.txt new file mode 100644 index 0000000..e69de29