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 option reset-rdbm-db #2413

Merged
merged 6 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions jans-linux-setup/jans_setup/setup_app/installers/rdbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def __init__(self):
def install(self):
self.qchar = '`' if Config.rdbm_type in ('mysql', 'spanner') else '"'
self.local_install()
if Config.rdbm_install_type == InstallTypes.REMOTE and base.argsp.reset_rdbm_db:
self.reset_rdbm_db()
jans_schema_files = []
self.jans_attributes = []
for jans_schema_fn in ('jans_schema.json', 'custom_schema.json'):
Expand All @@ -45,6 +47,13 @@ def install(self):
self.create_indexes()
self.rdbmProperties()

def reset_rdbm_db(self):
self.logIt("Resetting DB {}".format(Config.rdbm_db))
self.dbUtils.metadata.reflect(self.dbUtils.engine)
self.dbUtils.metadata.drop_all(self.dbUtils.engine)
self.dbUtils.session.commit()
self.dbUtils.metadata.clear()

def local_install(self):
if not Config.rdbm_password:
Config.rdbm_password = self.getPW()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
parser.add_argument('-rdbm-port', help="RDBM port")
parser.add_argument('-rdbm-db', help="RDBM database")
parser.add_argument('-rdbm-host', help="RDBM host")
parser.add_argument('--reset-rdbm-db', help="Deletes all tables on target database. Warning! You will lose all data on target database.", action='store_true')

parser.add_argument('--shell', help="Drop into interactive shell before starting installation", action='store_true')
parser.add_argument('--dump-config-on-error', help="Dump configuration on error", action='store_true')
Expand Down
18 changes: 8 additions & 10 deletions jans-linux-setup/jans_setup/setup_app/utils/properties_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import psycopg2
import inspect
import ldap3
import tempfile

from setup_app import paths
from setup_app.messages import msg
Expand Down Expand Up @@ -459,12 +460,13 @@ def check_oxd_server(self, oxd_url, error_out=True, log_error=True):
def check_oxd_ssl_cert(self, oxd_hostname, oxd_port):

oxd_cert = ssl.get_server_certificate((oxd_hostname, oxd_port))
oxd_crt_fn = '/tmp/oxd_{}.crt'.format(str(uuid.uuid4()))
self.writeFile(oxd_crt_fn, oxd_cert)
ssl_subjects = self.get_ssl_subject(oxd_crt_fn)

if ssl_subjects.get('commonName') != oxd_hostname:
return ssl_subjects
with tempfile.TemporaryDirectory() as tmpdirname:
oxd_crt_fn = os.path.join(tmpdirname, 'oxd.crt')
self.writeFile(oxd_crt_fn, oxd_cert)
ssl_subjects = self.get_ssl_subject(oxd_crt_fn)

if ssl_subjects.get('commonName') != oxd_hostname:
return ssl_subjects


def promptForBackendMappings(self):
Expand Down Expand Up @@ -769,10 +771,6 @@ def prompt_for_backend(self):
else:
Config.rdbm_port = 5432
Config.rdbm_type = 'pgsql'
if not Config.rdbm_host:

if not Config.rdbm_password:
Config.rdbm_password = self.getPW(special='.*=+-()[]{}')

elif backend_type_str in (BackendStrings.REMOTE_MYSQL, BackendStrings.REMOTE_PGSQL):
Config.opendj_install = InstallTypes.NONE
Expand Down