Skip to content

Commit

Permalink
feat: add main() function
Browse files Browse the repository at this point in the history
  • Loading branch information
devrimyatar committed Feb 7, 2022
1 parent 165ac35 commit 01f118c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 62 deletions.
127 changes: 66 additions & 61 deletions flex-linux-setup/flex_linux_setup/flex_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,64 +56,69 @@
httpdInstaller = HttpdInstaller()
configApiInstaller = ConfigApiInstaller()

if not node_installer.installed():
node_fn = 'node-{0}-linux-x64.tar.xz'.format(app_versions['NODE_VERSION'])
node_path = os.path.join(Config.distAppFolder, node_fn)
if not os.path.exists(node_path):
print("Downloading", node_fn)
base.download('https://nodejs.org/dist/{0}/node-{0}-linux-x64.tar.xz'.format(app_versions['NODE_VERSION']), node_path)
print("Installing node")
node_installer.install()


gluu_admin_ui_source_path = os.path.join(Config.distJansFolder, 'gluu-admin-ui.zip')
log4j2_adminui_path = os.path.join(Config.distJansFolder, 'log4j2-adminui.xml')
log4j2_path = os.path.join(Config.distJansFolder, 'log4j2.xml')
admin_ui_plugin_source_path = os.path.join(Config.distJansFolder, 'admin-ui-plugin-distribution.jar')
flex_path = os.path.join(Config.distJansFolder, 'flex.zip')
source_dir = os.path.join(Config.outputFolder, 'admin-ui')
flex_setup_dir = os.path.join(source_dir, 'flex-linux-setup')
admin_ui_config_properties_path = os.path.join(flex_setup_dir, 'auiConfiguration.properties')

print("Downloading components")
base.download(urljoin(maven_base_url, 'admin-ui-plugin/{0}{1}/admin-ui-plugin-{0}{1}-distribution.jar'.format(app_versions['JANS_APP_VERSION'], app_versions['JANS_BUILD'])), admin_ui_plugin_source_path)
base.download('https://raw.githubusercontent.com/JanssenProject/jans/{}/jans-config-api/server/src/main/resources/log4j2.xml'.format(app_versions['JANS_BRANCH']), log4j2_path)
base.download('https://raw.githubusercontent.com/JanssenProject/jans/{}/jans-config-api/plugins/admin-ui-plugin/config/log4j2-adminui.xml'.format(app_versions['JANS_BRANCH']), log4j2_adminui_path)
base.download('https://github.com/GluuFederation/flex/archive/refs/heads/{}.zip'.format(app_versions['FLEX_BRANCH']), flex_path)


print("Installing Gluu Admin UI Frontend")

print("Extracting admin-ui from", flex_path)
base.extract_from_zip(flex_path, 'admin-ui', source_dir)
base.extract_from_zip(flex_path, 'flex-linux-setup/flex_linux_setup', flex_setup_dir)

configApiInstaller.renderTemplateInOut(os.path.join(source_dir, '.env.tmp'), source_dir, source_dir)
configApiInstaller.copyFile(os.path.join(source_dir, '.env.tmp'), os.path.join(source_dir, '.env'))
configApiInstaller.run([paths.cmd_chown, '-R', 'node:node', source_dir])
cmd_path = 'PATH=$PATH:{}/bin:{}/bin'.format(Config.jre_home, Config.node_home)

for cmd in ('npm install @openapitools/openapi-generator-cli', 'npm run api', 'npm install', 'npm run build:prod'):
print("Executing `{}`".format(cmd))
run_cmd = '{} {}'.format(cmd_path, cmd)
configApiInstaller.run(['/bin/su', 'node','-c', run_cmd], source_dir)

target_dir = os.path.join(httpdInstaller.server_root, 'admin')
print("Copying files to", target_dir)
configApiInstaller.copyTree(os.path.join(source_dir, 'dist'), target_dir)

configApiInstaller.check_clients([('role_based_client_id', '2000.')])

configApiInstaller.renderTemplateInOut(admin_ui_config_properties_path, flex_setup_dir, configApiInstaller.custom_config_dir)
admin_ui_plugin_path = os.path.join(configApiInstaller.libDir, os.path.basename(admin_ui_plugin_source_path))
configApiInstaller.web_app_xml_fn = os.path.join(configApiInstaller.jetty_base, configApiInstaller.service_name, 'webapps/jans-config-api.xml')
configApiInstaller.copyFile(admin_ui_plugin_source_path, configApiInstaller.libDir)
configApiInstaller.add_extra_class(admin_ui_plugin_path)

for logfn in (log4j2_adminui_path, log4j2_path):
configApiInstaller.copyFile(logfn, configApiInstaller.custom_config_dir)

print("Restarting Janssen Config Api")
configApiInstaller.restart()

print("Installation was completed. Browse https://{}/admin".format(Config.hostname))
def main():

if not node_installer.installed():
node_fn = 'node-{0}-linux-x64.tar.xz'.format(app_versions['NODE_VERSION'])
node_path = os.path.join(Config.distAppFolder, node_fn)
if not os.path.exists(node_path):
print("Downloading", node_fn)
base.download('https://nodejs.org/dist/{0}/node-{0}-linux-x64.tar.xz'.format(app_versions['NODE_VERSION']), node_path)
print("Installing node")
node_installer.install()


gluu_admin_ui_source_path = os.path.join(Config.distJansFolder, 'gluu-admin-ui.zip')
log4j2_adminui_path = os.path.join(Config.distJansFolder, 'log4j2-adminui.xml')
log4j2_path = os.path.join(Config.distJansFolder, 'log4j2.xml')
admin_ui_plugin_source_path = os.path.join(Config.distJansFolder, 'admin-ui-plugin-distribution.jar')
flex_path = os.path.join(Config.distJansFolder, 'flex.zip')
source_dir = os.path.join(Config.outputFolder, 'admin-ui')
flex_setup_dir = os.path.join(source_dir, 'flex-linux-setup')
admin_ui_config_properties_path = os.path.join(flex_setup_dir, 'auiConfiguration.properties')

print("Downloading components")
base.download(urljoin(maven_base_url, 'admin-ui-plugin/{0}{1}/admin-ui-plugin-{0}{1}-distribution.jar'.format(app_versions['JANS_APP_VERSION'], app_versions['JANS_BUILD'])), admin_ui_plugin_source_path)
base.download('https://raw.githubusercontent.com/JanssenProject/jans/{}/jans-config-api/server/src/main/resources/log4j2.xml'.format(app_versions['JANS_BRANCH']), log4j2_path)
base.download('https://raw.githubusercontent.com/JanssenProject/jans/{}/jans-config-api/plugins/admin-ui-plugin/config/log4j2-adminui.xml'.format(app_versions['JANS_BRANCH']), log4j2_adminui_path)
base.download('https://github.com/GluuFederation/flex/archive/refs/heads/{}.zip'.format(app_versions['FLEX_BRANCH']), flex_path)


print("Installing Gluu Admin UI Frontend")

print("Extracting admin-ui from", flex_path)
base.extract_from_zip(flex_path, 'admin-ui', source_dir)
base.extract_from_zip(flex_path, 'flex-linux-setup/flex_linux_setup', flex_setup_dir)

configApiInstaller.renderTemplateInOut(os.path.join(source_dir, '.env.tmp'), source_dir, source_dir)
configApiInstaller.copyFile(os.path.join(source_dir, '.env.tmp'), os.path.join(source_dir, '.env'))
configApiInstaller.run([paths.cmd_chown, '-R', 'node:node', source_dir])
cmd_path = 'PATH=$PATH:{}/bin:{}/bin'.format(Config.jre_home, Config.node_home)

for cmd in ('npm install @openapitools/openapi-generator-cli', 'npm run api', 'npm install', 'npm run build:prod'):
print("Executing `{}`".format(cmd))
run_cmd = '{} {}'.format(cmd_path, cmd)
configApiInstaller.run(['/bin/su', 'node','-c', run_cmd], source_dir)

target_dir = os.path.join(httpdInstaller.server_root, 'admin')
print("Copying files to", target_dir)
configApiInstaller.copyTree(os.path.join(source_dir, 'dist'), target_dir)

configApiInstaller.check_clients([('role_based_client_id', '2000.')])

configApiInstaller.renderTemplateInOut(admin_ui_config_properties_path, flex_setup_dir, configApiInstaller.custom_config_dir)
admin_ui_plugin_path = os.path.join(configApiInstaller.libDir, os.path.basename(admin_ui_plugin_source_path))
configApiInstaller.web_app_xml_fn = os.path.join(configApiInstaller.jetty_base, configApiInstaller.service_name, 'webapps/jans-config-api.xml')
configApiInstaller.copyFile(admin_ui_plugin_source_path, configApiInstaller.libDir)
configApiInstaller.add_extra_class(admin_ui_plugin_path)

for logfn in (log4j2_adminui_path, log4j2_path):
configApiInstaller.copyFile(logfn, configApiInstaller.custom_config_dir)

print("Restarting Janssen Config Api")
configApiInstaller.restart()

print("Installation was completed. Browse https://{}/admin".format(Config.hostname))

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion flex-linux-setup/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ def find_version(*file_paths):
include_package_data=True,
packages=['flex_linux_setup'],
entry_points={
"console_scripts": ["jans-flex-setup=flex_linux_setup:flex_setup"],
"console_scripts": ["jans-flex-setup=flex_linux_setup:flex_setup.main"],
},
)

0 comments on commit 01f118c

Please sign in to comment.