From 3e7f65a934a07bc7bd4fd558a6caad4418197879 Mon Sep 17 00:00:00 2001 From: Dick Marinus Date: Thu, 13 Oct 2016 20:15:57 +0200 Subject: [PATCH 1/2] Make it possible for IOPlugins to use arguments --- simp_le.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/simp_le.py b/simp_le.py index b28e1de..18355ff 100755 --- a/simp_le.py +++ b/simp_le.py @@ -304,6 +304,23 @@ class IOPlugin(object): def __init__(self, path, **dummy_kwargs): self.path = path + self.arguments_dest = [] + self.script_name = None + if 'arguments' in dummy_kwargs: + self.arguments = dummy_kwargs['arguments'] + else: + self.arguments = None + + def add_arguments(self, manager): + if self.arguments: + for argument in self.arguments: + storeAction = manager.add_argument(*argument[0], **argument[1]) + self.arguments_dest.append(storeAction.dest) + + def set_arguments(self, args): + vargs = vars(args) + for dest in self.arguments_dest: + setattr(self, dest, vargs[dest]) @abc.abstractmethod def persisted(self): @@ -864,6 +881,9 @@ def create_parser(): 'is necessary to cover all components: key, certificate, chain. ' 'Allowed values: %s.' % ', '.join(sorted(IOPlugin.registered)), ) + for plugin_name in IOPlugin.registered: + IOPlugin.registered[plugin_name].add_arguments(io_group) + io_group.add_argument( '--cert_key_size', type=int, default=4096, metavar='BITS', help='Certificate key size. Fresh key is created for each renewal.', @@ -1121,6 +1141,10 @@ def check_plugins_persist_all(ioplugins): raise Error('Selected IO plugins do not cover the following ' 'components: %s.' % ', '.join(not_persisted)) +def set_plugins_arguments(ioplugins, args): + """Set arguments for plugin""" + for plugin_name in ioplugins: + IOPlugin.registered[plugin_name].set_arguments(args) def load_existing_data(ioplugins): """Load existing data from disk. @@ -1375,6 +1399,7 @@ def main_with_exceptions(cli_args): if args.vhosts is None: raise Error('You must set at least one -d/--vhost') + set_plugins_arguments(args.ioplugins, args) check_plugins_persist_all(args.ioplugins) existing_data = load_existing_data(args.ioplugins) From a76741a3b4d22e78b6c97610e4f2b2726041f670 Mon Sep 17 00:00:00 2001 From: Dick Marinus Date: Thu, 13 Oct 2016 20:15:22 +0200 Subject: [PATCH 2/2] Add --script parameter for custom external.sh script path --- simp_le.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/simp_le.py b/simp_le.py index 18355ff..efabac1 100755 --- a/simp_le.py +++ b/simp_le.py @@ -305,7 +305,6 @@ class IOPlugin(object): def __init__(self, path, **dummy_kwargs): self.path = path self.arguments_dest = [] - self.script_name = None if 'arguments' in dummy_kwargs: self.arguments = dummy_kwargs['arguments'] else: @@ -491,7 +490,16 @@ def dump_pem_jwk(data): ).strip() -@IOPlugin.register(path='external.sh', typ=OpenSSL.crypto.FILETYPE_PEM) +@IOPlugin.register(path='external.sh', typ=OpenSSL.crypto.FILETYPE_PEM, + arguments=[ + [ + ['--script'], + { + 'default': os.path.join('.', "external.sh"), + 'help': 'Script file for external.sh plugin', + } + ] + ]) class ExternalIOPlugin(OpenSSLIOPlugin): """External IO Plugin. @@ -514,11 +522,6 @@ class ExternalIOPlugin(OpenSSLIOPlugin): and ordered in the same way as in the `load` case. """ - @property - def script(self): - """Path to the script.""" - return os.path.join('.', self.path) - def get_output_or_fail(self, command): """Get output or throw an exception in case of errors.""" try: