Skip to content

Commit

Permalink
Merge pull request #195 from Mirantis/mandatorysecretkey
Browse files Browse the repository at this point in the history
Mandatory SECRET_KEY
  • Loading branch information
tomkukral authored Jan 11, 2018
2 parents 4f23e2e + 2d07a4b commit affc197
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion kqueen/config/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Config(BaseConfig):
LOG_LEVEL = 'DEBUG'

# App secret
SECRET_KEY = 'secret'
SECRET_KEY = 'SecretSecretSecret123'

# Jenkins engine settings
JENKINS_API_URL = 'https://ci.mcp.mirantis.net'
Expand Down
2 changes: 1 addition & 1 deletion kqueen/config/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Config(BaseConfig):
LOG_LEVEL = 'DEBUG'

# App secret
SECRET_KEY = 'secret'
SECRET_KEY = 'SecretSecretSecret123'

# Etcd settings
ETCD_PREFIX = '/kqueen_test'
Expand Down
3 changes: 3 additions & 0 deletions kqueen/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ImproperlyConfigured(Exception):
"""Kqueen is improperly configured"""
pass
6 changes: 6 additions & 0 deletions kqueen/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .blueprints.api.views import api
from .blueprints.metrics.views import metrics
from .config import current_config
from .exceptions import ImproperlyConfigured
from .middleware import setup_metrics
from .serializers import KqueenJSONEncoder
from .storages.etcd import EtcdBackend
Expand Down Expand Up @@ -38,6 +39,11 @@ def create_app(config_file=None):
# load configuration
config = current_config(config_file)
config.setup_policies()

secret_key = config.get('SECRET_KEY')
if not secret_key or len(secret_key) < 16:
raise ImproperlyConfigured('The SECRET_KEY must be set and longer than 16 chars.')

app.config.from_mapping(config.to_dict())
app.logger.setLevel(getattr(logging, app.config.get('LOG_LEVEL')))
app.logger.info('Loading configuration from {}'.format(config.source_file))
Expand Down

0 comments on commit affc197

Please sign in to comment.