From 728673e7338e5fc77bfc4ea1d62f974d4c0a95bc Mon Sep 17 00:00:00 2001 From: Mustafa Baser Date: Wed, 28 Sep 2022 13:49:25 +0300 Subject: [PATCH 1/2] fix: jans-linux-setup scan docs/script-catalog for custom scripts --- .../jans_setup/setup_app/config.py | 1 + .../jans_setup/setup_app/installers/jans.py | 4 +++ .../jans_setup/setup_app/utils/crypto64.py | 28 +++++++++++-------- .../jans_setup/templates/scripts.ldif | 2 +- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/jans-linux-setup/jans_setup/setup_app/config.py b/jans-linux-setup/jans_setup/setup_app/config.py index 27612ae7037..afd2610eec6 100644 --- a/jans-linux-setup/jans_setup/setup_app/config.py +++ b/jans-linux-setup/jans_setup/setup_app/config.py @@ -248,6 +248,7 @@ def progress(self, service_name, msg, incr=False): self.staticFolder = os.path.join(self.install_dir, 'static') self.extensionFolder = os.path.join(self.staticFolder, 'extension') + self.script_catalog_dir = os.path.join(self.install_dir, 'script_catalog') self.encoded_ldapTrustStorePass = None 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 29b56e4f439..33f7bc5385a 100644 --- a/jans-linux-setup/jans_setup/setup_app/installers/jans.py +++ b/jans-linux-setup/jans_setup/setup_app/installers/jans.py @@ -129,6 +129,7 @@ def initialize(self): else: self.logIt("Key generator path was determined as {}".format(Config.non_setup_properties['key_export_path'])) + self.extract_scripts() def configureSystem(self): self.logIt("Configuring system", 'jans') @@ -522,3 +523,6 @@ def enable_scripts(self, inums, enable=True): if inums: for inum in inums: self.dbUtils.enable_script(inum, enable) + + def extract_scripts(self): + base.extract_from_zip(base.current_app.jans_zip, 'docs/script-catalog', Config.script_catalog_dir) diff --git a/jans-linux-setup/jans_setup/setup_app/utils/crypto64.py b/jans-linux-setup/jans_setup/setup_app/utils/crypto64.py index 26a158eaafd..7304074fcf8 100644 --- a/jans-linux-setup/jans_setup/setup_app/utils/crypto64.py +++ b/jans-linux-setup/jans_setup/setup_app/utils/crypto64.py @@ -158,19 +158,23 @@ def gen_key_cert_from_ca(self, fn_suffix, ca_suffix='ca', cn=None): def prepare_base64_extension_scripts(self, extensions=[]): self.logIt("Preparing scripts") + # Remove extension_path when all scripts are moved to script_catalog_dir extension_path = Path(Config.extensionFolder) - for ep in extension_path.glob("**/*"): - if ep.is_file() and ep.suffix.lower() in ['.py', '.java']: - extension_type = ep.relative_to(Config.extensionFolder).parent.as_posix().lower().replace(os.path.sep, '_') - extension_name = ep.stem.lower() - extension_script_name = '{}_{}'.format(extension_type, extension_name) - - if extensions and extension_script_name in extensions: - continue - - # Prepare key for dictionary - base64_script_file = self.generate_base64_file(ep.as_posix(), 1) - Config.templateRenderingDict[extension_script_name] = base64_script_file + catalog_path = Path(Config.script_catalog_dir) + for path_ in (Config.extensionFolder, Config.script_catalog_dir): + extension_path = Path(path_) + for ep in extension_path.glob("**/*"): + if ep.is_file() and ep.suffix.lower() in ['.py', '.java']: + extension_type = ep.relative_to(path_).parent.as_posix().lower().replace(os.path.sep, '_').replace('-','_') + extension_name = ep.stem.lower() + extension_script_name = '{}_{}'.format(extension_type, extension_name) + + if extensions and extension_script_name in extensions: + continue + + # Prepare key for dictionary + base64_script_file = self.generate_base64_file(ep.as_posix(), 1) + Config.templateRenderingDict[extension_script_name] = base64_script_file def generate_base64_file(self, fn, num_spaces): diff --git a/jans-linux-setup/jans_setup/templates/scripts.ldif b/jans-linux-setup/jans_setup/templates/scripts.ldif index bb767f52478..d2e449c2bd8 100644 --- a/jans-linux-setup/jans_setup/templates/scripts.ldif +++ b/jans-linux-setup/jans_setup/templates/scripts.ldif @@ -272,7 +272,7 @@ jansLevel: 50 jansModuleProperty: {"value1":"usage_type","value2":"interactive","description":""} jansModuleProperty: {"value1":"location_type","value2":"ldap","description":""} jansRevision: 1 -jansScr::%(person_authentication_duoexternalauthenticator)s +jansScr::%(person_authentication_duo_external_authenticator_duoexternalauthenticator)s jansScrTyp: person_authentication objectClass: top objectClass: jansCustomScr From bcb3721cedbb1a43dd2c9f5e9b6f9efee9714945 Mon Sep 17 00:00:00 2001 From: Mustafa Baser Date: Wed, 28 Sep 2022 14:01:28 +0300 Subject: [PATCH 2/2] fix: jans-linux-setup code smells --- jans-linux-setup/jans_setup/setup_app/utils/crypto64.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/jans-linux-setup/jans_setup/setup_app/utils/crypto64.py b/jans-linux-setup/jans_setup/setup_app/utils/crypto64.py index 7304074fcf8..0e9afc69b8e 100644 --- a/jans-linux-setup/jans_setup/setup_app/utils/crypto64.py +++ b/jans-linux-setup/jans_setup/setup_app/utils/crypto64.py @@ -158,9 +158,7 @@ def gen_key_cert_from_ca(self, fn_suffix, ca_suffix='ca', cn=None): def prepare_base64_extension_scripts(self, extensions=[]): self.logIt("Preparing scripts") - # Remove extension_path when all scripts are moved to script_catalog_dir - extension_path = Path(Config.extensionFolder) - catalog_path = Path(Config.script_catalog_dir) + # Remove extensionFolder when all scripts are moved to script_catalog_dir for path_ in (Config.extensionFolder, Config.script_catalog_dir): extension_path = Path(path_) for ep in extension_path.glob("**/*"):