Skip to content

Commit

Permalink
MySQL DB: Always ignore the DB part of database_admin_url
Browse files Browse the repository at this point in the history
This prevents an initial connect error when the database does not exist.

Credits to Sasmita Panda for reporting this issue
  • Loading branch information
liviuchircu committed Nov 20, 2020
1 parent 524c020 commit ef936a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions opensipscli/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,12 @@ def get_db_host():

@staticmethod
def set_url_db(url, db):
"""
Force a given database @url string to include the given @db
"""Force a given database @url string to include the given @db.
Args:
url (str): the URL to change the DB for.
db (str): the name of the database to set. If None, the database
part will be removed from the URL.
"""
at_idx = url.find('@')
if at_idx < 0:
Expand All @@ -845,8 +849,12 @@ def set_url_db(url, db):

db_idx = url.find('/', at_idx)
if db_idx < 0:
if db is None:
return url
return url + '/' + db
else:
if db is None:
return url[:db_idx]
return url[:db_idx+1] + db


Expand Down
2 changes: 2 additions & 0 deletions opensipscli/modules/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ def get_admin_db_url(self, db_name):
admin_url = cfg.get("database_admin_url")
if engine == "postgres":
admin_url = osdb.set_url_db(admin_url, 'postgres')
else:
admin_url = osdb.set_url_db(admin_url, None)
else:
if engine == 'postgres':
if getuser() != "postgres":
Expand Down

0 comments on commit ef936a5

Please sign in to comment.