def _fetch_properties(self, gid, sid, did, scid, fnid=None): """ Return Function Properties which will be used in properties, msql function. Args: gid: Server Group Id sid: Server Id did: Database Id scid: Schema Id fnid: Function Id """ resp_data = {} SQL = render_template("/".join([self.sql_template_path, 'properties.sql']), scid=scid, fnid=fnid) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone(gettext(""" Could not find the function in the database.\n It may have been removed by another user or moved to another schema. """)) resp_data = res['rows'][0] # Get formatted Arguments frmtd_params, frmtd_proargs = self._format_arguments_from_db(resp_data) resp_data.update(frmtd_params) resp_data.update(frmtd_proargs) # Fetch privileges SQL = render_template("/".join([self.sql_template_path, 'acl.sql']), fnid=fnid) status, proaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) # Get Formatted Privileges resp_data.update(self._format_proacl_from_db(proaclres['rows'])) # Set System Functions Status resp_data['sysfunc'] = False if fnid <= self.manager.db_info[did]['datlastsysoid']: resp_data['sysfunc'] = True # Get formatted Security Labels if 'seclabels' in resp_data: resp_data.update(parse_sec_labels_from_db(resp_data['seclabels'])) # Get formatted Variable resp_data.update(parse_variables_from_db([ {"setconfig": resp_data['proconfig']}])) return resp_data
def properties(self, gid, sid, did): SQL = render_template("/".join([self.template_path, 'properties.sql']), did=did, conn=self.conn, last_system_oid=0) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone(_("Could not find the database on the server.")) SQL = render_template("/".join([self.template_path, 'acl.sql']), did=did, conn=self.conn) status, dataclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, dataclres['rows']) SQL = render_template("/".join([self.template_path, 'defacl.sql']), did=did, conn=self.conn) status, defaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, defaclres['rows']) result = res['rows'][0] result['is_sys_obj'] = (result['oid'] <= self.datlastsysoid) # Fetching variable for database SQL = render_template("/".join( [self.template_path, 'get_variables.sql']), did=did, conn=self.conn) status, res1 = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res1) # Get Formatted Security Labels if 'seclabels' in result: # Security Labels is not available for PostgreSQL <= 9.1 frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels']) result.update(frmtd_sec_labels) # Get Formatted Variables frmtd_variables = parse_variables_from_db(res1['rows']) result.update(frmtd_variables) return ajax_response(response=result, status=200)
def properties(self, gid, sid, did): SQL = render_template( "/".join([self.template_path, 'properties.sql']), did=did, conn=self.conn, last_system_oid=0 ) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) SQL = render_template( "/".join([self.template_path, 'acl.sql']), did=did, conn=self.conn ) status, dataclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, dataclres['rows']) SQL = render_template( "/".join([self.template_path, 'defacl.sql']), did=did, conn=self.conn ) status, defaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, defaclres['rows']) result = res['rows'][0] # Fetching variable for database SQL = render_template( "/".join([self.template_path, 'get_variables.sql']), did=did, conn=self.conn ) status, res1 = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res1) # Get Formatted Security Labels if 'seclabels' in result: # Security Labels is not available for PostgreSQL <= 9.1 frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels']) result.update(frmtd_sec_labels) # Get Formatted Variables frmtd_variables = parse_variables_from_db(res1['rows']) result.update(frmtd_variables) return ajax_response( response=result, status=200 )
def sql(self, gid, sid, did): """ This function will generate sql for sql panel """ SQL = render_template( "/".join([self.template_path, 'properties.sql']), did=did, conn=self.conn, last_system_oid=0 ) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) SQL = render_template( "/".join([self.template_path, 'acl.sql']), did=did, conn=self.conn ) status, dataclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, dataclres['rows']) SQL = render_template( "/".join([self.template_path, 'defacl.sql']), did=did, conn=self.conn ) status, defaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, defaclres['rows']) result = res['rows'][0] SQL = render_template( "/".join([self.template_path, 'get_variables.sql']), did=did, conn=self.conn ) status, res1 = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res1) # Get Formatted Security Labels if 'seclabels' in result: # Security Labels is not available for PostgreSQL <= 9.1 frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels']) result.update(frmtd_sec_labels) # Get Formatted Variables frmtd_variables = parse_variables_from_db(res1['rows']) result.update(frmtd_variables) SQL = self.get_new_sql(gid, sid, result, did) SQL = re.sub('\n{2,}', '\n\n', SQL) SQL = SQL.strip('\n') return ajax_response(response=SQL)
def sql(self, gid, sid, did): """ This function will generate sql for sql panel """ SQL = render_template( "/".join([self.template_path, 'properties.sql']), did=did, conn=self.conn, last_system_oid=0 ) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) SQL = render_template( "/".join([self.template_path, 'acl.sql']), did=did, conn=self.conn ) status, dataclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, dataclres['rows']) SQL = render_template( "/".join([self.template_path, 'defacl.sql']), did=did, conn=self.conn ) status, defaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, defaclres['rows']) result = res['rows'][0] SQL = render_template( "/".join([self.template_path, 'get_variables.sql']), did=did, conn=self.conn ) status, res1 = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res1) # Get Formatted Security Labels if 'seclabels' in result: # Security Labels is not available for PostgreSQL <= 9.1 frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels']) result.update(frmtd_sec_labels) # Get Formatted Variables frmtd_variables = parse_variables_from_db(res1['rows']) result.update(frmtd_variables) SQL = self.get_new_sql(gid, sid, result, did) return ajax_response(response=SQL)
def sql(self, gid, sid, did): """ This function will generate sql for sql panel """ conn = self.manager.connection() SQL = render_template("/".join([self.template_path, 'properties.sql']), did=did, conn=conn, last_system_oid=0) status, res = conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone(_("Could not find the database on the server.")) SQL = render_template("/".join([self.template_path, 'acl.sql']), did=did, conn=self.conn) status, dataclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=dataclres) res = self.formatdbacl(res, dataclres['rows']) SQL = render_template("/".join([self.template_path, 'defacl.sql']), did=did, conn=self.conn) status, defaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=defaclres) res = self.formatdbacl(res, defaclres['rows']) result = res['rows'][0] SQL = render_template("/".join( [self.template_path, 'get_variables.sql']), did=did, conn=self.conn) status, res1 = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res1) # Get Formatted Security Labels if 'seclabels' in result: # Security Labels is not available for PostgreSQL <= 9.1 frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels']) result.update(frmtd_sec_labels) # Get Formatted Variables frmtd_variables = parse_variables_from_db(res1['rows']) result.update(frmtd_variables) sql_header = u"-- Database: {0}\n\n-- ".format(result['name']) sql_header += render_template("/".join( [self.template_path, 'delete.sql']), datname=result['name'], conn=conn) SQL = self.get_new_sql(gid, sid, result, did) SQL = re.sub('\n{2,}', '\n\n', SQL) SQL = sql_header + '\n' + SQL SQL = SQL.strip('\n') return ajax_response(response=SQL)
def properties(self, gid, sid, did): SQL = render_template( "/".join([self.template_path, self._PROPERTIES_SQL]), did=did, conn=self.conn, last_system_oid=0, show_system_objects=self.blueprint.show_system_objects, ) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone( self.not_found_error_msg() ) SQL = render_template( "/".join([self.template_path, self._ACL_SQL]), did=did, conn=self.conn ) status, dataclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, dataclres['rows']) SQL = render_template( "/".join([self.template_path, 'defacl.sql']), did=did, conn=self.conn ) status, defaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) res = self.formatdbacl(res, defaclres['rows']) result = res['rows'][0] result['is_sys_obj'] = ( result['oid'] <= self.datlastsysoid or self.datistemplate) # Fetching variable for database SQL = render_template( "/".join([self.template_path, 'get_variables.sql']), did=did, conn=self.conn ) status, res1 = self.conn.execute_dict(SQL) database = Database.query.filter_by(id=did, server=sid).first() if database: result['schema_res'] = database.schema_res.split( ',') if database.schema_res else [] if not status: return internal_server_error(errormsg=res1) # Get Formatted Security Labels if 'seclabels' in result: # Security Labels is not available for PostgreSQL <= 9.1 frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels']) result.update(frmtd_sec_labels) # Get Formatted Variables frmtd_variables = parse_variables_from_db(res1['rows']) result.update(frmtd_variables) return ajax_response( response=result, status=200 )
def sql(self, gid, sid, did): """ This function will generate sql for sql panel """ conn = self.manager.connection(did=did) SQL = render_template( "/".join([self.template_path, self._PROPERTIES_SQL]), did=did, conn=conn, last_system_oid=0, show_system_objects=False, ) status, res = conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone(self.not_found_error_msg()) SQL = render_template("/".join([self.template_path, self._ACL_SQL]), did=did, conn=self.conn) status, dataclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=dataclres) res = self.formatdbacl(res, dataclres['rows']) SQL = render_template("/".join([self.template_path, 'defacl.sql']), did=did, conn=self.conn, grant_reovke_sql=True) status, defaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=defaclres) res = self.formatdbacl(res, defaclres['rows']) result = res['rows'][0] SQL = render_template("/".join( [self.template_path, 'get_variables.sql']), did=did, conn=self.conn) status, res1 = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res1) # Get Formatted Security Labels if 'seclabels' in result: # Security Labels is not available for PostgreSQL <= 9.1 frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels']) result.update(frmtd_sec_labels) # Get Formatted Variables frmtd_variables = parse_variables_from_db(res1['rows']) result.update(frmtd_variables) sql_header = "-- Database: {0}\n\n-- ".format(result['name']) sql_header += render_template("/".join( [self.template_path, self._DELETE_SQL]), datname=result['name'], conn=conn) SQL = self.get_new_sql(gid, sid, result, did) SQL = re.sub('\n{2,}', '\n\n', SQL) SQL = sql_header + '\n' + SQL SQL = SQL.strip('\n') return ajax_response(response=SQL)
def sql(self, gid, sid, did): """ This function will generate sql for sql panel """ conn = self.manager.connection() SQL = render_template( "/".join([self.template_path, 'properties.sql']), did=did, conn=conn, last_system_oid=0 ) status, res = conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone( _("Could not find the database on the server.") ) SQL = render_template( "/".join([self.template_path, 'acl.sql']), did=did, conn=self.conn ) status, dataclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=dataclres) res = self.formatdbacl(res, dataclres['rows']) SQL = render_template( "/".join([self.template_path, 'defacl.sql']), did=did, conn=self.conn ) status, defaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=defaclres) res = self.formatdbacl(res, defaclres['rows']) result = res['rows'][0] SQL = render_template( "/".join([self.template_path, 'get_variables.sql']), did=did, conn=self.conn ) status, res1 = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res1) # Get Formatted Security Labels if 'seclabels' in result: # Security Labels is not available for PostgreSQL <= 9.1 frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels']) result.update(frmtd_sec_labels) # Get Formatted Variables frmtd_variables = parse_variables_from_db(res1['rows']) result.update(frmtd_variables) sql_header = u"-- Database: {0}\n\n-- ".format(result['name']) sql_header += render_template( "/".join([self.template_path, 'delete.sql']), datname=result['name'], conn=conn ) SQL = self.get_new_sql(gid, sid, result, did) SQL = re.sub('\n{2,}', '\n\n', SQL) SQL = sql_header + '\n' + SQL SQL = SQL.strip('\n') return ajax_response(response=SQL)
def _fetch_properties(self, gid, sid, did, scid, fnid=None): """ Return Function Properties which will be used in properties, msql function. Args: gid: Server Group Id sid: Server Id did: Database Id scid: Schema Id fnid: Function Id """ resp_data = {} SQL = render_template("/".join( [self.sql_template_path, 'properties.sql']), scid=scid, fnid=fnid) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) if len(res['rows']) == 0: return gone( gettext(""" Could not find the function in the database.\n It may have been removed by another user or moved to another schema. """)) resp_data = res['rows'][0] # Get formatted Arguments frmtd_params, frmtd_proargs = self._format_arguments_from_db(resp_data) resp_data.update(frmtd_params) resp_data.update(frmtd_proargs) # Fetch privileges SQL = render_template("/".join([self.sql_template_path, 'acl.sql']), fnid=fnid) status, proaclres = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) # Get Formatted Privileges resp_data.update(self._format_proacl_from_db(proaclres['rows'])) # Set System Functions Status resp_data['sysfunc'] = False if fnid <= self.manager.db_info[did]['datlastsysoid']: resp_data['sysfunc'] = True # Get formatted Security Labels if 'seclabels' in resp_data: resp_data.update(parse_sec_labels_from_db(resp_data['seclabels'])) # Get formatted Variable resp_data.update( parse_variables_from_db([{ "setconfig": resp_data['proconfig'] }])) return resp_data