Add yaml configuration
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Tyler Perkins 2023-03-19 18:45:16 -04:00
parent 6c8b9dfc45
commit d5687ad289
4 changed files with 26 additions and 10 deletions

7
src/config.py Normal file
View File

@ -0,0 +1,7 @@
# Load configuration file
#
import envyaml
import os
config = envyaml.EnvYAML(os.environ.get('CONFIG_PATH', 'config.yaml'))

6
src/config.yaml Normal file
View File

@ -0,0 +1,6 @@
s3:
url: s3.clortox.com
username: ${S3_USERNAME}
password: ${S3_PASSWORD}
tls: True
bucket: memes

View File

@ -2,6 +2,7 @@ aniso8601==9.0.1
attrs==22.2.0 attrs==22.2.0
certifi==2022.12.7 certifi==2022.12.7
click==8.1.3 click==8.1.3
envyaml==1.10.211231
Flask==2.2.3 Flask==2.2.3
flask-restx==1.0.6 flask-restx==1.0.6
fuzzywuzzy==0.18.0 fuzzywuzzy==0.18.0
@ -14,6 +15,7 @@ minio==7.1.13
pyrsistent==0.19.3 pyrsistent==0.19.3
python-Levenshtein==0.20.9 python-Levenshtein==0.20.9
pytz==2022.7.1 pytz==2022.7.1
PyYAML==6.0
rapidfuzz==2.13.7 rapidfuzz==2.13.7
urllib3==1.26.14 urllib3==1.26.14
Werkzeug==2.2.3 Werkzeug==2.2.3

View File

@ -5,6 +5,7 @@ from minio.commonconfig import Tags
from minio import Minio from minio import Minio
from minio.commonconfig import Tags from minio.commonconfig import Tags
from minio.error import S3Error from minio.error import S3Error
from config import config
from datetime import datetime from datetime import datetime
from functools import lru_cache from functools import lru_cache
@ -29,30 +30,30 @@ def getClient():
if gclient != None: if gclient != None:
return gclient return gclient
if "S3_URL" not in os.environ: if "url" not in config["s3"]:
raise Exception("S3_URL is not set!") raise Exception("S3_URL is not set!")
S3_URL = os.environ["S3_URL"] S3_URL = config["s3.url"]
logging.info("Using S3_URL : " + S3_URL ) logging.info("Using S3_URL : " + S3_URL )
if "S3_UN" not in os.environ: if "username" not in config["s3"]:
raise Exception("S3_UN is not set!") raise Exception("S3_UN is not set!")
S3_UN = os.environ["S3_UN"] S3_UN = config["s3.username"]
logging.info("Using S3_UN : " + S3_UN) logging.info("Using S3_UN : " + S3_UN)
if "S3_PW" not in os.environ: if "password" not in config["s3"]:
raise Exception("S3_PW is not set!") raise Exception("S3_PW is not set!")
S3_PW = os.environ["S3_PW"] S3_PW = config["s3.password"]
logging.info("Using S3_PW : " + S3_PW) logging.info("Using S3_PW : " + S3_PW)
if "S3_BUCKET" not in os.environ: if "bucket" not in config["s3"]:
raise Exception("S3_BUCKET is not set!") raise Exception("S3_BUCKET is not set!")
S3_BUCKET = os.environ["S3_BUCKET"] S3_BUCKET = config["s3.bucket"]
logging.info("Using S3_BUCKET : " + S3_BUCKET) logging.info("Using S3_BUCKET : " + S3_BUCKET)
# override defaults # override defaults
if "S3_TLS" in os.environ: if "tls" in config["s3"]:
S3_TLS = os.environ["S3_TLS"].lower() in ("yes", "true", "1", "t") S3_TLS = config["s3.tls"]
logging.info("Using S3_TLS : " + str(S3_TLS)) logging.info("Using S3_TLS : " + str(S3_TLS))
client = Minio(S3_URL, client = Minio(S3_URL,