Skip to content

Commit

Permalink
fix: code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
devrimyatar committed Apr 29, 2022
1 parent c0a0cde commit e5aaad7
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 122 deletions.
11 changes: 6 additions & 5 deletions jans-linux-setup/jans_setup/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@

argsp = parser.parse_args()


bacup_ext = '-back.' + time.ctime()

def check_install_dependencies():

try:
Expand Down Expand Up @@ -106,8 +109,6 @@ def profile_setup():
replaced_dirs.append(source_dir)
if os.path.exists(source_dir) and os.path.exists(target_dir):
shutil.rmtree(target_dir)
copy_target = os.path.join(argsp.setup_dir, os.path.sep.join(os.path.split(pdir)[:-1]))
print(target_dir)
shutil.copytree(source_dir, target_dir)

for root, dirs, files in os.walk(profile_dir):
Expand All @@ -124,7 +125,7 @@ def profile_setup():

def extract_setup():
if os.path.exists(argsp.setup_dir):
shutil.move(argsp.setup_dir, argsp.setup_dir + '-back.' + time.ctime())
shutil.move(argsp.setup_dir, argsp.setup_dir + bacup_ext)

print("Extracting jans-setup package")
jans_zip = zipfile.ZipFile(jans_zip_file)
Expand Down Expand Up @@ -204,14 +205,14 @@ def upgrade():
target_fn = os.path.join(jetty_home, service, 'webapps', service +'.war' )
if os.path.exists(target_fn):
print("Copying", source_fn, "as", target_fn)
shutil.move(target_fn, target_fn+'-back.' + time.ctime())
shutil.move(target_fn, target_fn + bacup_ext)
shutil.copy(source_fn, target_fn)
print("Restarting", service)
os.system('systemctl restart ' + service)

jans_config_api_fn = '/opt/jans/config-api/jans-config-api-runner.jar'
if os.path.exists(jans_config_api_fn):
shutil.move(jans_config_api_fn, jans_config_api_fn + '-back.' + time.ctime())
shutil.move(jans_config_api_fn, jans_config_api_fn + bacup_ext)
source_fn = '/opt/dist/jans/jans-config-api-runner.jar'
print("Copying", source_fn, "as", jans_config_api_fn)
shutil.copy(source_fn, jans_config_api_fn)
Expand Down
9 changes: 6 additions & 3 deletions jans-linux-setup/jans_setup/openbanking/setup_app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Config:
network = '/etc/sysconfig/network'
jetty_home = '/opt/jetty'
jetty_base = os.path.join(jansOptFolder, 'jetty')
dist_app_dir = os.path.join(distFolder, 'app')
dist_jans_dir = os.path.join(distFolder, 'jans')

installed_instance = False
profile = 'openbanking'

Expand Down Expand Up @@ -93,8 +96,8 @@ def progress(self, service_name, msg, incr=False):
self.properties_password = None
self.noPrompt = False

self.distAppFolder = os.path.join(self.distFolder, 'app')
self.distJansFolder = os.path.join(self.distFolder, 'jans')
self.dist_app_dir = os.path.join(self.distFolder, 'app')
self.dist_jans_dir = os.path.join(self.distFolder, 'jans')
self.distTmpFolder = os.path.join(self.distFolder, 'tmp')

self.downloadWars = None
Expand Down Expand Up @@ -223,7 +226,7 @@ def progress(self, service_name, msg, incr=False):
}

self.non_setup_properties = {
'oxauth_client_jar_fn': os.path.join(self.distJansFolder, 'jans-auth-client-jar-with-dependencies.jar')
'oxauth_client_jar_fn': os.path.join(self.dist_jans_dir, 'jans-auth-client-jar-with-dependencies.jar')
}
self.mappingLocations = {'default': 'rdbm'}
Config.addPostSetupService = []
Expand Down
12 changes: 6 additions & 6 deletions jans-linux-setup/jans_setup/setup_app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class Config:
node_home = '/opt/node'
outputFolder = None
jetty_base = os.path.join(jansOptFolder, 'jetty')
distAppFolder = os.path.join(distFolder, 'app')
distJansFolder = os.path.join(distFolder, 'jans')
dist_app_dir = os.path.join(distFolder, 'app')
dist_jans_dir = os.path.join(distFolder, 'jans')

installed_instance = False
profile = 'jans'
Expand Down Expand Up @@ -111,8 +111,8 @@ def progress(self, service_name, msg, incr=False):
self.properties_password = None
self.noPrompt = False

self.distAppFolder = os.path.join(self.distFolder, 'app')
self.distJansFolder = os.path.join(self.distFolder, 'jans')
self.dist_app_dir = os.path.join(self.distFolder, 'app')
self.dist_jans_dir = os.path.join(self.distFolder, 'jans')
self.distTmpFolder = os.path.join(self.distFolder, 'tmp')

self.downloadWars = None
Expand Down Expand Up @@ -235,7 +235,7 @@ def progress(self, service_name, msg, incr=False):
self.ldapCertFn = self.opendj_cert_fn = os.path.join(self.certFolder, 'opendj.crt')
self.ldapTrustStoreFn = self.opendj_p12_fn = os.path.join(self.certFolder, 'opendj.p12')

self.oxd_package = base.determine_package(os.path.join(self.distJansFolder, 'oxd-server*.tgz'))
self.oxd_package = base.determine_package(os.path.join(self.dist_jans_dir, 'oxd-server*.tgz'))

self.opendj_p12_pass = None

Expand Down Expand Up @@ -381,7 +381,7 @@ def progress(self, service_name, msg, incr=False):

self.mappingLocations = { group: 'ldap' for group in self.couchbaseBucketDict } #default locations are OpenDJ
self.non_setup_properties = {
'oxauth_client_jar_fn': os.path.join(self.distJansFolder, 'jans-auth-client-jar-with-dependencies.jar')
'oxauth_client_jar_fn': os.path.join(self.dist_jans_dir, 'jans-auth-client-jar-with-dependencies.jar')
}
Config.addPostSetupService = []

Expand Down
25 changes: 16 additions & 9 deletions jans-linux-setup/jans_setup/setup_app/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ def download_jans_acrhieve():
verbose=True
)

def get_grpcio_package(data):

pyversion = 'cp{0}{1}'.format(sys.version_info.major, sys.version_info.minor)

package = {}

for package_ in data['urls']:

if package_['python_version'] == pyversion and 'manylinux' in package_['filename'] and package_['filename'].endswith('x86_64.whl'):
if package_['upload_time'] > package.get('upload_time',''):
package = package_
break

return package

def download_gcs():
gcs_dir = os.path.join(base.pylib_dir, 'gcs')

Expand All @@ -38,15 +53,7 @@ def download_gcs():
base.download('https://pypi.org/pypi/grpcio/1.37.0/json', grpcio_fn, verbose=True)
data = base.readJsonFile(grpcio_fn)

pyversion = 'cp{0}{1}'.format(sys.version_info.major, sys.version_info.minor)

package = {}

for package_ in data['urls']:

if package_['python_version'] == pyversion and 'manylinux' in package_['filename'] and package_['filename'].endswith('x86_64.whl'):
if package_['upload_time'] > package.get('upload_time',''):
package = package_
package = get_grpcio_package(data)

if package.get('url'):
target_whl_fn = os.path.join(tmp_dir, os.path.basename(package['url']))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
class ConfigApiInstaller(JettyInstaller):

source_files = [
(os.path.join(Config.distJansFolder, 'jans-config-api.war'), os.path.join(base.current_app.app_info['JANS_MAVEN'], 'maven/io/jans/jans-config-api-server/{0}/jans-config-api-server-{0}.war').format(base.current_app.app_info['ox_version'])),
(os.path.join(Config.distJansFolder, 'scim-plugin.jar'), os.path.join(base.current_app.app_info['JANS_MAVEN'], 'maven/io/jans/jans-config-api/plugins/scim-plugin/{0}/scim-plugin-{0}-distribution.jar').format(base.current_app.app_info['ox_version'])),
(os.path.join(Config.distJansFolder, 'facter'), 'https://raw.githubusercontent.com/GluuFederation/gluu-snap/master/facter/facter'),
(os.path.join(Config.dist_jans_dir, 'jans-config-api.war'), os.path.join(base.current_app.app_info['JANS_MAVEN'], 'maven/io/jans/jans-config-api-server/{0}/jans-config-api-server-{0}.war').format(base.current_app.app_info['ox_version'])),
(os.path.join(Config.dist_jans_dir, 'scim-plugin.jar'), os.path.join(base.current_app.app_info['JANS_MAVEN'], 'maven/io/jans/jans-config-api/plugins/scim-plugin/{0}/scim-plugin-{0}-distribution.jar').format(base.current_app.app_info['ox_version'])),
(os.path.join(Config.dist_jans_dir, 'facter'), 'https://raw.githubusercontent.com/GluuFederation/gluu-snap/master/facter/facter'),
#(os.path.join(Config.data_dir, 'jans-config-api-swagger.yaml'), 'https://raw.githubusercontent.com/JanssenProject/jans/main/jans-config-api/docs/jans-config-api-swagger.yaml'),
(os.path.join(Config.distJansFolder, 'user-mgt-plugin.jar'), os.path.join(base.current_app.app_info['JANS_MAVEN'], 'maven/io/jans/jans-config-api/plugins/user-mgt-plugin/{0}/user-mgt-plugin-{0}-distribution.jar').format(base.current_app.app_info['ox_version'])),
(os.path.join(Config.dist_jans_dir, 'user-mgt-plugin.jar'), os.path.join(base.current_app.app_info['JANS_MAVEN'], 'maven/io/jans/jans-config-api/plugins/user-mgt-plugin/{0}/user-mgt-plugin-{0}-distribution.jar').format(base.current_app.app_info['ox_version'])),
]

def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion jans-linux-setup/jans_setup/setup_app/installers/eleven.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class ElevenInstaller(JettyInstaller):

source_files = [
(os.path.join(Config.distJansFolder, 'jans-eleven.war'), os.path.join(base.current_app.app_info['JANS_MAVEN'], 'maven/io/jans/jans-eleven-server/{0}/jans-eleven-server-{0}.war').format(base.current_app.app_info['ox_version']))
(os.path.join(Config.dist_jans_dir, 'jans-eleven.war'), os.path.join(base.current_app.app_info['JANS_MAVEN'], 'maven/io/jans/jans-eleven-server/{0}/jans-eleven-server-{0}.war').format(base.current_app.app_info['ox_version']))
]

def __init__(self):
Expand Down
14 changes: 6 additions & 8 deletions jans-linux-setup/jans_setup/setup_app/installers/fido.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import glob
import shutil
from pathlib import Path

from setup_app import paths
from setup_app.utils import base
Expand All @@ -11,8 +12,8 @@
class FidoInstaller(JettyInstaller):

source_files = [
(os.path.join(Config.distJansFolder, 'jans-fido2.war'), os.path.join(base.current_app.app_info['JANS_MAVEN'], 'maven/io/jans/jans-fido2-server/{0}/jans-fido2-server-{0}.war').format(base.current_app.app_info['ox_version'])),
(os.path.join(Config.distAppFolder, os.path.basename(base.current_app.app_info['APPLE_WEBAUTHN'])), base.current_app.app_info['APPLE_WEBAUTHN'])
(os.path.join(Config.dist_jans_dir, 'jans-fido2.war'), os.path.join(base.current_app.app_info['JANS_MAVEN'], 'maven/io/jans/jans-fido2-server/{0}/jans-fido2-server-{0}.war').format(base.current_app.app_info['ox_version'])),
(os.path.join(Config.dist_app_dir, os.path.basename(base.current_app.app_info['APPLE_WEBAUTHN'])), base.current_app.app_info['APPLE_WEBAUTHN'])
]

def __init__(self):
Expand Down Expand Up @@ -75,12 +76,9 @@ def copy_static(self):
)

#copy fido2 server metadata
target = os.path.join(self.fido2ConfigFolder, 'server_metadata')
self.copyTree(
os.path.join(Config.install_dir, 'static/fido2/server_metadata'),
os.path.join(self.fido2ConfigFolder, 'server_metadata'),
except_list=['.dontdelete']
)
src_dir = os.path.join(Config.install_dir, 'static/fido2/server_metadata')
trgt_dir = os.path.join(self.fido2ConfigFolder, 'server_metadata')
self.copy_tree(src_dir, trgt_dir, ignore='.dontdelete')

# copy Apple_WebAuthn_Root_CA
if os.path.exists(self.source_files[1][0]):
Expand Down
4 changes: 2 additions & 2 deletions jans-linux-setup/jans_setup/setup_app/installers/jans_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def __init__(self):
self.register_progess()

self.source_files = [
(os.path.join(Config.distJansFolder, 'jans-auth.war'), os.path.join(base.current_app.app_info['JANS_MAVEN'], 'maven/io/jans/jans-auth-server/{0}/jans-auth-server-{0}.war'.format(base.current_app.app_info['ox_version']))),
(os.path.join(Config.distJansFolder, 'jans-auth-client-jar-with-dependencies.jar'), os.path.join(base.current_app.app_info['JANS_MAVEN'], 'maven/io/jans/jans-auth-client/{0}/jans-auth-client-{0}-jar-with-dependencies.jar'.format(base.current_app.app_info['ox_version']))),
(os.path.join(Config.dist_jans_dir, 'jans-auth.war'), os.path.join(base.current_app.app_info['JANS_MAVEN'], 'maven/io/jans/jans-auth-server/{0}/jans-auth-server-{0}.war'.format(base.current_app.app_info['ox_version']))),
(os.path.join(Config.dist_jans_dir, 'jans-auth-client-jar-with-dependencies.jar'), os.path.join(base.current_app.app_info['JANS_MAVEN'], 'maven/io/jans/jans-auth-client/{0}/jans-auth-client-{0}-jar-with-dependencies.jar'.format(base.current_app.app_info['ox_version']))),
]

self.templates_folder = os.path.join(Config.templateFolder, self.service_name)
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 @@ -18,9 +18,9 @@
class JansCliInstaller(BaseInstaller, SetupUtils):

source_files = [
(os.path.join(Config.distJansFolder, 'jca-swagger-client.zip'), os.path.join(base.current_app.app_info['EXTERNAL_LIBS'], 'cli-swagger/jca_swagger_client.zip')),
(os.path.join(Config.distJansFolder, 'scim-swagger-client.zip'), os.path.join(base.current_app.app_info['EXTERNAL_LIBS'], 'cli-swagger/scim_swagger_client.zip')),
(os.path.join(Config.distAppFolder, 'pyjwt.zip'), base.current_app.app_info['PYJWT']),
(os.path.join(Config.dist_jans_dir, 'jca-swagger-client.zip'), os.path.join(base.current_app.app_info['EXTERNAL_LIBS'], 'cli-swagger/jca_swagger_client.zip')),
(os.path.join(Config.dist_jans_dir, 'scim-swagger-client.zip'), os.path.join(base.current_app.app_info['EXTERNAL_LIBS'], 'cli-swagger/scim_swagger_client.zip')),
(os.path.join(Config.dist_app_dir, 'pyjwt.zip'), base.current_app.app_info['PYJWT']),
]

def __init__(self):
Expand Down
8 changes: 4 additions & 4 deletions jans-linux-setup/jans_setup/setup_app/installers/jetty.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class JettyInstaller(BaseInstaller, SetupUtils):

jetty_link = 'https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-home/{0}/jetty-home-{0}.tar.gz'.format(base.current_app.app_info['JETTY_VERSION'])
source_files = [
(os.path.join(Config.distAppFolder, os.path.basename(jetty_link)), jetty_link),
(os.path.join(Config.dist_app_dir, os.path.basename(jetty_link)), jetty_link),
]

def __init__(self):
Expand Down Expand Up @@ -106,10 +106,10 @@ def install(self):
def get_jetty_info(self):
# first try latest versions
self.jetty_dist_string = 'jetty-home'
jetty_archive_list = glob.glob(os.path.join(Config.distAppFolder, '{}-*.tar.gz'.format(self.jetty_dist_string)))
jetty_archive_list = glob.glob(os.path.join(Config.dist_app_dir, '{}-*.tar.gz'.format(self.jetty_dist_string)))

if not jetty_archive_list:
self.logIt("Jetty archive not found in {}. Exiting...".format(Config.distAppFolder), True, True)
self.logIt("Jetty archive not found in {}. Exiting...".format(Config.dist_app_dir), True, True)

jettyArchive = max(jetty_archive_list)

Expand All @@ -132,7 +132,7 @@ def web_app_xml_fn(self):
def installJettyService(self, serviceConfiguration, supportCustomizations=False, supportOnlyPageCustomizations=False):
serviceName = serviceConfiguration['name']
self.logIt("Installing jetty service %s..." % serviceName)

self.logIt("Deploying Jetty Service", pbar=serviceName)
self.get_jetty_info()
jettyServiceBase = '%s/%s' % (self.jetty_base, serviceName)
jettyModules = serviceConfiguration['jetty']['modules']
Expand Down
14 changes: 7 additions & 7 deletions jans-linux-setup/jans_setup/setup_app/installers/jre.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class JreInstaller(BaseInstaller, SetupUtils):

amazon_corretto_link = 'https://corretto.aws/downloads/resources/{0}/amazon-corretto-{0}-linux-x64.tar.gz'.format(base.current_app.app_info['AMAZON_CORRETTO_VERSION'])
source_files = [
(os.path.join(Config.distAppFolder, os.path.basename(amazon_corretto_link)), amazon_corretto_link),
(os.path.join(Config.dist_app_dir, os.path.basename(amazon_corretto_link)), amazon_corretto_link),
]

def __init__(self):
Expand All @@ -33,17 +33,17 @@ def install(self):

if Config.java_type == 'jdk':
open_jdk_archive_link = 'https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.9.1%2B1/OpenJDK11U-jdk_x64_linux_hotspot_11.0.9.1_1.tar.gz'
target_fn = os.path.join(Config.distAppFolder, os.path.basename(open_jdk_archive_link))
target_fn = os.path.join(Config.dist_app_dir, os.path.basename(open_jdk_archive_link))
base.download(open_jdk_archive_link, target_fn)
jreArchive = target_fn
jre_archive = target_fn
else:
jreArchive = self.source_files[0][0]
jre_archive = self.source_files[0][0]

self.logIt("Installing server JRE {} ...".format(os.path.basename(jreArchive)))
self.logIt("Installing server JRE {} ...".format(os.path.basename(jre_archive)))

try:
self.logIt("Extracting %s into /opt/" % os.path.basename(jreArchive))
self.run([paths.cmd_tar, '-xzf', jreArchive, '-C', '/opt/', '--no-xattrs', '--no-same-owner', '--no-same-permissions'])
self.logIt("Extracting %s into /opt/" % os.path.basename(jre_archive))
self.run([paths.cmd_tar, '-xzf', jre_archive, '-C', '/opt/', '--no-xattrs', '--no-same-owner', '--no-same-permissions'])
except Exception as e:
self.logIt("Error encountered while extracting archive {}".format(e))

Expand Down
4 changes: 2 additions & 2 deletions jans-linux-setup/jans_setup/setup_app/installers/jython.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class JythonInstaller(BaseInstaller, SetupUtils):

jython_link = 'https://maven.gluu.org/maven/org/gluufederation/jython-installer/{0}/jython-installer-{0}.jar'.format(base.current_app.app_info['JYTHON_VERSION'])
source_files = [
(os.path.join(Config.distAppFolder, os.path.basename(jython_link)), jython_link),
(os.path.join(Config.dist_app_dir, os.path.basename(jython_link)), jython_link),
]

def __init__(self):
Expand All @@ -30,7 +30,7 @@ def __init__(self):

def install(self):

jython_installer_list = glob.glob(os.path.join(Config.distAppFolder, 'jython-installer-*'))
jython_installer_list = glob.glob(os.path.join(Config.dist_app_dir, 'jython-installer-*'))

if not jython_installer_list:
self.logIt("Jython installer not found in. Exiting...", True, True)
Expand Down
2 changes: 1 addition & 1 deletion jans-linux-setup/jans_setup/setup_app/installers/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self):

def install(self):

node_archieve_list = glob.glob(os.path.join(Config.distAppFolder, 'node-*-linux-x64.tar.xz'))
node_archieve_list = glob.glob(os.path.join(Config.dist_app_dir, 'node-*-linux-x64.tar.xz'))

if not node_archieve_list:
self.logIt("Can't find node archive", True, True)
Expand Down
10 changes: 5 additions & 5 deletions jans-linux-setup/jans_setup/setup_app/installers/opendj.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class OpenDjInstaller(BaseInstaller, SetupUtils):

opendj_link = 'https://maven.gluu.org/maven/org/gluufederation/opendj/opendj-server-legacy/{0}/opendj-server-legacy-{0}.zip'.format(base.current_app.app_info['OPENDJ_VERSION'])
source_files = [
(os.path.join(Config.distAppFolder, os.path.basename(opendj_link)), opendj_link),
(os.path.join(Config.dist_app_dir, os.path.basename(opendj_link)), opendj_link),
]

def __init__(self):
Expand Down Expand Up @@ -93,13 +93,13 @@ def install(self):

def extractOpenDJ(self):

openDJArchive = max(glob.glob(os.path.join(Config.distAppFolder, 'opendj-server-*4*.zip')))
opendj_archive = max(glob.glob(os.path.join(Config.dist_app_dir, 'opendj-server-*4*.zip')))

try:
self.logIt("Unzipping %s in /opt/" % openDJArchive)
self.run([paths.cmd_unzip, '-n', '-q', '%s' % (openDJArchive), '-d', '/opt/' ])
self.logIt("Unzipping %s in /opt/" % opendj_archive)
self.run([paths.cmd_unzip, '-n', '-q', '%s' % (opendj_archive), '-d', '/opt/' ])
except:
self.logIt("Error encountered while doing unzip %s -d /opt/" % (openDJArchive))
self.logIt("Error encountered while doing unzip %s -d /opt/" % (opendj_archive))

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

0 comments on commit e5aaad7

Please sign in to comment.