Commit 8135944a authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

certificate-authority: Add ugly hack to ca request to use custom certificates instead

parent 37d067b6
...@@ -103,16 +103,27 @@ class Request(Recipe): ...@@ -103,16 +103,27 @@ class Request(Recipe):
key_file = self.options['key-file'] key_file = self.options['key-file']
cert_file = self.options['cert-file'] cert_file = self.options['cert-file']
key_content = self.options.get('key-content', None)
cert_content = self.options.get('cert-content', None)
request_needed = True
name = self.options['name'] name = self.options['name']
hash_ = hashlib.sha512(name).hexdigest() hash_ = hashlib.sha512(name).hexdigest()
key = os.path.join(self.ca_private, hash_ + self.ca_key_ext) key = os.path.join(self.ca_private, hash_ + self.ca_key_ext)
certificate = os.path.join(self.ca_certs, hash_ + self.ca_crt_ext) certificate = os.path.join(self.ca_certs, hash_ + self.ca_crt_ext)
parser = ConfigParser.RawConfigParser()
parser.add_section('certificate') # XXX Ugly hack to quickly provide custom certificate/key to everyone using the recipe
parser.set('certificate', 'name', name) if key_content and cert_content:
parser.set('certificate', 'key_file', key) open(key, 'w').write(key_content)
parser.set('certificate', 'certificate_file', certificate) open(certificate, 'w').write(cert_content)
parser.write(open(os.path.join(self.request_directory, hash_), 'w')) request_needed = False
else:
parser = ConfigParser.RawConfigParser()
parser.add_section('certificate')
parser.set('certificate', 'name', name)
parser.set('certificate', 'key_file', key)
parser.set('certificate', 'certificate_file', certificate)
parser.write(open(os.path.join(self.request_directory, hash_), 'w'))
for link in [key_file, cert_file]: for link in [key_file, cert_file]:
if os.path.islink(link): if os.path.islink(link):
...@@ -123,11 +134,14 @@ class Request(Recipe): ...@@ -123,11 +134,14 @@ class Request(Recipe):
os.symlink(key, key_file) os.symlink(key, key_file)
os.symlink(certificate, cert_file) os.symlink(certificate, cert_file)
wrapper = self.createPythonScript( path_list = [key_file, cert_file]
self.options['wrapper'], if request_needed:
'slapos.recipe.librecipe.execute.execute_wait', wrapper = self.createPythonScript(
[ [self.options['executable']], self.options['wrapper'],
[certificate, key] ], 'slapos.recipe.librecipe.execute.execute_wait',
) [ [self.options['executable']],
[certificate, key] ],
)
path_list.append(wrapper)
return [key_file, cert_file, wrapper] return path_list
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