Skip to content

Commit

Permalink
fix: jans-linux-setup code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
devrimyatar committed May 2, 2022
1 parent 244135d commit b2a48db
Show file tree
Hide file tree
Showing 22 changed files with 169 additions and 141 deletions.
2 changes: 1 addition & 1 deletion jans-linux-setup/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Collection of utilities used by SetupApp.
- `db_utils.py` Database management (both ldap and cocuhbase) class is inclueded `DBUtils` in this file. Since `DBUtils`
class is assigned to `self.dbutils` variable in base class for installers, we generally don't include this module
in installers. Functions in `DBUtils` class automatically determines which database to be used for operations by examining
`mappingLocations` defined in `Config` and populated during install time (or later from `setup.properties`).
`mapping_locations` defined in `Config` and populated during install time (or later from `setup.properties`).
Some most commanly functions are:

- `import_lidf(ldif_files)`: imports to list of ldif files to database. It automatically determines database location
Expand Down
14 changes: 7 additions & 7 deletions jans-linux-setup/jans_setup/jans_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def print_or_log(msg):
print("Exiting ...")
sys.exit()

Config.installJansCli = Config.installConfigApi or Config.installScimServer
Config.install_jans_cli = Config.install_config_api or Config.install_scim_server

app_vars = locals().copy()

Expand Down Expand Up @@ -393,15 +393,15 @@ def do_installation():
not Config.installed_instance and Config.installFido2):
fidoInstaller.start_installation()

if (Config.installed_instance and 'installScimServer' in Config.addPostSetupService) or (
not Config.installed_instance and Config.installScimServer):
if (Config.installed_instance and 'install_scim_server' in Config.addPostSetupService) or (
not Config.installed_instance and Config.install_scim_server):
scimInstaller.start_installation()

if (Config.installed_instance and elevenInstaller.install_var in Config.addPostSetupService) or (
not Config.installed_instance and Config.get(elevenInstaller.install_var)):
elevenInstaller.start_installation()

if Config.installJansCli:
if Config.install_jans_cli:
jansCliInstaller.start_installation()
jansCliInstaller.configure()

Expand Down Expand Up @@ -443,11 +443,11 @@ def do_installation():
if base.current_app.proceed_installation:
do_installation()
print('\n', static.colors.OKGREEN)
if Config.installConfigApi or Config.installScimServer:
if Config.install_config_api or Config.install_scim_server:
msg.installation_completed += "CLI available to manage Jannsen Server:\n"
if Config.installConfigApi:
if Config.install_config_api:
msg.installation_completed += "/opt/jans/jans-cli/config-cli.py\n"
if Config.profile == 'jans' and Config.installScimServer:
if Config.profile == 'jans' and Config.install_scim_server:
msg.installation_completed += "/opt/jans/jans-cli/scim-cli.py"

msg_text = msg.post_installation if Config.installed_instance else msg.installation_completed.format(
Expand Down
4 changes: 2 additions & 2 deletions jans-linux-setup/jans_setup/setup.properties.sample
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ installLdap=True
application_max_ram=

### If you want to install Janssen Config Api, set this to True
installConfigApi=
install_config_api=

### If you want to install Fido2 Server, set this to True
installFido2=

### If you want to install Scim Server, set this to True
installScimServer=
install_scim_server=
15 changes: 9 additions & 6 deletions jans-linux-setup/jans_setup/setup_app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ def init(self, install_dir=INSTALL_DIR):
self.profile = base.current_app.profile

self.thread_queue = None
self.jetty_user = 'jetty'
self.jetty_user = self.jetty_group = 'jetty'
self.root_user = self.root_group = 'root'
self.ldap_user = self.ldap_group = 'ldap'

self.dump_config_on_error = False
if not self.output_dir:
self.output_dir = os.path.join(install_dir, 'output')
Expand Down Expand Up @@ -186,13 +189,13 @@ def progress(self, service_name, msg, incr=False):
self.installSaml = False
self.installPassport = False
self.installJansRadius = False
self.installScimServer = True
self.install_scim_server = True
self.installFido2 = True
self.installConfigApi = True
self.install_config_api = True
self.installCasa = False
self.installOxd = False
self.installEleven = False
self.installJansCli = True
self.install_jans_cli = True
self.loadTestData = False
self.allowPreReleasedFeatures = False

Expand Down Expand Up @@ -394,10 +397,10 @@ def progress(self, service_name, msg, incr=False):

if self.profile == OPENBANKING_PROFILE:
#default locations are rdbm
self.mappingLocations = {'default': 'rdbm'}
self.mapping_locations = {'default': 'rdbm'}
else:
#default locations are OpenDJ
self.mappingLocations = { group: 'ldap' for group in self.couchbaseBucketDict }
self.mapping_locations = { group: 'ldap' for group in self.couchbaseBucketDict }

self.non_setup_properties = {
'oxauth_client_jar_fn': os.path.join(self.dist_jans_dir, 'jans-auth-client-jar-with-dependencies.jar')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self):
self.check_version = False #TODO: remove this when version format is changed to 1.0.0
self.app_type = AppType.SERVICE
self.install_type = InstallOption.OPTONAL
self.install_var = 'installConfigApi'
self.install_var = 'install_config_api'
self.register_progess()


Expand Down
8 changes: 4 additions & 4 deletions jans-linux-setup/jans_setup/setup_app/installers/couchbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def install(self):

couchbase_mappings = self.getMappingType('couchbase')

if Config.mappingLocations['default'] == 'couchbase':
if Config.mapping_locations['default'] == 'couchbase':
self.dbUtils.import_ldif(Config.couchbaseBucketDict['default']['ldif'], Config.couchbase_bucket_prefix)
else:
self.dbUtils.import_ldif([Config.ldif_base], force=BackendTypes.COUCHBASE)
Expand Down Expand Up @@ -288,7 +288,7 @@ def couchbaseDict(self):
bucket = Config.couchbase_bucket_prefix if group == 'default' else Config.couchbase_bucket_prefix + '_' + group
if bucket in Config.couchbase_buckets:
cb_key = 'couchbase_{}_mapping'.format(group)
if Config.mappingLocations[group] == 'couchbase':
if Config.mapping_locations[group] == 'couchbase':
if Config.couchbaseBucketDict[group]['mapping']:
couchbase_mappings.append('bucket.{}_{}.mapping: {}'.format(Config.couchbase_bucket_prefix, group, Config.couchbaseBucketDict[group]['mapping']))
Config.templateRenderingDict[cb_key] = Config.couchbaseBucketDict[group]['mapping']
Expand Down Expand Up @@ -343,13 +343,13 @@ def create_couchbase_buckets(self):

if not Config.couchbase_bucket_prefix in existing_buckets:

if Config.mappingLocations['default'] != 'couchbase':
if Config.mapping_locations['default'] != 'couchbase':
self.couchebaseCreateBucket(Config.couchbase_bucket_prefix, bucketRamsize=100)
else:
bucketRamsize = int((Config.couchbaseBucketDict['default']['memory_allocation']/min_cb_ram)*couchbaseClusterRamsize)
self.couchebaseCreateBucket(Config.couchbase_bucket_prefix, bucketRamsize=bucketRamsize)

if Config.mappingLocations['default'] == 'couchbase':
if Config.mapping_locations['default'] == 'couchbase':
self.couchebaseCreateIndexes(Config.couchbase_bucket_prefix)

for group in couchbase_mappings:
Expand Down
10 changes: 5 additions & 5 deletions jans-linux-setup/jans_setup/setup_app/installers/jans.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ def __repr__(self):

txt += 'Install Apache 2 web server'.ljust(30) + repr(Config.installHttpd).rjust(35) + (' *' if 'installHttpd' in Config.addPostSetupService else '') + "\n"
txt += 'Install Auth Server'.ljust(30) + repr(Config.installOxAuth).rjust(35) + "\n"
txt += 'Install Jans Auth Config Api'.ljust(30) + repr(Config.installConfigApi).rjust(35) + "\n"
txt += 'Install Jans Auth Config Api'.ljust(30) + repr(Config.install_config_api).rjust(35) + "\n"
if Config.profile == 'jans':
txt += 'Install Fido2 Server'.ljust(30) + repr(Config.installFido2).rjust(35) + (' *' if 'installFido2' in Config.addPostSetupService else '') + "\n"
txt += 'Install Scim Server'.ljust(30) + repr(Config.installScimServer).rjust(35) + (' *' if 'installScimServer' in Config.addPostSetupService else '') + "\n"
txt += 'Install Scim Server'.ljust(30) + repr(Config.install_scim_server).rjust(35) + (' *' if 'install_scim_server' in Config.addPostSetupService else '') + "\n"
txt += 'Install Eleven Server'.ljust(30) + repr(Config.installEleven).rjust(35) + (' *' if 'installEleven' in Config.addPostSetupService else '') + "\n"
#txt += 'Install Oxd '.ljust(30) + repr(Config.installOxd).rjust(35) + (' *' if 'installOxd' in Config.addPostSetupService else '') + "\n"
return txt
Expand Down Expand Up @@ -220,12 +220,12 @@ def writeHybridProperties(self):
ldap_mappings = self.getMappingType('ldap')
couchbase_mappings = self.getMappingType('couchbase')

for group in Config.mappingLocations:
for group in Config.mapping_locations:
if group == 'default':
default_mapping = Config.mappingLocations[group]
default_mapping = Config.mapping_locations[group]
break

storages = set(Config.mappingLocations.values())
storages = set(Config.mapping_locations.values())

jans_hybrid_roperties = [
'storages: {0}'.format(', '.join(storages)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def render_import_templates(self):

self.role_scope_mappings()

Config.templateRenderingDict['person_custom_object_class_list'] = '[]' if Config.mappingLocations['default'] == 'rdbm' else '["jansCustomPerson", "jansPerson"]'
Config.templateRenderingDict['person_custom_object_class_list'] = '[]' if Config.mapping_locations['default'] == 'rdbm' else '["jansCustomPerson", "jansPerson"]'

templates = [self.oxauth_config_json]
if Config.profile == 'jans':
Expand Down
6 changes: 3 additions & 3 deletions jans-linux-setup/jans_setup/setup_app/installers/jans_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self):
setattr(base.current_app, self.__class__.__name__, self)
self.service_name = 'jans-cli'
self.needdb = False # we don't need backend connection in this class
self.install_var = 'installJansCli'
self.install_var = 'install_jans_cli'
self.app_type = AppType.APPLICATION
self.install_type = InstallOption.OPTONAL
home_dir = Path.home()
Expand Down Expand Up @@ -86,11 +86,11 @@ def configure(self, options={}):
for key_ in options:
config['DEFAULT'][key_] = options[key_]

if Config.installConfigApi:
if Config.install_config_api:
config['DEFAULT']['jca_client_id'] = Config.role_based_client_id
config['DEFAULT']['jca_client_secret_enc'] = Config.role_based_client_encoded_pw

if Config.get('installScimServer'):
if Config.get('install_scim_server'):
config['DEFAULT']['scim_client_id'] = Config.scim_client_id
config['DEFAULT']['scim_client_secret_enc'] = Config.scim_client_encoded_pw

Expand Down
Loading

0 comments on commit b2a48db

Please sign in to comment.