from .ldap_app import PpLdapAppError, PpLdapApplication
-__version__ = '0.3.1'
+__version__ = '0.3.2'
LOG = logging.getLogger(__name__)
self.db_user = self.default_db_user
self.db_pass = None
+ self.db_users = []
+
self.db_connection = None
self._show_simulate_opt = True
self.get_admin_user_dns()
self.get_admin_users()
+ self.get_db_users()
finally:
self._close_db()
}
self.admin_users.append(user)
- LOG.debug("Found admin user:\n{}".format(pp(self.admin_users)))
+ LOG.debug("Found admin users:\n{}".format(pp(self.admin_users)))
+
+ # -------------------------------------------------------------------------
+ def get_db_users(self):
+
+ LOG.info("Get list of current users in DB.")
+
+ self.db_users = []
+
+ sql = textwrap.dedent('''\
+ SELECT id, uid, name, email, active, admin, developer
+ FROM public.user
+ WHERE auth_realm = 'LDAP'
+ ORDER BY uid
+ ''').strip()
+ if self.verbose > 1:
+ LOG.debug("SQL:\n{}".format(sql))
+
+ with self.db_connection.cursor() as db_cursor:
+
+ db_cursor.execute(sql)
+ results = db_cursor.fetchall()
+
+ if self.verbose > 2:
+ LOG.debug("Got users:\n{}".format(pp(results)))
+
+ for result in results:
+ user = {
+ 'id': result[0],
+ 'uid': result[1],
+ 'name': result[2],
+ 'email': result[3],
+ 'active': result[4],
+ 'admin': result[5],
+ 'developer': result[6],
+ }
+ self.db_users.append(user)
+
+ LOG.debug("Found database users:\n{}".format(pp(self.db_users)))
# -------------------------------------------------------------------------
def _close_db(self):