def get_user(self, context, username, hostname): """Return a single user matching the criteria. The username and hostname parameter are strings. The return value is a dictionary in the following form: {"_name": "", "_host": None, "_password": None, "_databases": [{"_name": ""}, ...]} Where "_databases" is a list of databases the user has access to. """ results = pgutil.query( pgutil.UserQuery.get(name=username), timeout=30, ) results = tuple(results) if len(results) < 1: return None return { "_name": results[0][0], "_host": None, "_password": None, "_databases": self.list_access(context, username, None), }
def list_users( self, context, limit=None, marker=None, include_marker=False, ): """List all users on the instance along with their access permissions. Return value is a list of dictionaries in the following form: [{"_name": "", "_password": None, "_host": None, "_databases": [{"_name": ""}, ...]}, ...] """ results = pgutil.query( pgutil.UserQuery.list(ignore=IGNORE_USERS_LIST), timeout=30, ) # Convert results into dictionaries. results = ( { '_name': r[0].strip(), '_password': None, '_host': None, '_databases': self.list_access(context, r[0], None), } for r in results ) # Force __iter__ of generator until marker found. if marker is not None: try: item = results.next() while item['_name'] != marker: item = results.next() except StopIteration: pass remainder = None if limit is not None: remainder = results results = itertools.islice(results, limit) results = tuple(results) next_marker = None if remainder is not None: try: next_marker = remainder.next() except StopIteration: pass return results, next_marker
def is_root_enabled(self, context): """Return True if there is a superuser account enabled. This ignores the built-in superuser of postgres and the potential system administration superuser of os_admin. """ results = pgutil.query( pgutil.UserQuery.list_root(ignore=IGNORE_USERS_LIST), timeout=30, ) # Reduce iter of iters to iter of single values. results = (r[0] for r in results) return len(tuple(results)) > 0
def list_databases( self, context, limit=None, marker=None, include_marker=False, ): """List databases created on this instance. Return value is a list of dictionaries in the following form: [{"_name": "", "_character_set": "", "_collate": ""}, ...] """ results = pgutil.query( pgutil.DatabaseQuery.list(ignore=IGNORE_DBS_LIST), timeout=30, ) # Convert results to dictionaries. results = ({ '_name': r[0].strip(), '_character_set': r[1], '_collate': r[2] } for r in results) # Force __iter__ of generator until marker found. if marker is not None: try: item = results.next() while item['_name'] != marker: item = results.next() except StopIteration: pass remainder = None if limit is not None: remainder = results results = itertools.islice(results, limit) results = tuple(results) next_marker = None if remainder is not None: try: next_marker = remainder.next() except StopIteration: pass return results, next_marker
def list_databases( self, context, limit=None, marker=None, include_marker=False, ): """List databases created on this instance. Return value is a list of dictionaries in the following form: [{"_name": "", "_character_set": "", "_collate": ""}, ...] """ results = pgutil.query( pgutil.DatabaseQuery.list(ignore=IGNORE_DBS_LIST), timeout=30, ) # Convert results to dictionaries. results = ( {'_name': r[0].strip(), '_character_set': r[1], '_collate': r[2]} for r in results ) # Force __iter__ of generator until marker found. if marker is not None: try: item = results.next() while item['_name'] != marker: item = results.next() except StopIteration: pass remainder = None if limit is not None: remainder = results results = itertools.islice(results, limit) results = tuple(results) next_marker = None if remainder is not None: try: next_marker = remainder.next() except StopIteration: pass return results, next_marker
def list_access(self, context, username, hostname): """List database for which the given user as access. The username and hostname parameters are strings. Return value is a list of dictionaries in the following form: [{"_name": "", "_collate": None, "_character_set": None}, ...] """ results = pgutil.query( pgutil.AccessQuery.list(user=username), timeout=30, ) # Convert to dictionaries. results = ( {'_name': r[0].strip(), '_collate': None, '_character_set': None} for r in results ) return tuple(results)
def list_access(self, context, username, hostname): """List database for which the given user as access. The username and hostname parameters are strings. Return value is a list of dictionaries in the following form: [{"_name": "", "_collate": None, "_character_set": None}, ...] """ results = pgutil.query( pgutil.AccessQuery.list(user=username), timeout=30, ) # Convert to dictionaries. results = ({ '_name': r[0].strip(), '_collate': None, '_character_set': None } for r in results) return tuple(results)