From 10c81cb7def6e29ee6db1e47494f6f635cd70a5b Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Wed, 12 Jan 2022 13:30:40 +0100 Subject: [PATCH] Move the init of ConfigImport object before downloading profile The init phase of the ConfigImport object does the config name duplication check. By moving the init before the profile download we will bail out earlier and quicker with an error in case of non-unique configuration names and we don't issue any remote operations until we are ready to process the retrieved data locally. Signed-off-by: David Sommerseth --- openvpn/connector/main.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/openvpn/connector/main.py b/openvpn/connector/main.py index 7e9346d..6d96465 100644 --- a/openvpn/connector/main.py +++ b/openvpn/connector/main.py @@ -119,13 +119,17 @@ def main(): # and a key used to decrypt the downloaded profile token = DecodeToken(token) + systembus = dbus.SystemBus() + cfgimport = None + if ConfigModes.UNITFILE == run_mode: + cfgimport = ConfigImport(systembus, config_name) + # Download the profile from OpenVPN Cloud profile = ProfileFetch(token) print('Downloading OpenVPN Cloud Connector profile ... ', end='', flush=True) profile.Download() print('Done') - systembus = dbus.SystemBus() if ConfigModes.AUTOLOAD == run_mode: # Generate the openvpn3-autoload configuration autoload = AutoloadConfig(profile, rootdir, autoload_prefix) @@ -145,7 +149,6 @@ def main(): print('Done') elif ConfigModes.UNITFILE == run_mode: - cfgimport = ConfigImport(systembus, config_name) cfgimport.Import(profile) if os.geteuid() != 0: