init: Allow specifying secrets via env vars
This commit is contained in:
parent
05c5fa8fa8
commit
6589ecae13
|
|
@ -21,23 +21,38 @@ def create_app():
|
|||
logging.basicConfig(level=level)
|
||||
|
||||
config_path = environ.get("FEEDLEWARE_CONFIG")
|
||||
config = {}
|
||||
|
||||
if not config_path:
|
||||
print(
|
||||
"Please set the FEEDLEWARE_CONFIG environment variable",
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
if config_path:
|
||||
print(f"Reading config from {config_path}")
|
||||
config = configparser.ConfigParser()
|
||||
config.read(config_path)
|
||||
|
||||
if "twitch" not in config:
|
||||
config["twitch"] = {}
|
||||
|
||||
if (client_id := environ.get("FEEDLEWARE_TWITCH_CLIENT_ID")):
|
||||
config["twitch"]["client_id"] = client_id
|
||||
|
||||
if (secret := environ.get("FEEDLEWARE_TWITCH_SECRET")):
|
||||
config["twitch"]["secret"] = secret
|
||||
|
||||
if "youtube" not in config:
|
||||
config["youtube"] = {}
|
||||
|
||||
if (key := environ.get("FEEDLEWARE_YOUTUBE_KEY")):
|
||||
config["youtube"]["key"] = key
|
||||
|
||||
if "openalex" not in config:
|
||||
config["openalex"] = {}
|
||||
|
||||
if (email := environ.get("FEEDLEWARE_OPENALEX_EMAIL")):
|
||||
config["openalex"]["email"] = email
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read(config_path)
|
||||
app = Flask(__name__)
|
||||
|
||||
for section in config.sections():
|
||||
if section in blueprints:
|
||||
blueprint = blueprints[section].create_blueprint(config[section])
|
||||
app.register_blueprint(blueprint, url_prefix="/" + section)
|
||||
else:
|
||||
logger.warning("Unknown service '%s'", section)
|
||||
for section in blueprints.keys():
|
||||
blueprint = blueprints[section].create_blueprint(config[section])
|
||||
app.register_blueprint(blueprint, url_prefix="/" + section)
|
||||
|
||||
return app
|
||||
|
|
|
|||
Loading…
Reference in New Issue