Skip to content

Commit

Permalink
fix: jans-linux-setup code smell
Browse files Browse the repository at this point in the history
  • Loading branch information
devrimyatar committed Apr 30, 2022
1 parent 3837dd2 commit 3c57d5e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 26 deletions.
4 changes: 2 additions & 2 deletions jans-linux-setup/jans_setup/openbanking/setup_app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Config:
osDefault = '/etc/default'
sysemProfile = '/etc/profile'
jython_home = '/opt/jython'
ldapBaseFolder = '/opt/opendj'
ldap_base_dir = '/opt/opendj'
network = '/etc/sysconfig/network'
jetty_home = '/opt/jetty'
jetty_base = os.path.join(jansOptFolder, 'jetty')
Expand Down Expand Up @@ -69,7 +69,7 @@ def init(self, install_dir=INSTALL_DIR):

self.ox_version = self.app_info['JANS_APP_VERSION'] + self.app_info['JANS_BUILD']
self.data_dir = os.path.join(self.install_dir, 'setup_app/data')
self.ldapBinFolder = os.path.join(self.ldapBaseFolder, 'bin')
self.ldap_bin_dir = os.path.join(self.ldap_base_dir, 'bin')

self.thread_queue = None
self.jetty_user = 'jetty'
Expand Down
10 changes: 4 additions & 6 deletions jans-linux-setup/jans_setup/setup_app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Config:
osDefault = '/etc/default'
sysemProfile = '/etc/profile'
jython_home = '/opt/jython'
ldapBaseFolder = '/opt/opendj'
ldap_base_dir = '/opt/opendj'
network = '/etc/sysconfig/network'
jetty_home = '/opt/jetty'
node_home = '/opt/node'
Expand Down Expand Up @@ -82,9 +82,9 @@ def init(self, install_dir=INSTALL_DIR):
if not self.outputFolder:
self.outputFolder = os.path.join(install_dir, 'output')

self.ldapBinFolder = os.path.join(self.ldapBaseFolder, 'bin')
self.ldap_bin_dir = os.path.join(self.ldap_base_dir, 'bin')
if base.snap:
self.ldapBaseFolder = os.path.join(base.snap_common, 'opendj')
self.ldap_base_dir = os.path.join(base.snap_common, 'opendj')
self.jetty_user = 'root'

#create dummy progress bar that logs to file in case not defined
Expand Down Expand Up @@ -223,8 +223,6 @@ def progress(self, service_name, msg, incr=False):
self.jans_max_mem = int(base.current_mem_size * .85 * 1000) # 85% of physical memory
self.calculate_mem()

self.ldapBaseFolderldapPass = None

self.templateFolder = os.path.join(self.install_dir, 'templates')
self.staticFolder = os.path.join(self.install_dir, 'static')

Expand All @@ -246,7 +244,7 @@ def progress(self, service_name, msg, incr=False):
self.ldaps_port = '1636'
self.ldap_admin_port = '4444'

self.ldap_user_home = self.ldapBaseFolder
self.ldap_user_home = self.ldap_base_dir
self.ldapPassFn = os.path.join(self.ldap_user_home, '.pw')
self.ldap_backend_type = 'je'

Expand Down
30 changes: 15 additions & 15 deletions jans-linux-setup/jans_setup/setup_app/installers/opendj.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def __init__(self):
self.register_progess()

self.openDjIndexJson = os.path.join(Config.install_dir, 'static/opendj/index.json')
self.openDjSchemaFolder = os.path.join(Config.ldapBaseFolder, 'config/schema')
self.openDjSchemaFolder = os.path.join(Config.ldap_base_dir, 'config/schema')

self.opendj_service_centos7 = os.path.join(Config.install_dir, 'static/opendj/systemd/opendj.service')
self.ldapDsconfigCommand = os.path.join(Config.ldapBinFolder, 'dsconfig')
self.ldapDsCreateRcCommand = os.path.join(Config.ldapBinFolder, 'create-rc-script')
self.ldapDsconfigCommand = os.path.join(Config.ldap_bin_dir , 'dsconfig')
self.ldapDsCreateRcCommand = os.path.join(Config.ldap_bin_dir , 'create-rc-script')


def install(self):
Expand Down Expand Up @@ -101,7 +101,7 @@ def extractOpenDJ(self):
except:
self.logIt("Error encountered while doing unzip %s -d /opt/" % (opendj_archive))

realLdapBaseFolder = os.path.realpath(Config.ldapBaseFolder)
realLdapBaseFolder = os.path.realpath(Config.ldap_base_dir)
self.run([paths.cmd_chown, '-R', 'ldap:ldap', realLdapBaseFolder])

if Config.opendj_install == InstallTypes.REMOTE:
Expand All @@ -115,17 +115,17 @@ def create_user(self):
def install_opendj(self):
self.logIt("Running OpenDJ Setup")

#if base.snap and not os.path.exists(Config.ldapBaseFolder):
# self.run([paths.cmd_mkdir, Config.ldapBaseFolder])
#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
setupPropsFN = os.path.join(Config.ldapBaseFolder, 'opendj-setup.properties')
setupPropsFN = os.path.join(Config.ldap_base_dir, 'opendj-setup.properties')
shutil.copy("%s/opendj-setup.properties" % Config.outputFolder, setupPropsFN)

self.run([paths.cmd_chown, 'ldap:ldap', setupPropsFN])


ldapSetupCommand = os.path.join(os.path.dirname(Config.ldapBinFolder), 'setup')
ldapSetupCommand = os.path.join(os.path.dirname(Config.ldap_bin_dir ), 'setup')

setupCmd = " ".join([ldapSetupCommand,
'--no-prompt',
Expand All @@ -151,7 +151,7 @@ def install_opendj(self):

try:
self.logIt('Stopping opendj server')
cmd = os.path.join(Config.ldapBinFolder, 'stop-ds')
cmd = os.path.join(Config.ldap_bin_dir , 'stop-ds')
self.run(cmd, shell=True)
except:
self.logIt("Error stopping opendj", True)
Expand All @@ -161,7 +161,7 @@ def set_opendj_java_properties(self, data):

self.logIt("Setting OpenDJ params: {}".format(str(data)))

opendj_java_properties_fn = os.path.join(Config.ldapBaseFolder, 'config/java.properties')
opendj_java_properties_fn = os.path.join(Config.ldap_base_dir, 'config/java.properties')
opendj_java_properties = self.readFile(opendj_java_properties_fn)
opendj_java_properties_list = opendj_java_properties.splitlines()

Expand All @@ -183,9 +183,9 @@ def set_opendj_java_properties(self, data):

def post_install_opendj(self):
try:
os.remove(os.path.join(Config.ldapBaseFolder, 'opendj-setup.properties'))
os.remove(os.path.join(Config.ldap_base_dir, 'opendj-setup.properties'))
except:
self.logIt("Error deleting OpenDJ properties. Make sure %s/opendj-setup.properties is deleted" % Config.ldapBaseFolder)
self.logIt("Error deleting OpenDJ properties. Make sure %s/opendj-setup.properties is deleted" % Config.ldap_base_dir)


def create_backends(self):
Expand All @@ -197,7 +197,7 @@ def create_backends(self):
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:
cwd = os.path.join(Config.ldapBinFolder)
cwd = os.path.join(Config.ldap_bin_dir )
dsconfigCmd = " ".join([
self.ldapDsconfigCommand,
'--trustAll',
Expand Down Expand Up @@ -338,8 +338,8 @@ def prepare_opendj_schema(self):
for schema_file in opendj_schema_files:
self.copyFile(schema_file, self.openDjSchemaFolder)

self.run([paths.cmd_chmod, '-R', 'a+rX', Config.ldapBaseFolder])
self.run([paths.cmd_chown, '-R', 'ldap:ldap', Config.ldapBaseFolder])
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.logIt("Re-starting OpenDj after schema update")
self.stop()
Expand Down
2 changes: 1 addition & 1 deletion jans-linux-setup/jans_setup/setup_app/test_data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def load_test_data(self):
if self.dbUtils.moddb == static.BackendTypes.LDAP:
# Update LDAP schema
Config.pbar.progress(self.service_name, "Updating schema", False)
openDjSchemaFolder = os.path.join(Config.ldapBaseFolder, 'config/schema/')
openDjSchemaFolder = os.path.join(Config.ldap_base_dir, 'config/schema/')
self.copyFile(os.path.join(Config.outputFolder, 'test/jans-auth/schema/102-oxauth_test.ldif'), openDjSchemaFolder)
self.copyFile(os.path.join(Config.outputFolder, 'test/scim-client/schema/103-scim_test.ldif'), openDjSchemaFolder)

Expand Down
2 changes: 1 addition & 1 deletion jans-linux-setup/jans_setup/templates/system_profile_init
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fi
export JAVA_HOME=%(jre_home)s
export OPENDJ_JAVA_HOME=%(jre_home)s

export PATH=$PATH:$JAVA_HOME/bin:$NODE_HOME/bin:%(ldapBaseFolder)s/bin
export PATH=$PATH:$JAVA_HOME/bin:$NODE_HOME/bin:%(ldap_base_dir)s/bin
#####################################################################################################
# End Jans Block #
#####################################################################################################
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export JAVA_HOME=%(jre_home)s
export OPENDJ_JAVA_HOME=%(jre_home)s

export PATH=$PATH:$JAVA_HOME/bin:$NODE_HOME/bin:%(ldapBaseFolder)s/bin
export PATH=$PATH:$JAVA_HOME/bin:$NODE_HOME/bin:%(ldap_base_dir)s/bin
########################################################################
# End Jans Block #
########################################################################

0 comments on commit 3c57d5e

Please sign in to comment.