使用token文件

This commit is contained in:
virusdefender 2016-10-29 16:02:44 +08:00
parent 32e0ab4516
commit 0dd7bc2ae5
6 changed files with 11 additions and 6 deletions

2
.gitignore vendored
View File

@ -68,3 +68,5 @@ docker-compose.yml
rsyncd.passwd
node_modules/
token.txt

View File

@ -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:

View File

@ -22,3 +22,4 @@ SPJ_SRC_DIR = "/spj"
SPJ_EXE_DIR = "/spj"
COUNTER_FILE_PATH = "/tmp/counter"
TOKEN_FILE_PATH = "/token.txt"

View File

@ -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

View File

@ -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()

0
token.example.txt Normal file
View File