From b2a48db9df08d5566d8b98f2debfd3ba96b48435 Mon Sep 17 00:00:00 2001 From: Mustafa Baser Date: Mon, 2 May 2022 19:59:26 +0300 Subject: [PATCH] fix: jans-linux-setup code smells --- jans-linux-setup/docs/README.md | 2 +- jans-linux-setup/jans_setup/jans_setup.py | 14 ++-- .../jans_setup/setup.properties.sample | 4 +- .../jans_setup/setup_app/config.py | 15 ++-- .../setup_app/installers/config_api.py | 2 +- .../setup_app/installers/couchbase.py | 8 +- .../jans_setup/setup_app/installers/jans.py | 10 +-- .../setup_app/installers/jans_auth.py | 2 +- .../setup_app/installers/jans_cli.py | 6 +- .../jans_setup/setup_app/installers/jetty.py | 79 ++++++++++++------- .../jans_setup/setup_app/installers/opendj.py | 36 ++++----- .../jans_setup/setup_app/installers/oxd.py | 2 +- .../jans_setup/setup_app/installers/rdbm.py | 2 +- .../jans_setup/setup_app/installers/scim.py | 2 +- .../jans_setup/setup_app/messages.py | 4 +- .../jans_setup/setup_app/setup_options.py | 8 +- .../jans_setup/setup_app/test_data_loader.py | 8 +- .../setup_app/utils/collect_properties.py | 10 +-- .../jans_setup/setup_app/utils/db_utils.py | 18 ++--- .../setup_app/utils/properties_utils.py | 46 +++++------ .../jans_setup/setup_app/utils/setup_utils.py | 30 ++++--- .../tools/ldap2mysql/ldap2mysql.py | 2 +- 22 files changed, 169 insertions(+), 141 deletions(-) diff --git a/jans-linux-setup/docs/README.md b/jans-linux-setup/docs/README.md index c3471e694d6..e3523ab7da4 100644 --- a/jans-linux-setup/docs/README.md +++ b/jans-linux-setup/docs/README.md @@ -80,7 +80,7 @@ Collection of utilities used by SetupApp. - `db_utils.py` Database management (both ldap and cocuhbase) class is inclueded `DBUtils` in this file. Since `DBUtils` class is assigned to `self.dbutils` variable in base class for installers, we generally don't include this module in installers. Functions in `DBUtils` class automatically determines which database to be used for operations by examining - `mappingLocations` defined in `Config` and populated during install time (or later from `setup.properties`). + `mapping_locations` defined in `Config` and populated during install time (or later from `setup.properties`). Some most commanly functions are: - `import_lidf(ldif_files)`: imports to list of ldif files to database. It automatically determines database location diff --git a/jans-linux-setup/jans_setup/jans_setup.py b/jans-linux-setup/jans_setup/jans_setup.py index 4ff8081caae..c1eef1352c4 100755 --- a/jans-linux-setup/jans_setup/jans_setup.py +++ b/jans-linux-setup/jans_setup/jans_setup.py @@ -284,7 +284,7 @@ def print_or_log(msg): print("Exiting ...") sys.exit() -Config.installJansCli = Config.installConfigApi or Config.installScimServer +Config.install_jans_cli = Config.install_config_api or Config.install_scim_server app_vars = locals().copy() @@ -393,15 +393,15 @@ def do_installation(): not Config.installed_instance and Config.installFido2): fidoInstaller.start_installation() - if (Config.installed_instance and 'installScimServer' in Config.addPostSetupService) or ( - not Config.installed_instance and Config.installScimServer): + if (Config.installed_instance and 'install_scim_server' in Config.addPostSetupService) or ( + not Config.installed_instance and Config.install_scim_server): scimInstaller.start_installation() if (Config.installed_instance and elevenInstaller.install_var in Config.addPostSetupService) or ( not Config.installed_instance and Config.get(elevenInstaller.install_var)): elevenInstaller.start_installation() - if Config.installJansCli: + if Config.install_jans_cli: jansCliInstaller.start_installation() jansCliInstaller.configure() @@ -443,11 +443,11 @@ def do_installation(): if base.current_app.proceed_installation: do_installation() print('\n', static.colors.OKGREEN) - if Config.installConfigApi or Config.installScimServer: + if Config.install_config_api or Config.install_scim_server: msg.installation_completed += "CLI available to manage Jannsen Server:\n" - if Config.installConfigApi: + if Config.install_config_api: msg.installation_completed += "/opt/jans/jans-cli/config-cli.py\n" - if Config.profile == 'jans' and Config.installScimServer: + if Config.profile == 'jans' and Config.install_scim_server: msg.installation_completed += "/opt/jans/jans-cli/scim-cli.py" msg_text = msg.post_installation if Config.installed_instance else msg.installation_completed.format( diff --git a/jans-linux-setup/jans_setup/setup.properties.sample b/jans-linux-setup/jans_setup/setup.properties.sample index b3c5dad552e..37d7a63468c 100644 --- a/jans-linux-setup/jans_setup/setup.properties.sample +++ b/jans-linux-setup/jans_setup/setup.properties.sample @@ -48,10 +48,10 @@ installLdap=True application_max_ram= ### If you want to install Janssen Config Api, set this to True -installConfigApi= +install_config_api= ### If you want to install Fido2 Server, set this to True installFido2= ### If you want to install Scim Server, set this to True -installScimServer= +install_scim_server= diff --git a/jans-linux-setup/jans_setup/setup_app/config.py b/jans-linux-setup/jans_setup/setup_app/config.py index 943390363c3..dfce1d59aeb 100644 --- a/jans-linux-setup/jans_setup/setup_app/config.py +++ b/jans-linux-setup/jans_setup/setup_app/config.py @@ -80,7 +80,10 @@ def init(self, install_dir=INSTALL_DIR): self.profile = base.current_app.profile self.thread_queue = None - self.jetty_user = 'jetty' + self.jetty_user = self.jetty_group = 'jetty' + self.root_user = self.root_group = 'root' + self.ldap_user = self.ldap_group = 'ldap' + self.dump_config_on_error = False if not self.output_dir: self.output_dir = os.path.join(install_dir, 'output') @@ -186,13 +189,13 @@ def progress(self, service_name, msg, incr=False): self.installSaml = False self.installPassport = False self.installJansRadius = False - self.installScimServer = True + self.install_scim_server = True self.installFido2 = True - self.installConfigApi = True + self.install_config_api = True self.installCasa = False self.installOxd = False self.installEleven = False - self.installJansCli = True + self.install_jans_cli = True self.loadTestData = False self.allowPreReleasedFeatures = False @@ -394,10 +397,10 @@ def progress(self, service_name, msg, incr=False): if self.profile == OPENBANKING_PROFILE: #default locations are rdbm - self.mappingLocations = {'default': 'rdbm'} + self.mapping_locations = {'default': 'rdbm'} else: #default locations are OpenDJ - self.mappingLocations = { group: 'ldap' for group in self.couchbaseBucketDict } + self.mapping_locations = { group: 'ldap' for group in self.couchbaseBucketDict } self.non_setup_properties = { 'oxauth_client_jar_fn': os.path.join(self.dist_jans_dir, 'jans-auth-client-jar-with-dependencies.jar') diff --git a/jans-linux-setup/jans_setup/setup_app/installers/config_api.py b/jans-linux-setup/jans_setup/setup_app/installers/config_api.py index 404197de3c7..0586c131721 100644 --- a/jans-linux-setup/jans_setup/setup_app/installers/config_api.py +++ b/jans-linux-setup/jans_setup/setup_app/installers/config_api.py @@ -32,7 +32,7 @@ def __init__(self): self.check_version = False #TODO: remove this when version format is changed to 1.0.0 self.app_type = AppType.SERVICE self.install_type = InstallOption.OPTONAL - self.install_var = 'installConfigApi' + self.install_var = 'install_config_api' self.register_progess() diff --git a/jans-linux-setup/jans_setup/setup_app/installers/couchbase.py b/jans-linux-setup/jans_setup/setup_app/installers/couchbase.py index 51b0173321f..b0f08e1ac54 100644 --- a/jans-linux-setup/jans_setup/setup_app/installers/couchbase.py +++ b/jans-linux-setup/jans_setup/setup_app/installers/couchbase.py @@ -72,7 +72,7 @@ def install(self): couchbase_mappings = self.getMappingType('couchbase') - if Config.mappingLocations['default'] == 'couchbase': + if Config.mapping_locations['default'] == 'couchbase': self.dbUtils.import_ldif(Config.couchbaseBucketDict['default']['ldif'], Config.couchbase_bucket_prefix) else: self.dbUtils.import_ldif([Config.ldif_base], force=BackendTypes.COUCHBASE) @@ -288,7 +288,7 @@ def couchbaseDict(self): bucket = Config.couchbase_bucket_prefix if group == 'default' else Config.couchbase_bucket_prefix + '_' + group if bucket in Config.couchbase_buckets: cb_key = 'couchbase_{}_mapping'.format(group) - if Config.mappingLocations[group] == 'couchbase': + if Config.mapping_locations[group] == 'couchbase': if Config.couchbaseBucketDict[group]['mapping']: couchbase_mappings.append('bucket.{}_{}.mapping: {}'.format(Config.couchbase_bucket_prefix, group, Config.couchbaseBucketDict[group]['mapping'])) Config.templateRenderingDict[cb_key] = Config.couchbaseBucketDict[group]['mapping'] @@ -343,13 +343,13 @@ def create_couchbase_buckets(self): if not Config.couchbase_bucket_prefix in existing_buckets: - if Config.mappingLocations['default'] != 'couchbase': + if Config.mapping_locations['default'] != 'couchbase': self.couchebaseCreateBucket(Config.couchbase_bucket_prefix, bucketRamsize=100) else: bucketRamsize = int((Config.couchbaseBucketDict['default']['memory_allocation']/min_cb_ram)*couchbaseClusterRamsize) self.couchebaseCreateBucket(Config.couchbase_bucket_prefix, bucketRamsize=bucketRamsize) - if Config.mappingLocations['default'] == 'couchbase': + if Config.mapping_locations['default'] == 'couchbase': self.couchebaseCreateIndexes(Config.couchbase_bucket_prefix) for group in couchbase_mappings: diff --git a/jans-linux-setup/jans_setup/setup_app/installers/jans.py b/jans-linux-setup/jans_setup/setup_app/installers/jans.py index 1fbf8f06123..4670114373a 100644 --- a/jans-linux-setup/jans_setup/setup_app/installers/jans.py +++ b/jans-linux-setup/jans_setup/setup_app/installers/jans.py @@ -70,10 +70,10 @@ def __repr__(self): txt += 'Install Apache 2 web server'.ljust(30) + repr(Config.installHttpd).rjust(35) + (' *' if 'installHttpd' in Config.addPostSetupService else '') + "\n" txt += 'Install Auth Server'.ljust(30) + repr(Config.installOxAuth).rjust(35) + "\n" - txt += 'Install Jans Auth Config Api'.ljust(30) + repr(Config.installConfigApi).rjust(35) + "\n" + txt += 'Install Jans Auth Config Api'.ljust(30) + repr(Config.install_config_api).rjust(35) + "\n" if Config.profile == 'jans': txt += 'Install Fido2 Server'.ljust(30) + repr(Config.installFido2).rjust(35) + (' *' if 'installFido2' in Config.addPostSetupService else '') + "\n" - txt += 'Install Scim Server'.ljust(30) + repr(Config.installScimServer).rjust(35) + (' *' if 'installScimServer' in Config.addPostSetupService else '') + "\n" + txt += 'Install Scim Server'.ljust(30) + repr(Config.install_scim_server).rjust(35) + (' *' if 'install_scim_server' in Config.addPostSetupService else '') + "\n" txt += 'Install Eleven Server'.ljust(30) + repr(Config.installEleven).rjust(35) + (' *' if 'installEleven' in Config.addPostSetupService else '') + "\n" #txt += 'Install Oxd '.ljust(30) + repr(Config.installOxd).rjust(35) + (' *' if 'installOxd' in Config.addPostSetupService else '') + "\n" return txt @@ -220,12 +220,12 @@ def writeHybridProperties(self): ldap_mappings = self.getMappingType('ldap') couchbase_mappings = self.getMappingType('couchbase') - for group in Config.mappingLocations: + for group in Config.mapping_locations: if group == 'default': - default_mapping = Config.mappingLocations[group] + default_mapping = Config.mapping_locations[group] break - storages = set(Config.mappingLocations.values()) + storages = set(Config.mapping_locations.values()) jans_hybrid_roperties = [ 'storages: {0}'.format(', '.join(storages)), diff --git a/jans-linux-setup/jans_setup/setup_app/installers/jans_auth.py b/jans-linux-setup/jans_setup/setup_app/installers/jans_auth.py index 35d6f4ed015..2091dde1967 100644 --- a/jans-linux-setup/jans_setup/setup_app/installers/jans_auth.py +++ b/jans-linux-setup/jans_setup/setup_app/installers/jans_auth.py @@ -111,7 +111,7 @@ def render_import_templates(self): self.role_scope_mappings() - Config.templateRenderingDict['person_custom_object_class_list'] = '[]' if Config.mappingLocations['default'] == 'rdbm' else '["jansCustomPerson", "jansPerson"]' + Config.templateRenderingDict['person_custom_object_class_list'] = '[]' if Config.mapping_locations['default'] == 'rdbm' else '["jansCustomPerson", "jansPerson"]' templates = [self.oxauth_config_json] if Config.profile == 'jans': diff --git a/jans-linux-setup/jans_setup/setup_app/installers/jans_cli.py b/jans-linux-setup/jans_setup/setup_app/installers/jans_cli.py index b2ae0811aea..d0477da53a0 100644 --- a/jans-linux-setup/jans_setup/setup_app/installers/jans_cli.py +++ b/jans-linux-setup/jans_setup/setup_app/installers/jans_cli.py @@ -27,7 +27,7 @@ def __init__(self): setattr(base.current_app, self.__class__.__name__, self) self.service_name = 'jans-cli' self.needdb = False # we don't need backend connection in this class - self.install_var = 'installJansCli' + self.install_var = 'install_jans_cli' self.app_type = AppType.APPLICATION self.install_type = InstallOption.OPTONAL home_dir = Path.home() @@ -86,11 +86,11 @@ def configure(self, options={}): for key_ in options: config['DEFAULT'][key_] = options[key_] - if Config.installConfigApi: + if Config.install_config_api: config['DEFAULT']['jca_client_id'] = Config.role_based_client_id config['DEFAULT']['jca_client_secret_enc'] = Config.role_based_client_encoded_pw - if Config.get('installScimServer'): + if Config.get('install_scim_server'): config['DEFAULT']['scim_client_id'] = Config.scim_client_id config['DEFAULT']['scim_client_secret_enc'] = Config.scim_client_encoded_pw diff --git a/jans-linux-setup/jans_setup/setup_app/installers/jetty.py b/jans-linux-setup/jans_setup/setup_app/installers/jetty.py index 8aea9ab37cb..8b98b36d613 100644 --- a/jans-linux-setup/jans_setup/setup_app/installers/jetty.py +++ b/jans-linux-setup/jans_setup/setup_app/installers/jetty.py @@ -11,6 +11,9 @@ from setup_app.utils.setup_utils import SetupUtils from setup_app.installers.base import BaseInstaller +NAME_STR = 'jetty' +WEBAPPS = 'webapps' + class JettyInstaller(BaseInstaller, SetupUtils): # let's borrow these variables from Config @@ -36,8 +39,8 @@ def __init__(self): self.jetty_user_home_lib = os.path.join(self.jetty_user_home, 'lib') self.app_custom_changes = { - 'jetty' : { - 'name' : 'jetty', + NAME_STR : { + 'name' : NAME_STR, 'files' : [ { 'path' : os.path.join(self.jetty_home, 'etc/webdefault.xml'), @@ -64,15 +67,15 @@ def __init__(self): def install(self): - self.createUser('jetty', self.jetty_user_home) - self.addUserToGroup('jans', 'jetty') + self.createUser(Config.jetty_user, self.jetty_user_home) + self.addUserToGroup('jans', Config.jetty_user) self.run([paths.cmd_mkdir, '-p', self.jetty_user_home_lib]) jettyArchive, jetty_dist = self.get_jetty_info() jettyTemp = os.path.join(jetty_dist, 'temp') self.run([paths.cmd_mkdir, '-p', jettyTemp]) - self.run([paths.cmd_chown, '-R', 'jetty:jetty', jettyTemp]) + self.chown(jettyTemp, Config.jetty_user, Config.jetty_group, recursive=True) try: self.logIt("Extracting %s into /opt/jetty" % jettyArchive) @@ -85,23 +88,24 @@ def install(self): self.run([paths.cmd_ln, '-sf', jettyDestinationPath, self.jetty_home]) self.run([paths.cmd_chmod, '-R', "755", "%s/bin/" % jettyDestinationPath]) - self.applyChangesInFiles(self.app_custom_changes['jetty']) + self.applyChangesInFiles(self.app_custom_changes[NAME_STR]) - self.run([paths.cmd_chown, '-R', 'jetty:jetty', jettyDestinationPath]) - self.run([paths.cmd_chown, '-h', 'jetty:jetty', self.jetty_home]) + self.chown(jettyDestinationPath, Config.jetty_user, Config.jetty_group, recursive=True) + self.run([paths.cmd_chown, '-h', '{}:{}'.format(Config.jetty_user, Config.jetty_group), self.jetty_home]) self.run([paths.cmd_mkdir, '-p', self.jetty_base]) - self.run([paths.cmd_chown, '-R', 'jetty:jetty', self.jetty_base]) + self.chown(self.jetty_base, Config.jetty_user, Config.jetty_group, recursive=True) jettyRunFolder = '/var/run/jetty' self.run([paths.cmd_mkdir, '-p', jettyRunFolder]) self.run([paths.cmd_chmod, '-R', '775', jettyRunFolder]) - self.run([paths.cmd_chgrp, '-R', 'jetty', jettyRunFolder]) + self.run([paths.cmd_chgrp, '-R', Config.jetty_group, jettyRunFolder]) + jetty_bin_sh_fn = os.path.join(self.jetty_home, 'bin/jetty.sh') self.run(['rm', '-rf', '/opt/jetty/bin/jetty.sh']) - self.copyFile("%s/system/initd/jetty.sh" % Config.staticFolder, "%s/bin/jetty.sh" % self.jetty_home) - self.run([paths.cmd_chown, '-R', 'jetty:jetty', "%s/bin/jetty.sh" % self.jetty_home]) - self.run([paths.cmd_chmod, '-R', '755', "%s/bin/jetty.sh" % self.jetty_home]) + self.copyFile("%s/system/initd/jetty.sh" % Config.staticFolder, jetty_bin_sh_fn) + self.chown(jetty_bin_sh_fn, Config.jetty_user, Config.jetty_group, recursive=True) + self.run([paths.cmd_chmod, '-R', '755', jetty_bin_sh_fn]) def get_jetty_info(self): # first try latest versions @@ -126,7 +130,7 @@ def get_jetty_info(self): @property def web_app_xml_fn(self): - return os.path.join(self.jetty_base, self.service_name, 'webapps', self.service_name+'.xml') + return os.path.join(self.jetty_base, self.service_name, WEBAPPS, self.service_name+'.xml') def installJettyService(self, serviceConfiguration, supportCustomizations=False, supportOnlyPageCustomizations=False): @@ -135,7 +139,7 @@ def installJettyService(self, serviceConfiguration, supportCustomizations=False, self.logIt("Deploying Jetty Service", pbar=serviceName) self.get_jetty_info() jettyServiceBase = '%s/%s' % (self.jetty_base, serviceName) - jettyModules = serviceConfiguration['jetty']['modules'] + jettyModules = serviceConfiguration[NAME_STR]['modules'] jettyModulesList = jettyModules.split(',') jettyModulesList = [m.strip() for m in jettyModules.split(',')] @@ -173,35 +177,49 @@ def installJettyService(self, serviceConfiguration, supportCustomizations=False, jettyEnv['PATH'] = '%s/bin:' % Config.jre_home + jettyEnv['PATH'] self.run([Config.cmd_java, '-jar', '%s/start.jar' % self.jetty_home, 'jetty.home=%s' % self.jetty_home, 'jetty.base=%s' % jettyServiceBase, '--add-module=%s' % jettyModules], None, jettyEnv) - self.run([paths.cmd_chown, '-R', 'jetty:jetty', jettyServiceBase]) + self.chown(jettyServiceBase, Config.jetty_user, Config.jetty_group, recursive=True) # make variables of this class accesible from Config self.update_rendering_dict() try: - self.renderTemplateInOut(serviceName, '%s/jetty' % Config.templateFolder, '%s/jetty' % Config.output_dir) + self.renderTemplateInOut(serviceName, os.path.join(Config.templateFolder, NAME_STR), os.path.join(Config.output_dir, NAME_STR)) except: self.logIt("Error rendering service '%s' defaults" % serviceName, True) - jettyServiceConfiguration = '%s/jetty/%s' % (Config.output_dir, serviceName) + jettyServiceConfiguration = os.path.join(Config.output_dir, NAME_STR, serviceName) self.copyFile(jettyServiceConfiguration, Config.osDefault) - self.run([paths.cmd_chown, 'root:root', os.path.join(Config.osDefault, serviceName)]) + self.chown(os.path.join(Config.osDefault, serviceName), Config.root_user) # Render web eources file try: web_resources = '%s_web_resources.xml' % serviceName - if os.path.exists('%s/jetty/%s' % (Config.templateFolder, web_resources)): - self.renderTemplateInOut(web_resources, '%s/jetty' % Config.templateFolder, '%s/jetty' % Config.output_dir) - self.copyFile('%s/jetty/%s' % (Config.output_dir, web_resources), "%s/%s/webapps" % (self.jetty_base, serviceName)) + if os.path.exists(os.path.join(Config.templateFolder, NAME_STR, web_resources)): + self.renderTemplateInOut( + web_resources, + os.path.join(Config.templateFolder, NAME_STR), + os.path.join(Config.output_dir, NAME_STR) + ) + self.copyFile( + os.path.join(Config.output_dir, NAME_STR, web_resources), + os.path.join(self.jetty_base, serviceName, WEBAPPS) + ) except: self.logIt("Error rendering service '%s' web_resources.xml" % serviceName, True) # Render web context file try: web_context = '%s.xml' % serviceName - if os.path.exists('%s/jetty/%s' % (Config.templateFolder, web_context)): - self.renderTemplateInOut(web_context, '%s/jetty' % Config.templateFolder, '%s/jetty' % Config.output_dir) - self.copyFile('%s/jetty/%s' % (Config.output_dir, web_context), "%s/%s/webapps" % (self.jetty_base, serviceName)) + if os.path.exists(os.path.join(Config.templateFolder, NAME_STR, web_context)): + self.renderTemplateInOut( + web_context, + os.path.join(Config.templateFolder, NAME_STR), + os.path.join(Config.output_dir, NAME_STR) + ) + self.copyFile( + os.path.join(Config.output_dir, NAME_STR, web_context), + os.path.join(self.jetty_base, serviceName, WEBAPPS) + ) except: self.logIt("Error rendering service '%s' context xml" % serviceName, True) @@ -215,7 +233,8 @@ def installJettyService(self, serviceConfiguration, supportCustomizations=False, jetty_tmpfiles_src = '%s/jetty.conf.tmpfiles.d' % Config.templateFolder jetty_tmpfiles_dst = '%s/jetty.conf' % tmpfiles_base self.copyFile(jetty_tmpfiles_src, jetty_tmpfiles_dst) - self.run([paths.cmd_chown, 'root:root', jetty_tmpfiles_dst]) + self.chown(jetty_tmpfiles_dst, Config.root_user, Config.root_group) + self.run([paths.cmd_chmod, '644', jetty_tmpfiles_dst]) self.copyFile(os.path.join(self.jetty_home, 'bin/jetty.sh'), os.path.join(Config.distFolder, 'scripts', serviceName), backup=False) @@ -327,9 +346,9 @@ def calculate_selected_aplications_memory(self): # Jetty apps for config_var, service in [('installOxAuth', 'jans-auth'), - ('installScimServer', 'jans-scim'), + ('install_scim_server', 'jans-scim'), ('installFido2', 'jans-fido2'), - ('installConfigApi', 'jans-config-api'), + ('install_config_api', 'jans-config-api'), ('installEleven', 'jans-eleven')]: if Config.get(config_var) and service in self.jetty_app_configuration: @@ -361,14 +380,14 @@ def add_extra_class(self, class_path, xml_fn=None): app_set.text = ','.join(path_list) with open(xml_fn, 'wb') as f: - f.write(b'\n') + f.write(b'\n') f.write(b'\n') f.write(ET.tostring(root, method='xml')) def get_plugins(self): plugins = [] - webapps_xml_fn = os.path.join(self.jetty_base, self.service_name, 'webapps', self.service_name+'.xml') + webapps_xml_fn = os.path.join(self.jetty_base, self.service_name, WEBAPPS, self.service_name+'.xml') if os.path.exists(webapps_xml_fn): diff --git a/jans-linux-setup/jans_setup/setup_app/installers/opendj.py b/jans-linux-setup/jans_setup/setup_app/installers/opendj.py index 4a36ac668f6..66103d7905c 100644 --- a/jans-linux-setup/jans_setup/setup_app/installers/opendj.py +++ b/jans-linux-setup/jans_setup/setup_app/installers/opendj.py @@ -30,6 +30,7 @@ def __init__(self): self.install_type = InstallOption.OPTONAL self.install_var = 'opendj_install' self.register_progess() + self.ldap_str = 'ldap' self.openDjIndexJson = os.path.join(Config.install_dir, 'static/opendj/index.json') self.openDjSchemaFolder = os.path.join(Config.ldap_base_dir, 'config/schema') @@ -71,10 +72,10 @@ def install(self): ldif_files = [] - if Config.mappingLocations['default'] == 'ldap': + if Config.mapping_locations['default'] == self.ldap_str: ldif_files += Config.couchbaseBucketDict['default']['ldif'] - ldap_mappings = self.getMappingType('ldap') + ldap_mappings = self.getMappingType(self.ldap_str) for group in ldap_mappings: ldif_files += Config.couchbaseBucketDict[group]['ldif'] @@ -102,44 +103,41 @@ def extractOpenDJ(self): self.logIt("Error encountered while doing unzip %s -d /opt/" % (opendj_archive)) real_ldap_base_dir = os.path.realpath(Config.ldap_base_dir) - self.run([paths.cmd_chown, '-R', 'ldap:ldap', real_ldap_base_dir]) + self.chown(real_ldap_base_dir, Config.ldap_user, Config.ldap_group, recursive=True) if Config.opendj_install == InstallTypes.REMOTE: self.run([paths.cmd_ln, '-s', '/opt/opendj/template/config/', '/opt/opendj/config']) def create_user(self): - self.createUser('ldap', Config.ldap_user_home) - self.addUserToGroup('jans', 'ldap') - self.addUserToGroup('adm', 'ldap') + self.createUser(Config.ldap_user, Config.ldap_user_home) + self.addUserToGroup('jans', Config.ldap_group) + self.addUserToGroup('adm', Config.ldap_group) def install_opendj(self): self.logIt("Running OpenDJ Setup") - #if base.snap and not os.path.exists(Config.ldap_base_dir): - # self.run([paths.cmd_mkdir, Config.ldap_base_dir]) - # Copy opendj-setup.properties so user ldap can find it in /opt/opendj setup_props_fn = os.path.join(Config.ldap_base_dir, 'opendj-setup.properties') shutil.copy("%s/opendj-setup.properties" % Config.output_dir, setup_props_fn) - self.run([paths.cmd_chown, 'ldap:ldap', setup_props_fn]) + self.chown(setup_props_fn, Config.ldap_user, Config.ldap_group) ldap_setup_command = os.path.join(os.path.dirname(Config.ldap_bin_dir ), 'setup') - setupCmd = " ".join([ldap_setup_command, + setup_cmd = " ".join([ldap_setup_command, '--no-prompt', '--cli', '--propertiesFilePath', setup_props_fn, '--acceptLicense']) if base.snap: - self.run(setupCmd, shell=True) + self.run(setup_cmd, shell=True) else: self.run(['/bin/su', - 'ldap', + Config.ldap_user, '-c', - setupCmd], + setup_cmd], cwd='/opt/opendj', ) @@ -193,7 +191,7 @@ def create_backends(self): ['create-backend', '--backend-name', 'metric', '--set', 'base-dn:o=metric', '--type %s' % Config.ldap_backend_type, '--set', 'enabled:true', '--set', 'db-cache-percent:20'], ] - if Config.mappingLocations['site'] == 'ldap': + if Config.mapping_locations['site'] == self.ldap_str: backends.append(['create-backend', '--backend-name', 'site', '--set', 'base-dn:o=site', '--type %s' % Config.ldap_backend_type, '--set', 'enabled:true', '--set', 'db-cache-percent:20']) for changes in backends: @@ -214,7 +212,7 @@ def create_backends(self): self.run(dsconfigCmd, shell=True) else: self.run(['/bin/su', - 'ldap', + Config.ldap_user, '-c', dsconfigCmd], cwd=cwd) @@ -303,7 +301,7 @@ def index_opendj(self): index_backends = ['userRoot'] - if Config.mappingLocations['site'] == 'ldap': + if Config.mapping_locations['site'] == self.ldap_str: index_backends.append('site') for attrDict in index_json: @@ -339,7 +337,7 @@ def prepare_opendj_schema(self): self.copyFile(schema_file, self.openDjSchemaFolder) self.run([paths.cmd_chmod, '-R', 'a+rX', Config.ldap_base_dir]) - self.run([paths.cmd_chown, '-R', 'ldap:ldap', Config.ldap_base_dir]) + self.chown(Config.ldap_base_dir, Config.ldap_user, Config.ldap_group, recursive=True) self.logIt("Re-starting OpenDj after schema update") self.stop() @@ -359,7 +357,7 @@ def setup_opendj_service(self): if os.path.exists(init_script_fn): self.run(['rm', '-f', init_script_fn]) else: - self.run([self.ldapDsCreateRcCommand, "--outputFile", "/etc/init.d/opendj", "--userName", "ldap"]) + self.run([self.ldapDsCreateRcCommand, '--outputFile', '/etc/init.d/opendj', '--userName', Config.ldap_user]) # Make the generated script LSB compliant lsb_str=( '### BEGIN INIT INFO\n' diff --git a/jans-linux-setup/jans_setup/setup_app/installers/oxd.py b/jans-linux-setup/jans_setup/setup_app/installers/oxd.py index 287505b12f7..5231f3068ef 100644 --- a/jans-linux-setup/jans_setup/setup_app/installers/oxd.py +++ b/jans-linux-setup/jans_setup/setup_app/installers/oxd.py @@ -86,7 +86,7 @@ def modify_config_yml(self): oxd_yaml['storage'] = 'jans_server_configuration' oxd_yaml['storage_configuration']['baseDn'] = 'o=jans' oxd_yaml['storage_configuration']['type'] = Config.jans_properties_fn - oxd_yaml['storage_configuration']['connection'] = Config.ox_ldap_properties if Config.mappingLocations['default'] == 'ldap' else Config.jansCouchebaseProperties + oxd_yaml['storage_configuration']['connection'] = Config.ox_ldap_properties if Config.mapping_locations['default'] == 'ldap' else Config.jansCouchebaseProperties oxd_yaml['storage_configuration']['salt'] = os.path.join(Config.configFolder, "salt") if base.snap: diff --git a/jans-linux-setup/jans_setup/setup_app/installers/rdbm.py b/jans-linux-setup/jans_setup/setup_app/installers/rdbm.py index 06d8c135beb..b563c9021c9 100644 --- a/jans-linux-setup/jans_setup/setup_app/installers/rdbm.py +++ b/jans-linux-setup/jans_setup/setup_app/installers/rdbm.py @@ -335,7 +335,7 @@ def create_indexes(self): def import_ldif(self): ldif_files = [] - if Config.mappingLocations['default'] == 'rdbm': + if Config.mapping_locations['default'] == 'rdbm': ldif_files += Config.couchbaseBucketDict['default']['ldif'] ldap_mappings = self.getMappingType('rdbm') diff --git a/jans-linux-setup/jans_setup/setup_app/installers/scim.py b/jans-linux-setup/jans_setup/setup_app/installers/scim.py index 5fa2ec1146d..613da151bb5 100644 --- a/jans-linux-setup/jans_setup/setup_app/installers/scim.py +++ b/jans-linux-setup/jans_setup/setup_app/installers/scim.py @@ -21,7 +21,7 @@ def __init__(self): self.needdb = True self.app_type = AppType.SERVICE self.install_type = InstallOption.OPTONAL - self.install_var = 'installScimServer' + self.install_var = 'install_scim_server' self.register_progess() self.templates_folder = os.path.join(Config.templateFolder, self.service_name) diff --git a/jans-linux-setup/jans_setup/setup_app/messages.py b/jans-linux-setup/jans_setup/setup_app/messages.py index c453d5e9f82..5f2c79fb4f6 100644 --- a/jans-linux-setup/jans_setup/setup_app/messages.py +++ b/jans-linux-setup/jans_setup/setup_app/messages.py @@ -37,7 +37,7 @@ class msg: installing_label = "Current" installOxd_label = "Install Oxd" installCasa_label = "Install Casa" - installScimServer_label = "Install Scim" + install_scim_server_label = "Install Scim" installFido2_label = "Install Fido2" insufficient_free_disk_space = "Available free disk space was determined to be {1:0.1f} GB. This is less than the required disk space of {} GB." @@ -79,7 +79,7 @@ class msg: ask_installCasa = "Install Casa" ask_installOxd = "Install Oxd" ask_opendj_install = "Install OpenDJ" - ask_installScimServer = "Install Scim Server" + ask_install_scim_server = "Install Scim Server" ask_installFido2 = "Install Fido2" opendj_install_options = ["Don't Install","Install Locally","Use Remote OpenDJ"] diff --git a/jans-linux-setup/jans_setup/setup_app/setup_options.py b/jans-linux-setup/jans_setup/setup_app/setup_options.py index 8432a0d7fe9..33599e14313 100644 --- a/jans-linux-setup/jans_setup/setup_app/setup_options.py +++ b/jans-linux-setup/jans_setup/setup_app/setup_options.py @@ -12,9 +12,9 @@ def get_setup_options(): 'noPrompt': False, 'downloadWars': False, 'installOxAuth': True, - 'installConfigApi': True, + 'install_config_api': True, 'installHTTPD': True, - 'installScimServer': True if base.current_app.profile == 'jans' else False, + 'install_scim_server': True if base.current_app.profile == 'jans' else False, 'installOxd': False, 'installFido2': True, 'installEleven': False, @@ -90,10 +90,10 @@ def get_setup_options(): setupOptions['installOxAuth'] = False if base.argsp.no_config_api: - setupOptions['installConfigApi'] = False + setupOptions['install_config_api'] = False if base.argsp.no_scim: - setupOptions['installScimServer'] = False + setupOptions['install_scim_server'] = False if base.argsp.no_fido2: setupOptions['installFido2'] = False diff --git a/jans-linux-setup/jans_setup/setup_app/test_data_loader.py b/jans-linux-setup/jans_setup/setup_app/test_data_loader.py index 87292c3f313..4d4af6967dd 100644 --- a/jans-linux-setup/jans_setup/setup_app/test_data_loader.py +++ b/jans-linux-setup/jans_setup/setup_app/test_data_loader.py @@ -78,7 +78,7 @@ def load_test_data(self): if not base.current_app.ScimInstaller.installed(): self.logIt("Scim was not installed. Installing") - Config.installScimServer = True + Config.install_scim_server = True base.current_app.ScimInstaller.start_installation() self.encode_test_passwords() @@ -172,7 +172,7 @@ def load_test_data(self): ignoredirs = [] - if not Config.installConfigApi: + if not Config.install_config_api: ignoredirs.append(os.path.join(self.template_base, 'jans-config-api')) self.render_templates_folder(self.template_base, ignoredirs=ignoredirs) @@ -383,13 +383,13 @@ def load_test_data(self): os.makedirs(target_dir) self.run([paths.cmd_tar, '-zxf', eleven_tokens_package, '-C', target_dir]) - if Config.installScimServer: + if Config.install_scim_server: self.restart('jans-scim') if Config.installFido2: self.restart('jans-fido2') - if Config.installConfigApi: + if Config.install_config_api: self.restart('jans-config-api') if Config.installEleven: diff --git a/jans-linux-setup/jans_setup/setup_app/utils/collect_properties.py b/jans-linux-setup/jans_setup/setup_app/utils/collect_properties.py index 8b1641d6614..17fb053e7c7 100644 --- a/jans-linux-setup/jans_setup/setup_app/utils/collect_properties.py +++ b/jans-linux-setup/jans_setup/setup_app/utils/collect_properties.py @@ -42,7 +42,7 @@ def collect(self): if Config.persistence_type in ('couchbase', 'sql', 'spanner'): ptype = 'rdbm' if Config.persistence_type in ('sql', 'spanner') else 'couchbase' - Config.mappingLocations = { group: ptype for group in Config.couchbaseBucketDict } + Config.mapping_locations = { group: ptype for group in Config.couchbaseBucketDict } default_storage = Config.persistence_type @@ -99,13 +99,13 @@ def collect(self): if Config.persistence_type in ['hybrid']: jans_hybrid_properties = base.read_properties_file(jans_hybrid_properties_fn) - Config.mappingLocations = {'default': jans_hybrid_properties['storage.default']} + Config.mapping_locations = {'default': jans_hybrid_properties['storage.default']} storages = [ storage.strip() for storage in jans_hybrid_properties['storages'].split(',') ] for ml, m in (('user', 'people'), ('cache', 'cache'), ('site', 'cache-refresh'), ('token', 'tokens')): for storage in storages: if m in jans_hybrid_properties.get('storage.{}.mapping'.format(storage),[]): - Config.mappingLocations[ml] = storage + Config.mapping_locations[ml] = storage if not Config.get('couchbase_bucket_prefix'): Config.couchbase_bucket_prefix = 'jans' @@ -247,10 +247,10 @@ def collect(self): if not Config.get('ip'): Config.ip = self.detect_ip() - Config.installScimServer = os.path.exists(os.path.join(Config.jetty_base, 'jans-scim/start.ini')) + Config.install_scim_server = os.path.exists(os.path.join(Config.jetty_base, 'jans-scim/start.ini')) Config.installFido2 = os.path.exists(os.path.join(Config.jetty_base, 'jans-fido2/start.ini')) Config.installEleven = os.path.exists(os.path.join(Config.jetty_base, 'jans-eleven/start.ini')) - Config.installConfigApi = os.path.exists(os.path.join(Config.jansOptFolder, 'jans-config-api')) + Config.install_config_api = os.path.exists(os.path.join(Config.jansOptFolder, 'jans-config-api')) result = dbUtils.search('ou=people,o=jans', search_filter='(&(uid=admin)(objectClass=jansPerson))') if result: diff --git a/jans-linux-setup/jans_setup/setup_app/utils/db_utils.py b/jans-linux-setup/jans_setup/setup_app/utils/db_utils.py index 157ab11feda..25070ba1d5f 100644 --- a/jans-linux-setup/jans_setup/setup_app/utils/db_utils.py +++ b/jans-linux-setup/jans_setup/setup_app/utils/db_utils.py @@ -52,9 +52,9 @@ def bind(self, use_ssl=True, force=False): format='%(asctime)s %(levelname)s - %(message)s' ) - if Config.mappingLocations['default'] == 'ldap': + if Config.mapping_locations['default'] == 'ldap': self.moddb = BackendTypes.LDAP - elif Config.mappingLocations['default'] == 'rdbm': + elif Config.mapping_locations['default'] == 'rdbm': self.read_jans_schema() if Config.rdbm_type == 'mysql': self.moddb = BackendTypes.MYSQL @@ -67,8 +67,8 @@ def bind(self, use_ssl=True, force=False): self.moddb = BackendTypes.COUCHBASE if not hasattr(self, 'ldap_conn') or force: - for group in Config.mappingLocations: - if Config.mappingLocations[group] == 'ldap': + for group in Config.mapping_locations: + if Config.mapping_locations[group] == 'ldap': base.logIt("Making LDAP Conncetion") ldap_server = ldap3.Server(Config.ldap_hostname, port=int(Config.ldaps_port), use_ssl=use_ssl) self.ldap_conn = ldap3.Connection( @@ -81,8 +81,8 @@ def bind(self, use_ssl=True, force=False): break if not self.session or force: - for group in Config.mappingLocations: - if Config.mappingLocations[group] == 'rdbm': + for group in Config.mapping_locations: + if Config.mapping_locations[group] == 'rdbm': if Config.rdbm_type in ('mysql', 'pgsql'): base.logIt("Making MySql Conncetion") result = self.mysqlconnection() @@ -1156,10 +1156,10 @@ def get_backend_location_for_dn(self, dn): key = ldif_utils.get_key_from(dn) group = self.get_group_for_key(key) - if Config.mappingLocations[group] == 'ldap': + if Config.mapping_locations[group] == 'ldap': return static.BackendTypes.LDAP - if Config.mappingLocations[group] == 'rdbm': + if Config.mapping_locations[group] == 'rdbm': if Config.rdbm_type == 'mysql': return static.BackendTypes.MYSQL elif Config.rdbm_type == 'pgsql': @@ -1167,7 +1167,7 @@ def get_backend_location_for_dn(self, dn): elif Config.rdbm_type == 'spanner': return static.BackendTypes.SPANNER - if Config.mappingLocations[group] == 'couchbase': + if Config.mapping_locations[group] == 'couchbase': return static.BackendTypes.COUCHBASE diff --git a/jans-linux-setup/jans_setup/setup_app/utils/properties_utils.py b/jans-linux-setup/jans_setup/setup_app/utils/properties_utils.py index e9421d99a65..fb42ac24e49 100644 --- a/jans-linux-setup/jans_setup/setup_app/utils/properties_utils.py +++ b/jans-linux-setup/jans_setup/setup_app/utils/properties_utils.py @@ -117,10 +117,10 @@ def check_properties(self): if not Config.opendj_install: if Config.cb_install: - Config.mappingLocations = { group: 'couchbase' for group in Config.couchbaseBucketDict } + Config.mapping_locations = { group: 'couchbase' for group in Config.couchbaseBucketDict } if Config.rdbm_install: - Config.mappingLocations = { group: 'rdbm' for group in Config.couchbaseBucketDict } + Config.mapping_locations = { group: 'rdbm' for group in Config.couchbaseBucketDict } if Config.opendj_install == InstallTypes.LOCAL and not Config.installed_instance: used_ports = self.opendj_used_ports() @@ -205,12 +205,12 @@ def load_properties(self, prop_file, no_update=[]): continue try: setattr(Config, prop, p[prop]) - if prop == 'mappingLocations': - mappingLocations = json.loads(p[prop]) - setattr(Config, prop, mappingLocations) - for l in mappingLocations: - if not mappingLocations[l] in map_db: - map_db.append(mappingLocations[l]) + if prop == 'mapping_locations': + mapping_locations = json.loads(p[prop]) + setattr(Config, prop, mapping_locations) + for l in mapping_locations: + if not mapping_locations[l] in map_db: + map_db.append(mapping_locations[l]) if p[prop] == 'True': setattr(Config, prop, True) @@ -307,7 +307,7 @@ def getString(value): if not obj_name.startswith('__') and (not callable(obj)): - if obj_name == 'mappingLocations': + if obj_name == 'mapping_locations': p[obj_name] = json.dumps(obj) else: value = getString(obj) @@ -488,7 +488,7 @@ def promptForBackendMappings(self): couchbase_mappings.remove(m) for m in couchbase_mappings: - Config.mappingLocations[m] = 'couchbase' + Config.mapping_locations[m] = 'couchbase' def set_persistence_type(self): if Config.opendj_install and (not Config.cb_install) and (not Config.rdbm_install): @@ -518,20 +518,20 @@ def promptForHTTPD(self): def promptForScimServer(self): - if Config.installed_instance and Config.installScimServer: + if Config.installed_instance and Config.install_scim_server: return promptForScimServer = self.getPrompt("Install Scim Server?", - self.getDefaultOption(Config.installScimServer) + self.getDefaultOption(Config.install_scim_server) )[0].lower() if promptForScimServer == 'y': - Config.installScimServer = True + Config.install_scim_server = True else: - Config.installScimServer = False + Config.install_scim_server = False - if Config.installed_instance and Config.installScimServer: - Config.addPostSetupService.append('installScimServer') + if Config.installed_instance and Config.install_scim_server: + Config.addPostSetupService.append('install_scim_server') def promptForFido2Server(self): if Config.installed_instance and Config.installFido2: @@ -585,17 +585,17 @@ def promptForEleven(self): def promptForConfigApi(self): - if Config.installed_instance and Config.installConfigApi: + if Config.installed_instance and Config.install_config_api: return promptForConfigApi = self.getPrompt("Install Jans Auth Config Api?", - self.getDefaultOption(Config.installConfigApi) + self.getDefaultOption(Config.install_config_api) )[0].lower() - Config.installConfigApi = True if promptForConfigApi == 'y' else False + Config.install_config_api = True if promptForConfigApi == 'y' else False - if Config.installed_instance and Config.installConfigApi: - Config.addPostSetupService.append('installConfigApi') + if Config.installed_instance and Config.install_config_api: + Config.addPostSetupService.append('install_config_api') def prompt_for_rdbm(self): while True: @@ -715,7 +715,7 @@ def prompt_for_backend(self): print("Password must be at least 6 characters and include one uppercase letter, one lowercase letter, one digit, and one special character.") Config.cb_password = cbPass - Config.mappingLocations = { group: 'couchbase' for group in Config.couchbaseBucketDict } + Config.mapping_locations = { group: 'couchbase' for group in Config.couchbaseBucketDict } elif backend_type_str == 'Remote Couchbase': Config.opendj_install = InstallTypes.NONE @@ -729,7 +729,7 @@ def prompt_for_backend(self): if result['result']: break - Config.mappingLocations = { group: 'couchbase' for group in Config.couchbaseBucketDict } + Config.mapping_locations = { group: 'couchbase' for group in Config.couchbaseBucketDict } elif backend_type_str == 'Local MySQL': Config.opendj_install = InstallTypes.NONE diff --git a/jans-linux-setup/jans_setup/setup_app/utils/setup_utils.py b/jans-linux-setup/jans_setup/setup_app/utils/setup_utils.py index 3c9404c4474..8f35138e68c 100644 --- a/jans-linux-setup/jans_setup/setup_app/utils/setup_utils.py +++ b/jans-linux-setup/jans_setup/setup_app/utils/setup_utils.py @@ -354,8 +354,8 @@ def deleteLdapPw(self): def getMappingType(self, mtype): location = [] - for group in Config.mappingLocations: - if group != 'default' and Config.mappingLocations[group] == mtype: + for group in Config.mapping_locations: + if group != 'default' and Config.mapping_locations[group] == mtype: location.append(group) return location @@ -385,9 +385,9 @@ def fomatWithDict(self, text, dictionary): return text % dictionary - def renderTemplateInOut(self, filePath, templateFolder, output_dir, me='', pystring=False): - fn = os.path.basename(filePath) - in_fp = os.path.join(templateFolder, fn) + def renderTemplateInOut(self, file_path, template_folder, output_dir, pystring=False): + fn = os.path.basename(file_path) + in_fp = os.path.join(template_folder, fn) self.logIt("Rendering template %s" % in_fp) template_text = self.readFile(in_fp) @@ -517,16 +517,16 @@ def in_ignoredirs(p): output_dir = rp.parent template_name = rp.name - fullOutputDir = Path(Config.output_dir, output_dir) - fullOutputFile = Path(Config.output_dir, rp) + full_output_dir = Path(Config.output_dir, output_dir) + full_output_file = Path(Config.output_dir, rp) - if not fullOutputDir.exists(): - fullOutputDir.mkdir(parents=True, exist_ok=True) + if not full_output_dir.exists(): + full_output_dir.mkdir(parents=True, exist_ok=True) template_text = te.read_text() rendered_text = template_text % self.merge_dicts(Config.templateRenderingDict, Config.__dict__) - self.logIt("Writing rendered template {}".format(fullOutputFile)) - fullOutputFile.write_text(rendered_text) + self.logIt("Writing rendered template {}".format(full_output_file)) + full_output_file.write_text(rendered_text) def add_yacron_job(self, command, schedule, name=None, args={}): import ruamel.yaml @@ -567,3 +567,11 @@ def opendj_used_ports(self): if self.port_used(port): ports.append(port) return ports + + def chown(self, fn, user, group=None, recursive=False): + cmd = [paths.cmd_chown] + if recursive: + cmd.append('-R') + usr_grp = '{}:{}'.format(user, group) if group else user + cmd += [usr_grp, fn] + self.run(cmd) diff --git a/jans-linux-setup/tools/ldap2mysql/ldap2mysql.py b/jans-linux-setup/tools/ldap2mysql/ldap2mysql.py index 7461a259409..fd87701deb8 100755 --- a/jans-linux-setup/tools/ldap2mysql/ldap2mysql.py +++ b/jans-linux-setup/tools/ldap2mysql/ldap2mysql.py @@ -157,7 +157,7 @@ Config.opendj_install = static.InstallTypes.NONE Config.rdbm_install = static.InstallTypes.REMOTE -Config.mappingLocations = { group: 'rdbm' for group in Config.couchbaseBucketDict } +Config.mapping_locations = { group: 'rdbm' for group in Config.couchbaseBucketDict } rdbmInstaller.dbUtils.bind(force=True) propertiesUtils.set_persistence_type()