Do not manually create json file. Use module instead.

Mother of god, why did I do that monstrosity?
parent 72aefdbf
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
# #
############################################################################## ##############################################################################
from slapos.recipe.librecipe import GenericBaseRecipe from slapos.recipe.librecipe import GenericBaseRecipe
import json
from json import loads as unjson from json import loads as unjson
class Recipe(GenericBaseRecipe): class Recipe(GenericBaseRecipe):
...@@ -70,14 +71,15 @@ class Recipe(GenericBaseRecipe): ...@@ -70,14 +71,15 @@ class Recipe(GenericBaseRecipe):
def _getProxyTableContent(self, rewrite_rule_list): def _getProxyTableContent(self, rewrite_rule_list):
"""Generate proxy table file content from rewrite rules list""" """Generate proxy table file content from rewrite rules list"""
proxy_table_content = '{' proxy_table = dict()
for rewrite_rule in rewrite_rule_list: for rewrite_rule in rewrite_rule_list:
rewrite_part = self.substituteTemplate( proxy_table[rewrite_rule['resource']] = {
self.getTemplateFilename('proxytable-resource-snippet.json.in'), 'port': rewrite_rule['port'],
rewrite_rule) 'host': rewrite_rule['host'],
proxy_table_content += "%s," % rewrite_part 'https': rewrite_rule['https'],
}
proxy_table_content += '}\n' proxy_table_content = json.dumps(proxy_table)
return proxy_table_content return proxy_table_content
def install(self): def install(self):
......
"/%(resource)s": {
"port": %(port)s,
"host": "%(host)s",
"https": %(https)s
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment