Commit 08b53cb3 authored by Łukasz Nowak's avatar Łukasz Nowak

Use slapos.cfg file instead of other arguments.

parent bc328ce0
...@@ -17,6 +17,7 @@ import argparse ...@@ -17,6 +17,7 @@ import argparse
import os import os
import subprocess import subprocess
import sys import sys
import ConfigParser
def generateCertificate(certificate_file, key_file, common_name): def generateCertificate(certificate_file, key_file, common_name):
...@@ -27,6 +28,8 @@ def generateCertificate(certificate_file, key_file, common_name): ...@@ -27,6 +28,8 @@ def generateCertificate(certificate_file, key_file, common_name):
raise ValueError("Key %r exists, will not overwrite." % raise ValueError("Key %r exists, will not overwrite." %
key_file) key_file)
print 'Generating certificate for %r (key: %r, certficate: %r)' % (
common_name, key_file, certificate_file)
subj = '/CN=%s' % common_name subj = '/CN=%s' % common_name
subprocess.check_call(["openssl", "req", "-x509", "-nodes", "-days", "365", subprocess.check_call(["openssl", "req", "-x509", "-nodes", "-days", "365",
"-subj", subj, "-newkey", "rsa:1024", "-keyout", key_file, "-out", "-subj", subj, "-newkey", "rsa:1024", "-keyout", key_file, "-out",
...@@ -35,13 +38,12 @@ def generateCertificate(certificate_file, key_file, common_name): ...@@ -35,13 +38,12 @@ def generateCertificate(certificate_file, key_file, common_name):
def run(*args): def run(*args):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('certificate_file', type=str, parser.add_argument('slapos_config', type=argparse.FileType('r'),
help='Certificate file to generate.') help='SlapOS configuration file.')
parser.add_argument('key_file', type=str,
help='Key file to generate.')
parser.add_argument('common_name', type=str, help="Common Name")
config = ConfigParser.SafeConfigParser()
option = parser.parse_args(list(args) or sys.argv[1:]) option = parser.parse_args(list(args) or sys.argv[1:])
generateCertificate(option.certificate_file, config.readfp(option.slapos_config)
option.key_file, option.common_name) generateCertificate(config.get('networkcache', 'signature_certificate_file'),
config.get('networkcache', 'signature_private_key_file'),
config.get('slapos', 'computer_id'))
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