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)
|
logging.basicConfig(level=level)
|
||||||
|
|
||||||
config_path = environ.get("FEEDLEWARE_CONFIG")
|
config_path = environ.get("FEEDLEWARE_CONFIG")
|
||||||
|
config = {}
|
||||||
|
|
||||||
if not config_path:
|
if config_path:
|
||||||
print(
|
print(f"Reading config from {config_path}")
|
||||||
"Please set the FEEDLEWARE_CONFIG environment variable",
|
|
||||||
file=sys.stderr,
|
|
||||||
)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(config_path)
|
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
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
for section in config.sections():
|
for section in blueprints.keys():
|
||||||
if section in blueprints:
|
|
||||||
blueprint = blueprints[section].create_blueprint(config[section])
|
blueprint = blueprints[section].create_blueprint(config[section])
|
||||||
app.register_blueprint(blueprint, url_prefix="/" + section)
|
app.register_blueprint(blueprint, url_prefix="/" + section)
|
||||||
else:
|
|
||||||
logger.warning("Unknown service '%s'", section)
|
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue