From ea92ff82c98948ceea0755debdd0daa169e630bc Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Sun, 7 Aug 2022 21:53:18 +0800 Subject: [PATCH] feat: local env configure --- Basis/Constant.py | 23 +++++++++++++++++++++++ Dockerfile | 2 +- env.yaml | 10 ++++++++++ main.py | 2 +- 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 env.yaml diff --git a/Basis/Constant.py b/Basis/Constant.py index 72c3b55..9ffbc7f 100644 --- a/Basis/Constant.py +++ b/Basis/Constant.py @@ -1,6 +1,9 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +import os +import yaml + # Global Options Version = 'dev' @@ -17,6 +20,26 @@ TestHost = 'proxyc.net' TestSite = 'www.bing.com' PathEnv = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin' +# Load Env Options +yamlFile = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../env.yaml') +yamlContent = open(yamlFile, 'r', encoding = 'utf-8').read() +envOptions = yaml.load(yamlContent, Loader = yaml.FullLoader) +if 'version' in envOptions: + Version = envOptions['version'] +if 'loglevel' in envOptions: + LogLevel = envOptions['loglevel'] +if 'dir' in envOptions: + WorkDir = envOptions['dir'] +if 'dns' in envOptions: + DnsServer = envOptions['dns'] +if 'api' in envOptions: + if 'port' in envOptions['api']: + ApiPort = envOptions['api']['port'] + if 'path' in envOptions['api']: + ApiPath = envOptions['api']['path'] + if 'token' in envOptions['api']: + ApiToken = envOptions['api']['token'] + # Shadowsocks Info mbedtlsMethods = [ 'aes-128-cfb128', diff --git a/Dockerfile b/Dockerfile index 699f252..e3aa413 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ FROM ${PYTHON_IMG} AS wheels WORKDIR /wheels/ RUN apk add linux-headers COPY --from=build-base /apk/ /apk/ -RUN /apk/build-base && pip wheel colorlog flask IPy psutil pysocks requests salsa20 +RUN /apk/build-base && pip wheel colorlog flask IPy psutil pysocks pyyaml requests salsa20 COPY --from=gevent /wheels/*.whl /wheels/ COPY --from=numpy /wheels/*.whl /wheels/ diff --git a/env.yaml b/env.yaml new file mode 100644 index 0000000..7432cd0 --- /dev/null +++ b/env.yaml @@ -0,0 +1,10 @@ +version: 'v0.1' +loglevel: 'INFO' +dir: '/tmp/ProxyC' +dns: + - 223.5.5.5 + - 119.29.29.29 +api: + port: 17839 + path: '/v1' + token: 'dnomd343' diff --git a/main.py b/main.py index 4d5384e..80fc9fd 100755 --- a/main.py +++ b/main.py @@ -13,7 +13,7 @@ from Basis import Constant def mainArgParse(rawArgs: list) -> argparse.Namespace: mainParser = argparse.ArgumentParser(description = 'Start running API server') mainParser.add_argument('--log', type = str, default = Constant.LogLevel, help = 'output log level') - mainParser.add_argument('--dns', type = str, nargs = '+', help = 'specify dns server') + mainParser.add_argument('--dns', type = str, default = Constant.DnsServer, nargs = '+', help = 'specify dns server') mainParser.add_argument('--port', type = int, default = Constant.ApiPort, help = 'port for running') mainParser.add_argument('--path', type = str, default = Constant.ApiPath, help = 'root path for api server') mainParser.add_argument('--token', type = str, default = Constant.ApiToken, help = 'token for api server')