This repository was archived by the owner on Sep 12, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 13
13
from . import toolkit
14
14
from .lib import config
15
15
16
+ from .lib .core .exceptions import ConfigError
17
+
16
18
17
19
VERSION = '0.6.8'
18
20
app = flask .Flask ('docker-registry' )
@@ -46,7 +48,7 @@ def after_request(response):
46
48
def init ():
47
49
# Configure the secret key
48
50
if not cfg .secret_key :
49
- raise RuntimeError ( 'Config error: `secret_key\' is not set' )
51
+ raise ConfigError ( ' `secret_key\' is not set' )
50
52
app .secret_key = cfg .secret_key
51
53
# Configure the email exceptions
52
54
info = cfg .email_exceptions
Original file line number Diff line number Diff line change 3
3
import rsa
4
4
import yaml
5
5
6
+ from .core .exceptions import FileNotFoundError , ConfigError
7
+
6
8
7
9
class Config (object ):
8
10
@@ -56,15 +58,35 @@ def load():
56
58
if not os .path .isabs (config_path ):
57
59
config_path = os .path .join (os .path .dirname (__file__ ), '../../' ,
58
60
'config' , config_path )
59
- with open (config_path ) as f :
61
+ try :
62
+ f = open (config_path )
63
+ except :
64
+ raise FileNotFoundError (
65
+ 'Heads-up! File is missing: %s' % config_path )
66
+
67
+ try :
60
68
data = yaml .load (f )
69
+ except :
70
+ raise ConfigError (
71
+ 'Config file (%s) is not valid yaml' % config_path )
72
+
61
73
config = data .get ('common' , {})
62
74
flavor = os .environ .get ('SETTINGS_FLAVOR' , 'dev' )
63
75
config .update (data .get (flavor , {}))
64
76
config ['flavor' ] = flavor
65
77
config = convert_env_vars (config )
66
78
if 'privileged_key' in config :
67
- with open (config ['privileged_key' ]) as f :
79
+ try :
80
+ f = open (config ['privileged_key' ])
81
+ except :
82
+ raise FileNotFoundError (
83
+ 'Heads-up! File is missing: %s' % config ['privileged_key' ])
84
+
85
+ try :
68
86
config ['privileged_key' ] = rsa .PublicKey .load_pkcs1 (f .read ())
87
+ except :
88
+ raise ConfigError (
89
+ 'Key at %s is not a valid RSA key' % config ['privileged_key' ])
90
+
69
91
_config = Config (config )
70
92
return _config
You can’t perform that action at this time.
0 commit comments