Commit 81a46850 authored by Marco Mariani's avatar Marco Mariani

node register: retain comments, reject non-ascii configuration templates

parent f3825592
......@@ -45,6 +45,7 @@ setup(name=name,
'zope.interface', # slap library implementes interfaces
] + additional_install_requires,
extra_requires={'docs': (
# -*- coding: utf-8 -*-
import ConfigParser
import getpass
import os
import shutil
......@@ -9,6 +8,7 @@ import sys
import tempfile
import subprocess
import iniparse
import requests
from slapos.cli.command import Command, must_be_root
......@@ -174,13 +174,21 @@ def save_former_config(conf):
shutil.move(former, saved)
def get_slapos_conf_example():
def get_slapos_conf_example(logger):
Get slapos.cfg.example and return its path
_, path = tempfile.mkstemp()
with open(path, 'wb') as fout:
req = requests.get('')
except UnicodeDecodeError:
# we have to reject the file because iniparse chokes on non-ascii,
# and similar packages (cfgparse, INITools etc) have issues with
# multiline values, like certificates, or do not retain comments (ConfigParser).
logger.critical('Cannot create configuration file (bad template).')
return path
......@@ -231,11 +239,10 @@ def slapconfig(conf):
# Put slapos configuration file
config_path = os.path.join(slap_conf_dir, 'slapos.cfg')'Creating slap configuration: %s', config_path)
# Get example configuration file
slapos_cfg_example = get_slapos_conf_example()
new_configp = ConfigParser.RawConfigParser()
slapos_cfg_example = get_slapos_conf_example(conf.logger)
new_configp = iniparse.RawConfigParser()
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