Skip to content

Commit c0e4120

Browse files
committed
Added template check
1 parent a48215c commit c0e4120

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

app.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,20 @@ def validate(data):
331331
if (bool('version' in my or 'version' in defaults)
332332
!= bool('install' in my or 'install' in defaults)):
333333
raise ValueError("'version' and 'install' are both required")
334+
335+
# Check $-based substitutions
336+
config = my.get('config', defaults.get('config', ''))
337+
template = my.get('template', defaults.get('template', ''))
338+
try:
339+
with open(config) as infile:
340+
template += infile.read()
341+
except:
342+
pass
343+
subst = my.get('subst', defaults.get('subst', OrderedDict()))
344+
names = set(re.findall(r'\${?(\w+)}?', template))
345+
for name in names - set(subst.keys()):
346+
raise ValueError("'%s' not found in all 'subst' objects" % name)
347+
334348
else:
335349
if defaults:
336350
raise ValueError("Only one object without 'stack' is allowed")
@@ -345,8 +359,11 @@ def validate(data):
345359

346360
if 'base_url' in my:
347361
result = urlparse(my['base_url'])
348-
if result.scheme != 'http' or result.path != '/file/':
349-
raise ValueError("'base_url' format is 'http://change.me:8080/file/'")
362+
if not all((result.scheme, result.netloc)):
363+
raise ValueError("'base_url' is not valid")
364+
365+
if not result.path.endswith('/'):
366+
raise ValueError("'base_url' should end with /")
350367

351368
# Check local path existence only
352369
for key in ('install', 'config'):

0 commit comments

Comments
 (0)