Skip to content

Commit

Permalink
feat(jans-linux-setup): import custom ldif (#873)
Browse files Browse the repository at this point in the history
* feat: import custom ldif

* fix: jans-linux-setup remove unused module

* fix: jans-linux-setup add missing  prepare_jans_cli_package() to install.py
  • Loading branch information
devrimyatar authored Feb 22, 2022
1 parent 8346517 commit 363cf0e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions jans-linux-setup/jans_setup/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ def extract_yaml_files():
extract_file(jans_zip_file, 'jans-scim/server/src/main/resources/jans-scim-openapi.yaml', os.path.join(setup_dir, 'setup_app/data'))
extract_file(jans_zip_file, 'jans-config-api/server/src/main/resources/log4j2.xml', jans_app_dir)

def prepare_jans_cli_package():
print("Preparing jans-cli package")
extract_subdir(jans_zip_file, 'jans-cli', 'jans-cli', os.path.join(jans_app_dir, 'jans-cli.zip'))

def uninstall_jans():
check_installation()
Expand Down
6 changes: 6 additions & 0 deletions jans-linux-setup/jans_setup/jans_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ def ami_packaged():
base.logIt('%s Properties found!\n' % Config.setup_properties_fn + '.enc')
setup_loaded = propertiesUtils.load_properties(Config.setup_properties_fn + '.enc')

if argsp.import_ldif:
if os.path.isdir(argsp.import_ldif):
base.logIt("Found setup LDIF import directory {}".format(argsp.import_ldif))
else:
base.logIt("The custom LDIF import directory {} does not exist. Exiting...".format(argsp.import_ldif, True, True))

collectProperties = CollectProperties()
if os.path.exists(Config.jans_properties_fn):
collectProperties.collect()
Expand Down
38 changes: 37 additions & 1 deletion jans-linux-setup/jans_setup/setup_app/installers/jans.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,46 @@ def copy_output(self):
except:
self.logIt("Error writing %s to %s" % (output_fn, dest_fn), True)


def render_custom_templates(self, ldif_dir):
output_dir_p = Path(ldif_dir + '.output')
self.logIt("Rendering custom templates from {} to {}".format(ldif_dir, output_dir_p))

for p in Path(ldif_dir).rglob('*'):
if p.is_file():
out_file_p = output_dir_p.joinpath(p.relative_to(ldif_dir))
if not out_file_p.parent.exists():
out_file_p.parent.mkdir(parents=True)
try:
self.renderTemplateInOut(p.as_posix(), p.parent.as_posix(), out_file_p.parent.as_posix())
except Exception:
self.logIt("Error writing template {}".format(out_file_p), True)


def import_custom_ldif_dir(self, ldif_dir):
ldif_dir = ldif_dir.rstrip('/')
self.logIt("Importing Custom LDIF files", pbar='post-setup')
self.render_custom_templates(ldif_dir)

output_dir = ldif_dir + '.output'

for p in Path(output_dir).rglob('*.ldif'):
ldif = p.as_posix()
self.logIt("Importing rendered custom ldif {}".format(ldif))
try:
self.dbUtils.import_ldif([ldif])
except Exception:
self.logIt("Error importing custom ldif file {}".format(ldif), True)


def post_install_tasks(self):

self.deleteLdapPw()

if base.argsp.import_ldif:
self.dbUtils.bind(force=True)
self.import_custom_ldif_dir(base.argsp.import_ldif)

if base.snap:
#write post-install.py script
self.logIt("Writing snap-post-setup.py", pbar='post-setup')
Expand All @@ -389,7 +425,7 @@ def post_install_tasks(self):
('{{SNAP}}', base.snap),
('{{SNAP_COMMON}}', base.snap_common)
):

post_setup_script = post_setup_script.replace(key, val)

post_setup_script_fn = os.path.join(Config.install_dir, 'snap-post-setup.py')
Expand Down

0 comments on commit 363cf0e

Please sign in to comment.