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
# 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'])
import os
import pwd
+from string import Template
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)