Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: jans linux setup enable/disable script via arg #1634

Merged
merged 2 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions jans-linux-setup/jans_setup/jans_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ def ami_packaged():
if Config.profile != 'jans':
argsp.t = False

if os.path.exists(Config.jans_properties_fn):
Config.installed_instance = True

# we must initilize SetupUtils after initilizing Config
SetupUtils.init()

Expand All @@ -167,7 +170,7 @@ def ami_packaged():
except:
argsp.no_progress = True

if not argsp.n:
if not (argsp.n or Config.installed_instance):
base.check_resources()

# pass progress indicator to Config object
Expand All @@ -179,17 +182,18 @@ def ami_packaged():
jansInstaller = JansInstaller()
jansInstaller.initialize()

print()
detected_os = '{} {}'.format(base.os_type, base.os_version)
if base.snap:
detected_os = 'snap ' + detected_os
print("Installing Janssen Server...\n\nFor more info see:\n {} \n {}\n".format(paths.LOG_FILE, paths.LOG_ERROR_FILE))
print("Profile : {}".format(Config.profile))
print("Detected OS : {}".format(detected_os))
print("Janssen Version : {}".format(base.current_app.app_info['ox_version']))
print("Detected init : {}".format(base.os_initdaemon))
print("Detected Apache : {}".format(base.determineApacheVersion()))
print()
if not Config.installed_instance:
print()
detected_os = '{} {}'.format(base.os_type, base.os_version)
if base.snap:
detected_os = 'snap ' + detected_os
print("Installing Janssen Server...\n\nFor more info see:\n {} \n {}\n".format(paths.LOG_FILE, paths.LOG_ERROR_FILE))
print("Profile : {}".format(Config.profile))
print("Detected OS : {}".format(detected_os))
print("Janssen Version : {}".format(base.current_app.app_info['ox_version']))
print("Detected init : {}".format(base.os_initdaemon))
print("Detected Apache : {}".format(base.determineApacheVersion()))
print()

setup_loaded = {}
if setupOptions['setup_properties']:
Expand All @@ -212,7 +216,6 @@ def ami_packaged():
if os.path.exists(Config.jans_properties_fn):
collectProperties.collect()
collectProperties.save()
Config.installed_instance = True

if argsp.csx:
print("Saving collected properties")
Expand Down Expand Up @@ -249,6 +252,18 @@ def ami_packaged():
rdbmInstaller.packageUtils = packageUtils

if Config.installed_instance:

if argsp.enable_script:
print("Enabling scripts {}".format(', '.join(argsp.enable_script)))
jansInstaller.enable_scripts(argsp.enable_script)
sys.exit()

if argsp.disable_script:
print("Disabling scripts {}".format(', '.join(argsp.disable_script)))
jansInstaller.enable_scripts(argsp.disable_script, enable=False)
sys.exit()


for service in jansProgress.services:
setattr(Config, service['object'].install_var, service['object'].installed())

Expand Down
11 changes: 10 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 @@ -432,8 +432,9 @@ def post_install_tasks(self):

self.deleteLdapPw()

self.dbUtils.bind(force=True)

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

if base.snap:
Expand Down Expand Up @@ -504,3 +505,11 @@ def post_install_tasks(self):
site_file.write(gluu_site_dir)
self.logIt("Copying site packages to {}".format(gluu_site_dir))
shutil.copytree(p, gluu_site_dir, dirs_exist_ok=True)

#enable scripts
self.enable_scripts(base.argsp.enable_script)

def enable_scripts(self, inums, enable=True):
if inums:
for inum in inums:
self.dbUtils.enable_script(inum, enable)
3 changes: 3 additions & 0 deletions jans-linux-setup/jans_setup/setup_app/utils/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
parser.add_argument('--cli-test-client', help="Use config api test client for CLI", action='store_true')
parser.add_argument('--import-ldif', help="Render ldif templates from directory and import them in Database")

parser.add_argument('-enable-script', action='append', help="inum of script to enable", required=False)
parser.add_argument('-disable-script', action='append', help="inum of script to enable", required=False)

if PROFILE != OPENBANKING_PROFILE:

parser.add_argument('-stm', '--enable-scim-test-mode', help="Enable Scim Test Mode", action='store_true')
Expand Down
8 changes: 4 additions & 4 deletions jans-linux-setup/jans_setup/setup_app/utils/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,26 +240,26 @@ def set_oxAuthConfDynamic(self, entries):
self.cbm.exec_query(n1ql)


def enable_script(self, inum):
def enable_script(self, inum, enable=True):
base.logIt("Enabling script {}".format(inum))
if self.moddb == BackendTypes.LDAP:
ldap_operation_result = self.ldap_conn.modify(
'inum={},ou=scripts,o=jans'.format(inum),
{"jansEnabled": [ldap3.MODIFY_REPLACE, 'true']}
{"jansEnabled": [ldap3.MODIFY_REPLACE, str(enable).lower()]}
)
self.log_ldap_result(ldap_operation_result)

elif self.moddb in (BackendTypes.MYSQL, BackendTypes.PGSQL):
dn = 'inum={},ou=scripts,o=jans'.format(inum)
sqlalchemyObj = self.get_sqlalchObj_for_dn(dn)
sqlalchemyObj.jansEnabled = 1
sqlalchemyObj.jansEnabled = 1 if enable else 0
self.session.commit()

elif self.moddb == BackendTypes.SPANNER:
dn = 'inum={},ou=scripts,o=jans'.format(inum)
table = self.get_spanner_table_for_dn(dn)
if table:
self.spanner.update_data(table=table, columns=['doc_id', 'jansEnabled'], values=[[inum, True]])
self.spanner.update_data(table=table, columns=['doc_id', 'jansEnabled'], values=[[inum, enable]])

elif self.moddb == BackendTypes.COUCHBASE:
n1ql = 'UPDATE `{}` USE KEYS "scripts_{}" SET jansEnabled=true'.format(self.default_bucket, inum)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ def check_properties(self):
Config.jans_max_mem = int(base.current_mem_size * .83 * 1000) # 83% of physical memory


print(Config.cb_install, Config.rdbm_install, Config.opendj_install)


def check_oxd_server_https(self):

if Config.get('oxd_server_https'):
Expand Down Expand Up @@ -207,6 +204,9 @@ def load_properties(self, prop_file, no_update=[]):
if p.get('opendj_install') == '0':
p['opendj_install'] = InstallTypes.NONE

if p.get('enable-script'):
base.argsp.enable_script = p['enable-script'].split()

properties_list = list(p.keys())

for prop in properties_list:
Expand Down