From 4b6f760c48675e469cde90f54576f35bffdf6b96 Mon Sep 17 00:00:00 2001 From: a-ruskomaa <48881971+a-ruskomaa@users.noreply.github.com> Date: Sun, 7 Feb 2021 15:31:49 +0200 Subject: [PATCH] Use a static secret key when running on App Engine, otherwise generate a random key. --- main.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 87a31fe..9c27cda 100644 --- a/main.py +++ b/main.py @@ -12,18 +12,22 @@ from opencensus.trace.tracer import Tracer from opencensus.ext.flask.flask_middleware import FlaskMiddleware from opencensus.trace.samplers import ProbabilitySampler +app = Flask(__name__) -depl_env = os.getenv("DEPLOYMENT_ENVIRONMENT") - -if depl_env == 'production' or depl_env == 'staging': +if os.getenv('GAE_ENV', '').startswith('standard'): client = google.cloud.logging.Client() handler = CloudLoggingHandler(client) setup_logging(handler) logging.getLogger().setLevel(logging.DEBUG) -app = Flask(__name__) -app.config.from_pyfile('config/config.py') +if os.getenv('GAE_ENV', '').startswith('standard'): + logging.info("Loading app configuration from file") + app.config.from_pyfile('config/config.py') + +if not app.secret_key: + logging.info("Generating a random secret key") + app.secret_key = os.urandom(16) def main(): sde = StackdriverExporter( -- GitLab