diff --git a/.travis.yml b/.travis.yml index 753bae3..73ca938 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,9 @@ services: before_install: - sudo mkdir -p /data/log - pip install requests - - echo "token" > token.txt script: - docker pull qduoj/judge_server - cp docker-compose.example.yml docker-compose.yml - docker-compose up -d - docker ps -a - - python tests/tests.py \ No newline at end of file + - python tests/tests.py diff --git a/docker-compose.example.yml b/docker-compose.example.yml index 2c1dad7..0d6d62b 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -18,9 +18,9 @@ services: - $PWD/tests/test_case:/test_case - /data/log:/log - $PWD/server:/code:ro - - $PWD/token.txt:/token.txt environment: - service_discovery_url=https://virusdefender.net/service.php - service_url=http://1.2.3.4:12358 + - token=YOUR_TOKEN_HERE ports: - "0.0.0.0:12358:8080" diff --git a/server/config.py b/server/config.py index 762c19e..828bd99 100644 --- a/server/config.py +++ b/server/config.py @@ -20,5 +20,3 @@ COMPILER_GROUP_GID = grp.getgrnam("compiler").gr_gid TEST_CASE_DIR = "/test_case" SPJ_SRC_DIR = "/spj" SPJ_EXE_DIR = "/spj" - -TOKEN_FILE_PATH = "/token.txt" diff --git a/server/service.py b/server/service.py index fcc40b8..7bb90d2 100644 --- a/server/service.py +++ b/server/service.py @@ -11,14 +11,14 @@ from utils import server_info, logger, token class JudgeService(object): def __init__(self): + # this container's ip and port, if these are not set, web server will think it's a linked container + self.service_url = os.environ.get("service_url") + # exists if docker link oj_web_server:oj_web_server self.service_discovery_host = os.environ.get("OJ_WEB_SERVER_PORT_8080_TCP_ADDR") self.service_discovery_port = os.environ.get("OJ_WEB_SERVER_PORT_8080_TCP_PORT") self.service_discovery_url = os.environ.get("service_discovery_url", "") - # this container's ip and port, if these are not set, web server will think it's a linked container - self.service_url = os.environ.get("service_url") - if not self.service_discovery_url: if not (self.service_discovery_host and self.service_discovery_port): raise JudgeServiceError("service discovery host or port not found") diff --git a/server/utils.py b/server/utils.py index c7574ff..bb89f2b 100644 --- a/server/utils.py +++ b/server/utils.py @@ -5,8 +5,8 @@ import psutil import socket import logging import hashlib +import os -from config import TOKEN_FILE_PATH from exception import JudgeClientError @@ -28,11 +28,11 @@ def server_info(): def get_token(): - try: - with open(TOKEN_FILE_PATH, "r") as f: - return f.read().strip() - except IOError: - raise JudgeClientError("token.txt not found") + token = os.environ.get("token") + if token: + return token + else: + raise JudgeClientError("ENV token not found") token = hashlib.sha256(get_token()).hexdigest() diff --git a/tests/tests.py b/tests/tests.py index fc6f7c8..b38824d 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -24,7 +24,7 @@ class JudgeServerClientForTokenHeaderTest(JudgeServerClient): class JudgeServerTest(unittest.TestCase): def setUp(self): - self.token = "token" + self.token = "YOUR_TOKEN_HERE" self.server_base_url = "http://127.0.0.1:12358" self.client = JudgeServerClient(token=self.token, server_base_url=self.server_base_url) @@ -44,4 +44,4 @@ class JudgeServerTest(unittest.TestCase): self.assertEqual(data["err"], "TokenVerificationFailed") if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() diff --git a/token.example.txt b/token.example.txt deleted file mode 100644 index b4e686e..0000000 --- a/token.example.txt +++ /dev/null @@ -1 +0,0 @@ -PLEASE_USE_YOUR_OWN_TOKEN \ No newline at end of file