From: Simo Sorce Date: Fri, 18 Apr 2014 04:16:12 +0000 (-0400) Subject: Move templatized file creation to tools X-Git-Tag: v0.2.2~13 X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fipsilon.git;a=commitdiff_plain;h=47ff8363b7961188084f05c55558a166b06decb4 Move templatized file creation to tools Signed-off-by: Simo Sorce --- diff --git a/ipsilon/install/ipsilon-client-install b/ipsilon/install/ipsilon-client-install index f49e351..b9cc4b6 100755 --- a/ipsilon/install/ipsilon-client-install +++ b/ipsilon/install/ipsilon-client-install @@ -21,7 +21,7 @@ from ipsilon.tools.saml2metadata import Metadata from ipsilon.tools.saml2metadata import SAML2_NAMEID_MAP from ipsilon.tools.saml2metadata import SAML2_SERVICE_MAP from ipsilon.tools.certs import Certificate -from string import Template +from ipsilon.tools import files import argparse import logging import os @@ -118,20 +118,15 @@ def saml2(): # default location, enable the default page psp = '' - with open(SAML2_TEMPLATE) as f: - template = f.read() - t = Template(template) - hunk = t.substitute(saml_base=args['saml_base'], - saml_protect=saml_protect, - saml_sp_key=c.key, - saml_sp_cert=c.cert, - saml_sp_meta=sp_metafile, - saml_idp_meta=idp_metafile, - saml_sp=args['saml_sp'], - saml_auth=saml_auth, sp=psp) - - with open(SAML2_CONFFILE, 'w+') as f: - f.write(hunk) + samlopts = {'saml_base': args['saml_base'], + 'saml_protect': saml_protect, + 'saml_sp_key': c.key, + 'saml_sp_cert': c.cert, + 'saml_sp_meta': sp_metafile, + 'saml_idp_meta': idp_metafile, + 'saml_sp': args['saml_sp'], + 'saml_auth': saml_auth, sp=psp} + files.write_from_template(SAML2_CONFFILE, SAML2_TEMPLATE, samlopts) files.fix_user_dirs(SAML2_HTTPDIR, args['httpd_user']) diff --git a/ipsilon/tools/files.py b/ipsilon/tools/files.py index 7f3bf7f..a18384c 100755 --- a/ipsilon/tools/files.py +++ b/ipsilon/tools/files.py @@ -19,6 +19,7 @@ import os import pwd +from string import Template def fix_user_dirs(path, user=None, mode=0700): @@ -35,3 +36,11 @@ def fix_user_dirs(path, user=None, mode=0700): if pw: os.chown(root, pw.pw_uid, pw.pw_gid) os.chmod(root, mode) + + +def write_from_template(destfile, template, opts): + with open(template) as f: + t = Template(f.read()) + text = t.substitute(**opts) # pylint: disable=star-args + with open(destfile, 'w+') as f: + f.write(text)