def get_admin_db_url(self, db_name): engine = osdb.get_db_engine() if not engine: return None if cfg.exists('database_admin_url'): admin_url = cfg.get("database_admin_url") if engine == "postgres": admin_url = osdb.set_url_db(admin_url, 'postgres') else: if engine == 'postgres': if getuser() != "postgres": logger.error("Command must be run as 'postgres' user: "******"sudo -u postgres opensips-cli ...") return None """ For PG, do the initial setup using 'postgres' as role + DB """ admin_url = "postgres://postgres@localhost/postgres" else: admin_url = "{}://root@localhost".format(engine) if osdb.get_url_pswd(admin_url) is None: pswd = getpass("Password for admin {} user ({}): ".format( osdb.get_url_driver(admin_url, capitalize=True), osdb.get_url_user(admin_url))) logger.debug("read password: '******'", pswd) admin_url = osdb.set_url_password(admin_url, pswd) logger.debug("admin DB URL: '{}'".format(admin_url)) return admin_url
def user_db_connect(self): engine = osdb.get_db_engine() db_url = cfg.read_param(["database_user_url", "database_url"], "Please provide us the URL of the database") if db_url is None: print() logger.error("no URL specified: aborting!") return None db_url = osdb.set_url_driver(db_url, engine) db_name = cfg.read_param(["database_user_name", "database_name"], "Please provide the database to add user to", DEFAULT_DB_NAME) try: db = osdb(db_url, db_name) except osdbError: logger.error("failed to connect to database %s", db_name) return None if not db.connect(): return None return db
def get_db_url(self, db_name=cfg.get('database_name')): engine = osdb.get_db_engine() if not engine: return None # make sure to inherit the 'database_admin_url' engine db_url = osdb.set_url_driver(cfg.get("database_url"), engine) logger.debug("DB URL: '{}'".format(db_url)) return db_url
def user_db_connect(self): engine = osdb.get_db_engine() db_url = cfg.read_param(["database_user_url", "database_url"], "Please provide us the URL of the database") if db_url is None: print() logger.error("no URL specified: aborting!") return None, None db_url = osdb.set_url_driver(db_url, engine) db_name = cfg.read_param(["database_user_name", "database_name"], "Please provide the database to add user to", DEFAULT_DB_NAME) try: db = osdb(db_url, db_name) except osdbError: logger.error("failed to connect to database %s", db_name) return None, None if not db.connect(): return None, None res = db.find('version', 'table_version', {'table_name': USER_TABLE}) if not res: osips_ver = '3.2+' else: # RFC 8760 support was introduced in OpenSIPS 3.2 (table ver 8+) tb_ver = res.first()[0] if tb_ver >= 8: osips_ver = '3.2+' else: osips_ver = '3.1' return db, osips_ver