def _fetch_properties(self, umid): """ This function fetch the properties of the User Mapping. :param umid: :return: """ sql = render_template("/".join([self.template_path, self._PROPERTIES_SQL]), umid=umid, conn=self.conn) status, res = self.conn.execute_dict(sql) if not status: return False, internal_server_error(errormsg=res) if len(res['rows']) == 0: return False, gone(self.not_found_error_msg()) res['rows'][0]['is_sys_obj'] = ( res['rows'][0]['oid'] <= self.datlastsysoid or self.datistemplate) if res['rows'][0]['umoptions'] is not None: res['rows'][0]['umoptions'] = tokenize_options( res['rows'][0]['umoptions'], 'umoption', 'umvalue' ) return True, res['rows'][0]
def list(self, gid, sid, did): """ This function is used to list all the foreign data wrapper nodes within that collection. Args: gid: Server Group ID sid: Server ID did: Database ID """ sql = render_template("/".join([self.template_path, self._PROPERTIES_SQL]), conn=self.conn) status, res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res) for row in res['rows']: if row['fdwoptions'] is not None: row['fdwoptions'] = tokenize_options( row['fdwoptions'], 'fdwoption', 'fdwvalue' ) return ajax_response( response=res['rows'], status=200 )
def list(self, gid, sid, did): """ This function is used to list all the foreign data wrapper nodes within that collection. Args: gid: Server Group ID sid: Server ID did: Database ID """ sql = render_template("/".join([self.template_path, 'properties.sql']), conn=self.conn) status, res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res) for row in res['rows']: if row['fdwoptions'] is not None: row['fdwoptions'] = tokenize_options( row['fdwoptions'], 'fdwoption', 'fdwvalue' ) return ajax_response( response=res['rows'], status=200 )
def properties(self, gid, sid, did, fid, fsid, umid): """ This function will show the properties of the selected user mapping node. Args: gid: Server Group ID sid: Server ID did: Database ID fid: Foreign data wrapper ID fsid: Foreign server ID umid: User mapping ID """ sql = render_template("/".join([self.template_path, 'properties.sql']), umid=umid, conn=self.conn) 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 user mapping information.")) if res['rows'][0]['umoptions'] is not None: res['rows'][0]['umoptions'] = tokenize_options( res['rows'][0]['umoptions'], 'umoption', 'umvalue') return ajax_response(response=res['rows'][0], status=200)
def sql(self, gid, sid, did, fid, fsid, umid): """ This function will generate sql to show it in sql pane for the selected user mapping node. Args: gid: Server Group ID sid: Server ID did: Database ID fid: Foreign data wrapper ID fsid: Foreign server ID umid: User mapping ID """ sql = render_template("/".join( [self.template_path, self._PROPERTIES_SQL]), umid=umid, conn=self.conn) 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 user mapping information.")) is_valid_options = False if res['rows'][0]['umoptions'] is not None: res['rows'][0]['umoptions'] = tokenize_options( res['rows'][0]['umoptions'], 'umoption', 'umvalue') if len(res['rows'][0]['umoptions']) > 0: is_valid_options = True sql = render_template("/".join( [self.template_path, self._PROPERTIES_SQL]), fserid=fsid, conn=self.conn) status, res1 = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res1) fdw_data = res1['rows'][0] sql = '' sql = render_template("/".join([self.template_path, self._CREATE_SQL]), data=res['rows'][0], fdwdata=fdw_data, is_valid_options=is_valid_options, conn=self.conn) sql += "\n" sql_header = u"""-- User Mapping : {0} -- DROP USER MAPPING FOR {0} SERVER {1} """.format(res['rows'][0]['name'], fdw_data['name']) sql = sql_header + sql return ajax_response(response=sql.strip('\n'))
def sql(self, gid, sid, did, fid): """ This function will generate sql to show it in sql pane for the selected foreign data wrapper node. Args: gid: Server Group ID sid: Server ID did: Database ID fid: Foreign data wrapper ID """ sql = render_template("/".join([self.template_path, 'properties.sql']), fid=fid, conn=self.conn ) status, res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res) is_valid_options = False if res['rows'][0]['fdwoptions'] is not None: res['rows'][0]['fdwoptions'] = tokenize_options( res['rows'][0]['fdwoptions'], 'fdwoption', 'fdwvalue' ) if len(res['rows'][0]['fdwoptions']) > 0: is_valid_options = True sql = render_template("/".join([self.template_path, 'acl.sql']), fid=fid) status, fdw_acl_res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=fdw_acl_res) for row in fdw_acl_res['rows']: privilege = parse_priv_from_db(row) if row['deftype'] in res['rows'][0]: res['rows'][0][row['deftype']].append(privilege) else: res['rows'][0][row['deftype']] = [privilege] # To format privileges if 'fdwacl' in res['rows'][0]: res['rows'][0]['fdwacl'] = parse_priv_to_db(res['rows'][0]['fdwacl'], ['U']) sql = '' sql = render_template("/".join([self.template_path, 'create.sql']), data=res['rows'][0], conn=self.conn, is_valid_options=is_valid_options ) sql += "\n" sql_header = u"""-- Foreign Data Wrapper: {0} -- DROP FOREIGN DATA WRAPPER {0} """.format(res['rows'][0]['name']) sql = sql_header + sql return ajax_response(response=sql.strip('\n'))
def sql(self, gid, sid, did, fid, fsid, umid): """ This function will generate sql to show it in sql pane for the selected user mapping node. Args: gid: Server Group ID sid: Server ID did: Database ID fid: Foreign data wrapper ID fsid: Foreign server ID umid: User mapping ID """ sql = render_template("/".join([self.template_path, 'properties.sql']), umid=umid, conn=self.conn) 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 user mapping information.") ) is_valid_options = False if res['rows'][0]['umoptions'] is not None: res['rows'][0]['umoptions'] = tokenize_options( res['rows'][0]['umoptions'], 'umoption', 'umvalue' ) if len(res['rows'][0]['umoptions']) > 0: is_valid_options = True sql = render_template("/".join([self.template_path, 'properties.sql']), fserid=fsid, conn=self.conn ) status, res1 = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res1) fdw_data = res1['rows'][0] sql = '' sql = render_template("/".join([self.template_path, 'create.sql']), data=res['rows'][0], fdwdata=fdw_data, is_valid_options=is_valid_options, conn=self.conn) sql += "\n" sql_header = u"""-- User Mapping : {0} -- DROP USER MAPPING FOR {0} SERVER {1} """.format(res['rows'][0]['name'], fdw_data['name']) sql = sql_header + sql return ajax_response(response=sql.strip('\n'))
def get_sql(self, gid, sid, data, did, fid=None): """ This function will generate sql from model data. Args: gid: Server Group ID sid: Server ID did: Database ID data: Contains the data of the selected foreign data wrapper node fid: foreign data wrapper ID """ required_args = ['name'] if fid is not None: sql = render_template("/".join( [self.template_path, self._PROPERTIES_SQL]), fid=fid, conn=self.conn) 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 foreign" " data wrapper information.")) if res['rows'][0]['fdwoptions'] is not None: res['rows'][0]['fdwoptions'] = tokenize_options( res['rows'][0]['fdwoptions'], 'fdwoption', 'fdwvalue') self._check_and_parse_priv_to_db(data) old_data = res['rows'][0] for arg in required_args: if arg not in data: data[arg] = old_data[arg] # Allow user to set the blank value in fdwvalue # field in option model is_valid_added_options, \ is_valid_changed_options = self._check_validate_options(data) sql = render_template( "/".join([self.template_path, self._UPDATE_SQL]), data=data, o_data=old_data, is_valid_added_options=is_valid_added_options, is_valid_changed_options=is_valid_changed_options, conn=self.conn) return sql.strip('\n'), \ data['name'] if 'name' in data else old_data['name'] else: sql = self._get_create_sql(data) return sql.strip('\n'), data['name']
def properties(self, gid, sid, did, fid, fsid): """ This function will show the properties of the selected foreign server node. Args: gid: Server Group ID sid: Server ID did: Database ID fid: foreign data wrapper ID fsid: foreign server ID """ sql = render_template("/".join([self.template_path, self._PROPERTIES_SQL]), fsid=fsid, conn=self.conn) 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 foreign server information.") ) res['rows'][0]['is_sys_obj'] = ( res['rows'][0]['fsrvid'] <= self.datlastsysoid) if res['rows'][0]['fsrvoptions'] is not None: res['rows'][0]['fsrvoptions'] = tokenize_options( res['rows'][0]['fsrvoptions'], 'fsrvoption', 'fsrvvalue' ) sql = render_template("/".join([self.template_path, self._ACL_SQL]), fsid=fsid ) status, fs_rv_acl_res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=fs_rv_acl_res) for row in fs_rv_acl_res['rows']: privilege = parse_priv_from_db(row) if row['deftype'] in res['rows'][0]: res['rows'][0][row['deftype']].append(privilege) else: res['rows'][0][row['deftype']] = [privilege] return ajax_response( response=res['rows'][0], status=200 )
def properties(self, gid, sid, did, fid): """ This function will show the properties of the selected foreign data wrapper node. Args: gid: Server Group ID sid: Server ID did: Database ID fid: foreign data wrapper ID """ sql = render_template("/".join([self.template_path, 'properties.sql']), fid=fid, conn=self.conn ) 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 foreign data" " wrapper information.") ) if res['rows'][0]['fdwoptions'] is not None: res['rows'][0]['fdwoptions'] = tokenize_options( res['rows'][0]['fdwoptions'], 'fdwoption', 'fdwvalue' ) sql = render_template("/".join([self.template_path, 'acl.sql']), fid=fid ) status, fdw_acl_res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=fdw_acl_res) for row in fdw_acl_res['rows']: privilege = parse_priv_from_db(row) if row['deftype'] in res['rows'][0]: res['rows'][0][row['deftype']].append(privilege) else: res['rows'][0][row['deftype']] = [privilege] return ajax_response( response=res['rows'][0], status=200 )
def _fetch_properties(self, fid): """ This function fetch the properties of the FDW. :param fid: :return: """ sql = render_template("/".join([self.template_path, self._PROPERTIES_SQL]), fid=fid, conn=self.conn ) status, res = self.conn.execute_dict(sql) status, res = self.conn.execute_dict(sql) if not status: return False, internal_server_error(errormsg=res) if len(res['rows']) == 0: return False, gone( gettext("Could not find the foreign data" " wrapper information.") ) res['rows'][0]['is_sys_obj'] = ( res['rows'][0]['oid'] <= self.datlastsysoid or self.datistemplate) if res['rows'][0]['fdwoptions'] is not None: res['rows'][0]['fdwoptions'] = tokenize_options( res['rows'][0]['fdwoptions'], 'fdwoption', 'fdwvalue' ) sql = render_template("/".join([self.template_path, self._ACL_SQL]), fid=fid ) status, fdw_acl_res = self.conn.execute_dict(sql) if not status: return False, internal_server_error(errormsg=fdw_acl_res) for row in fdw_acl_res['rows']: privilege = parse_priv_from_db(row) if row['deftype'] in res['rows'][0]: res['rows'][0][row['deftype']].append(privilege) else: res['rows'][0][row['deftype']] = [privilege] return True, res['rows'][0]
def _fetch_properties(self, fsid): """ This function fetch the properties of the Foreign server. :param fsid: :return: """ sql = render_template("/".join( [self.template_path, self._PROPERTIES_SQL]), fsid=fsid, conn=self.conn) status, res = self.conn.execute_dict(sql) if not status: return False, internal_server_error(errormsg=res) if len(res['rows']) == 0: return False, gone(self.not_found_error_msg()) res['rows'][0]['is_sys_obj'] = ( res['rows'][0]['oid'] <= self._DATABASE_LAST_SYSTEM_OID or self.datistemplate) if res['rows'][0]['fsrvoptions'] is not None: res['rows'][0]['fsrvoptions'] = tokenize_options( res['rows'][0]['fsrvoptions'], 'fsrvoption', 'fsrvvalue') sql = render_template("/".join([self.template_path, self._ACL_SQL]), fsid=fsid) status, fs_rv_acl_res = self.conn.execute_dict(sql) if not status: return False, internal_server_error(errormsg=fs_rv_acl_res) for row in fs_rv_acl_res['rows']: privilege = parse_priv_from_db(row) if row['deftype'] in res['rows'][0]: res['rows'][0][row['deftype']].append(privilege) else: res['rows'][0][row['deftype']] = [privilege] return True, res['rows'][0]
def properties(self, gid, sid, did, fid, fsid, umid): """ This function will show the properties of the selected user mapping node. Args: gid: Server Group ID sid: Server ID did: Database ID fid: Foreign data wrapper ID fsid: Foreign server ID umid: User mapping ID """ sql = render_template("/".join([self.template_path, 'properties.sql']), umid=umid, conn=self.conn) 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 user mapping information.") ) if res['rows'][0]['umoptions'] is not None: res['rows'][0]['umoptions'] = tokenize_options( res['rows'][0]['umoptions'], 'umoption', 'umvalue' ) return ajax_response( response=res['rows'][0], status=200 )
def get_sql(self, **kwargs): """ This function will generate sql from model data. Args: kwargs: Server Group ID """ fsid = kwargs.get('fsid') data = kwargs.get('data') umid = kwargs.get('umid', None) required_args = [ 'name' ] if umid is not None: sql = render_template("/".join([self.template_path, self._PROPERTIES_SQL]), umid=umid, conn=self.conn) 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()) if res['rows'][0]['umoptions'] is not None: res['rows'][0]['umoptions'] = tokenize_options( res['rows'][0]['umoptions'], 'umoption', 'umvalue' ) old_data = res['rows'][0] sql = render_template("/".join([self.template_path, self._PROPERTIES_SQL]), fserid=fsid, conn=self.conn) status, res1 = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res1) fdw_data = res1['rows'][0] # Get SQL for update. sql, name = self.get_update_sql(data, old_data, required_args, fdw_data) return sql, name else: sql = render_template("/".join([self.template_path, self._PROPERTIES_SQL]), fserid=fsid, conn=self.conn) status, res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res) fdw_data = res['rows'][0] is_valid_options = False if 'umoptions' in data: is_valid_options, data['umoptions'] = validate_options( data['umoptions'], 'umoption', 'umvalue' ) sql = render_template("/".join([self.template_path, self._CREATE_SQL]), data=data, fdwdata=fdw_data, is_valid_options=is_valid_options, conn=self.conn) sql += "\n" return sql, data['name']
def sql(self, gid, sid, did, fid, fsid, json_resp=True): """ This function will generate sql to show it in sql pane for the selected foreign server node. Args: gid: Server Group ID sid: Server ID did: Database ID fid: Foreign data wrapper ID fsid: Foreign server ID json_resp: """ sql = render_template("/".join([self.template_path, self._PROPERTIES_SQL]), fsid=fsid, conn=self.conn) 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()) if fid is None and 'fdwid' in res['rows'][0]: fid = res['rows'][0]['fdwid'] is_valid_options = False if res['rows'][0]['fsrvoptions'] is not None: res['rows'][0]['fsrvoptions'] = tokenize_options( res['rows'][0]['fsrvoptions'], 'fsrvoption', 'fsrvvalue' ) if len(res['rows'][0]['fsrvoptions']) > 0: is_valid_options = True sql = render_template("/".join([self.template_path, self._ACL_SQL]), fsid=fsid) status, fs_rv_acl_res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=fs_rv_acl_res) for row in fs_rv_acl_res['rows']: privilege = parse_priv_from_db(row) if row['deftype'] in res['rows'][0]: res['rows'][0][row['deftype']].append(privilege) else: res['rows'][0][row['deftype']] = [privilege] # To format privileges if 'fsrvacl' in res['rows'][0]: res['rows'][0]['fsrvacl'] = parse_priv_to_db( res['rows'][0]['fsrvacl'], ['U'] ) sql = render_template("/".join([self.template_path, self._PROPERTIES_SQL]), fdwid=fid, conn=self.conn) status, res1 = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res1) fdw_data = res1['rows'][0] sql = '' sql = render_template("/".join([self.template_path, self._CREATE_SQL]), data=res['rows'][0], fdwdata=fdw_data, is_valid_options=is_valid_options, conn=self.conn) sql += "\n" sql_header = """-- Foreign Server: {0} -- DROP SERVER IF EXISTS {0} """.format(res['rows'][0]['name']) sql = sql_header + sql if not json_resp: return sql.strip('\n') return ajax_response(response=sql.strip('\n'))
def get_sql(self, gid, sid, data, did, fid, fsid=None): """ This function will generate sql from model data. Args: gid: Server Group ID sid: Server ID did: Database ID data: Contains the data of the selected foreign server node fid: foreign data wrapper ID fsid: foreign server ID """ if fsid is not None: sql = render_template("/".join([self.template_path, self._PROPERTIES_SQL]), fsid=fsid, conn=self.conn) status, res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res) elif len(res['rows']) == 0: return gone(self.not_found_error_msg()) elif res['rows'][0]['fsrvoptions'] is not None: res['rows'][0]['fsrvoptions'] = tokenize_options( res['rows'][0]['fsrvoptions'], 'fsrvoption', 'fsrvvalue' ) ForeignServerView._get_fsvr_acl(data) old_data = res['rows'][0] is_valid_added_options, \ is_valid_changed_options = \ ForeignServerView._validate_fsvr_options(data, old_data) sql = render_template( "/".join([self.template_path, self._UPDATE_SQL]), data=data, o_data=old_data, is_valid_added_options=is_valid_added_options, is_valid_changed_options=is_valid_changed_options, conn=self.conn ) return sql.strip('\n'), \ data['name'] if 'name' in data else old_data['name'] else: sql = render_template("/".join([self.template_path, self._PROPERTIES_SQL]), fdwid=fid, conn=self.conn) status, res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res) fdw_data = res['rows'][0] ForeignServerView._parse_priv(data) is_valid_options = False if 'fsrvoptions' in data: is_valid_options, data['fsrvoptions'] = validate_options( data['fsrvoptions'], 'fsrvoption', 'fsrvvalue' ) sql = render_template("/".join([self.template_path, self._CREATE_SQL]), data=data, fdwdata=fdw_data, is_valid_options=is_valid_options, conn=self.conn) sql += "\n" return sql, data['name']
def get_sql(self, gid, sid, data, did, fid, fsid, umid=None): """ This function will generate sql from model data. Args: gid: Server Group ID sid: Server ID did: Database ID data: Contains the data of the selected user mapping node fid: foreign data wrapper ID fsid: foreign server ID umid: User mapping ID """ required_args = [ 'name' ] if umid is not None: sql = render_template("/".join([self.template_path, 'properties.sql']), umid=umid, conn=self.conn) 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 user mapping information.") ) if res['rows'][0]['umoptions'] is not None: res['rows'][0]['umoptions'] = tokenize_options( res['rows'][0]['umoptions'], 'umoption', 'umvalue' ) old_data = res['rows'][0] sql = render_template("/".join([self.template_path, 'properties.sql']), fserid=fsid, conn=self.conn) status, res1 = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res1) fdw_data = res1['rows'][0] for arg in required_args: if arg not in data: data[arg] = old_data[arg] # Allow user to set the blank value in fdwvalue # field in option model is_valid_added_options = is_valid_changed_options = False if 'umoptions' in data and 'added' in data['umoptions']: is_valid_added_options, data['umoptions']['added'] =\ validate_options( data['umoptions']['added'], 'umoption', 'umvalue') if 'umoptions' in data and 'changed' in data['umoptions']: is_valid_changed_options, data['umoptions']['changed'] =\ validate_options( data['umoptions']['changed'], 'umoption', 'umvalue') sql = render_template( "/".join([self.template_path, 'update.sql']), data=data, o_data=old_data, is_valid_added_options=is_valid_added_options, is_valid_changed_options=is_valid_changed_options, fdwdata=fdw_data, conn=self.conn ) return sql, data['name'] if 'name' in data else old_data['name'] else: sql = render_template("/".join([self.template_path, 'properties.sql']), fserid=fsid, conn=self.conn) status, res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res) fdw_data = res['rows'][0] is_valid_options = False if 'umoptions' in data: is_valid_options, data['umoptions'] = validate_options( data['umoptions'], 'umoption', 'umvalue' ) sql = render_template("/".join([self.template_path, 'create.sql']), data=data, fdwdata=fdw_data, is_valid_options=is_valid_options, conn=self.conn) sql += "\n" return sql, data['name']
def sql(self, gid, sid, did, fid, json_resp=True): """ This function will generate sql to show it in sql pane for the selected foreign data wrapper node. Args: gid: Server Group ID sid: Server ID did: Database ID fid: Foreign data wrapper ID json_resp: """ sql = render_template("/".join( [self.template_path, self._PROPERTIES_SQL]), fid=fid, conn=self.conn) 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 foreign data wrapper on the server.")) is_valid_options = False if res['rows'][0]['fdwoptions'] is not None: res['rows'][0]['fdwoptions'] = tokenize_options( res['rows'][0]['fdwoptions'], 'fdwoption', 'fdwvalue') if len(res['rows'][0]['fdwoptions']) > 0: is_valid_options = True sql = render_template("/".join([self.template_path, self._ACL_SQL]), fid=fid) status, fdw_acl_res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=fdw_acl_res) for row in fdw_acl_res['rows']: privilege = parse_priv_from_db(row) if row['deftype'] in res['rows'][0]: res['rows'][0][row['deftype']].append(privilege) else: res['rows'][0][row['deftype']] = [privilege] # To format privileges if 'fdwacl' in res['rows'][0]: res['rows'][0]['fdwacl'] = parse_priv_to_db( res['rows'][0]['fdwacl'], ['U']) sql = '' sql = render_template("/".join([self.template_path, self._CREATE_SQL]), data=res['rows'][0], conn=self.conn, is_valid_options=is_valid_options) sql += "\n" sql_header = """-- Foreign Data Wrapper: {0}\n\n""".format( res['rows'][0]['name']) sql_header += """-- DROP FOREIGN DATA WRAPPER IF EXISTS {0} """.format(self.qtIdent(self.conn, res['rows'][0]['name'])) sql = sql_header + sql if not json_resp: return sql.strip('\n') return ajax_response(response=sql.strip('\n'))
def get_sql(self, gid, sid, data, did, fid, fsid=None): """ This function will generate sql from model data. Args: gid: Server Group ID sid: Server ID did: Database ID data: Contains the data of the selected foreign server node fid: foreign data wrapper ID fsid: foreign server ID """ required_args = [ 'name' ] if fsid is not None: sql = render_template("/".join([self.template_path, 'properties.sql']), fsid=fsid, conn=self.conn) status, res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res) if res['rows'][0]['fsrvoptions'] is not None: res['rows'][0]['fsrvoptions'] = tokenize_options( res['rows'][0]['fsrvoptions'], 'fsrvoption', 'fsrvvalue' ) for key in ['fsrvacl']: if key in data and data[key] is not None: if 'added' in data[key]: data[key]['added'] = parse_priv_to_db(data[key]['added'], ['U']) if 'changed' in data[key]: data[key]['changed'] = parse_priv_to_db(data[key]['changed'], ['U']) if 'deleted' in data[key]: data[key]['deleted'] = parse_priv_to_db(data[key]['deleted'], ['U']) old_data = res['rows'][0] for arg in required_args: if arg not in data: data[arg] = old_data[arg] is_valid_added_options = is_valid_changed_options = False if 'fsrvoptions' in data and 'added' in data['fsrvoptions']: is_valid_added_options, data['fsrvoptions']['added'] = validate_options( data['fsrvoptions']['added'], 'fsrvoption', 'fsrvvalue' ) if 'fsrvoptions' in data and 'changed' in data['fsrvoptions']: is_valid_changed_options, data['fsrvoptions']['changed'] = validate_options( data['fsrvoptions']['changed'], 'fsrvoption', 'fsrvvalue' ) sql = render_template("/".join([self.template_path, 'update.sql']), data=data, o_data=old_data, is_valid_added_options=is_valid_added_options, is_valid_changed_options=is_valid_changed_options, conn=self.conn) return sql, data['name'] if 'name' in data else old_data['name'] else: sql = render_template("/".join([self.template_path, 'properties.sql']), fdwid=fid, conn=self.conn) status, res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res) fdw_data = res['rows'][0] for key in ['fsrvacl']: if key in data and data[key] is not None: data[key] = parse_priv_to_db(data[key], ['U']) is_valid_options = False if 'fsrvoptions' in data: is_valid_options, data['fsrvoptions'] = validate_options( data['fsrvoptions'], 'fsrvoption', 'fsrvvalue' ) sql = render_template("/".join([self.template_path, 'create.sql']), data=data, fdwdata=fdw_data, is_valid_options=is_valid_options, conn=self.conn) sql += "\n" return sql, data['name']
def get_sql(self, gid, sid, data, did, fid=None): """ This function will generate sql from model data. Args: gid: Server Group ID sid: Server ID did: Database ID data: Contains the data of the selected foreign data wrapper node fid: foreign data wrapper ID """ required_args = [ 'name' ] if fid is not None: sql = render_template("/".join([self.template_path, 'properties.sql']), fid=fid, conn=self.conn ) 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 foreign" " data wrapper information.") ) if res['rows'][0]['fdwoptions'] is not None: res['rows'][0]['fdwoptions'] = tokenize_options( res['rows'][0]['fdwoptions'], 'fdwoption', 'fdwvalue' ) for key in ['fdwacl']: if key in data and data[key] is not None: if 'added' in data[key]: data[key]['added'] = parse_priv_to_db( data[key]['added'], ['U'] ) if 'changed' in data[key]: data[key]['changed'] = parse_priv_to_db( data[key]['changed'], ['U'] ) if 'deleted' in data[key]: data[key]['deleted'] = parse_priv_to_db( data[key]['deleted'], ['U'] ) old_data = res['rows'][0] for arg in required_args: if arg not in data: data[arg] = old_data[arg] # Allow user to set the blank value in fdwvalue # field in option model is_valid_added_options = is_valid_changed_options = False if 'fdwoptions' in data and 'added' in data['fdwoptions']: is_valid_added_options, data['fdwoptions']['added'] = \ validate_options( data['fdwoptions']['added'], 'fdwoption', 'fdwvalue') if 'fdwoptions' in data and 'changed' in data['fdwoptions']: is_valid_changed_options, data['fdwoptions']['changed'] = \ validate_options( data['fdwoptions']['changed'], 'fdwoption', 'fdwvalue') sql = render_template( "/".join([self.template_path, 'update.sql']), data=data, o_data=old_data, is_valid_added_options=is_valid_added_options, is_valid_changed_options=is_valid_changed_options, conn=self.conn ) return sql, data['name'] if 'name' in data else old_data['name'] else: for key in ['fdwacl']: if key in data and data[key] is not None: data[key] = parse_priv_to_db(data[key], ['U']) # Allow user to set the blank value in # fdwvalue field in option model is_valid_options = False if 'fdwoptions' in data: is_valid_options, data['fdwoptions'] = validate_options( data['fdwoptions'], 'fdwoption', 'fdwvalue' ) sql = render_template("/".join([self.template_path, 'create.sql']), data=data, conn=self.conn, is_valid_options=is_valid_options ) return sql, data['name']
def get_sql(self, gid, sid, data, did, fid, fsid, umid=None): """ This function will generate sql from model data. Args: gid: Server Group ID sid: Server ID did: Database ID data: Contains the data of the selected user mapping node fid: foreign data wrapper ID fsid: foreign server ID umid: User mapping ID """ required_args = ['name'] if umid is not None: sql = render_template("/".join( [self.template_path, 'properties.sql']), umid=umid, conn=self.conn) 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 user mapping information.")) if res['rows'][0]['umoptions'] is not None: res['rows'][0]['umoptions'] = tokenize_options( res['rows'][0]['umoptions'], 'umoption', 'umvalue') old_data = res['rows'][0] sql = render_template("/".join( [self.template_path, 'properties.sql']), fserid=fsid, conn=self.conn) status, res1 = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res1) fdw_data = res1['rows'][0] for arg in required_args: if arg not in data: data[arg] = old_data[arg] # Allow user to set the blank value in fdwvalue # field in option model is_valid_added_options = is_valid_changed_options = False if 'umoptions' in data and 'added' in data['umoptions']: is_valid_added_options, data['umoptions']['added'] =\ validate_options( data['umoptions']['added'], 'umoption', 'umvalue') if 'umoptions' in data and 'changed' in data['umoptions']: is_valid_changed_options, data['umoptions']['changed'] =\ validate_options( data['umoptions']['changed'], 'umoption', 'umvalue') sql = render_template( "/".join([self.template_path, 'update.sql']), data=data, o_data=old_data, is_valid_added_options=is_valid_added_options, is_valid_changed_options=is_valid_changed_options, fdwdata=fdw_data, conn=self.conn) return sql, data['name'] if 'name' in data else old_data['name'] else: sql = render_template("/".join( [self.template_path, 'properties.sql']), fserid=fsid, conn=self.conn) status, res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res) fdw_data = res['rows'][0] is_valid_options = False if 'umoptions' in data: is_valid_options, data['umoptions'] = validate_options( data['umoptions'], 'umoption', 'umvalue') sql = render_template("/".join([self.template_path, 'create.sql']), data=data, fdwdata=fdw_data, is_valid_options=is_valid_options, conn=self.conn) sql += "\n" return sql, data['name']
def sql(self, gid, sid, did, fid): """ This function will generate sql to show it in sql pane for the selected foreign data wrapper node. Args: gid: Server Group ID sid: Server ID did: Database ID fid: Foreign data wrapper ID """ sql = render_template("/".join([self.template_path, 'properties.sql']), fid=fid, conn=self.conn ) 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 foreign data wrapper on the server.") ) is_valid_options = False if res['rows'][0]['fdwoptions'] is not None: res['rows'][0]['fdwoptions'] = tokenize_options( res['rows'][0]['fdwoptions'], 'fdwoption', 'fdwvalue' ) if len(res['rows'][0]['fdwoptions']) > 0: is_valid_options = True sql = render_template("/".join([self.template_path, 'acl.sql']), fid=fid) status, fdw_acl_res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=fdw_acl_res) for row in fdw_acl_res['rows']: privilege = parse_priv_from_db(row) if row['deftype'] in res['rows'][0]: res['rows'][0][row['deftype']].append(privilege) else: res['rows'][0][row['deftype']] = [privilege] # To format privileges if 'fdwacl' in res['rows'][0]: res['rows'][0]['fdwacl'] = parse_priv_to_db( res['rows'][0]['fdwacl'], ['U'] ) sql = '' sql = render_template("/".join([self.template_path, 'create.sql']), data=res['rows'][0], conn=self.conn, is_valid_options=is_valid_options ) sql += "\n" sql_header = u"""-- Foreign Data Wrapper: {0} -- DROP FOREIGN DATA WRAPPER {0} """.format(res['rows'][0]['name']) sql = sql_header + sql return ajax_response(response=sql.strip('\n'))
def get_sql(self, **kwargs): """ This function will generate sql from model data. Args: kwargs: Server Group ID """ fsid = kwargs.get('fsid') data = kwargs.get('data') umid = kwargs.get('umid', None) required_args = ['name'] if umid is not None: sql = render_template("/".join( [self.template_path, self._PROPERTIES_SQL]), umid=umid, conn=self.conn) 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 user mapping information.")) if res['rows'][0]['umoptions'] is not None: res['rows'][0]['umoptions'] = tokenize_options( res['rows'][0]['umoptions'], 'umoption', 'umvalue') old_data = res['rows'][0] sql = render_template("/".join( [self.template_path, self._PROPERTIES_SQL]), fserid=fsid, conn=self.conn) status, res1 = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res1) fdw_data = res1['rows'][0] for arg in required_args: if arg not in data: data[arg] = old_data[arg] # Allow user to set the blank value in fdwvalue # field in option model is_valid_added_options = is_valid_changed_options = False if 'umoptions' in data and 'added' in data['umoptions']: is_valid_added_options, data['umoptions']['added'] =\ validate_options( data['umoptions']['added'], 'umoption', 'umvalue') if 'umoptions' in data and 'changed' in data['umoptions']: is_valid_changed_options, data['umoptions']['changed'] =\ validate_options( data['umoptions']['changed'], 'umoption', 'umvalue') sql = render_template( "/".join([self.template_path, self._UPDATE_SQL]), data=data, o_data=old_data, is_valid_added_options=is_valid_added_options, is_valid_changed_options=is_valid_changed_options, fdwdata=fdw_data, conn=self.conn) return sql, data['name'] if 'name' in data else old_data['name'] else: sql = render_template("/".join( [self.template_path, self._PROPERTIES_SQL]), fserid=fsid, conn=self.conn) status, res = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res) fdw_data = res['rows'][0] is_valid_options = False if 'umoptions' in data: is_valid_options, data['umoptions'] = validate_options( data['umoptions'], 'umoption', 'umvalue') sql = render_template("/".join( [self.template_path, self._CREATE_SQL]), data=data, fdwdata=fdw_data, is_valid_options=is_valid_options, conn=self.conn) sql += "\n" return sql, data['name']
def get_sql(self, gid, sid, data, did, fid=None): """ This function will generate sql from model data. Args: gid: Server Group ID sid: Server ID did: Database ID data: Contains the data of the selected foreign data wrapper node fid: foreign data wrapper ID """ required_args = ['name'] if fid is not None: sql = render_template("/".join( [self.template_path, 'properties.sql']), fid=fid, conn=self.conn) 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 foreign" " data wrapper information.")) if res['rows'][0]['fdwoptions'] is not None: res['rows'][0]['fdwoptions'] = tokenize_options( res['rows'][0]['fdwoptions'], 'fdwoption', 'fdwvalue') for key in ['fdwacl']: if key in data and data[key] is not None: if 'added' in data[key]: data[key]['added'] = parse_priv_to_db( data[key]['added'], ['U']) if 'changed' in data[key]: data[key]['changed'] = parse_priv_to_db( data[key]['changed'], ['U']) if 'deleted' in data[key]: data[key]['deleted'] = parse_priv_to_db( data[key]['deleted'], ['U']) old_data = res['rows'][0] for arg in required_args: if arg not in data: data[arg] = old_data[arg] # Allow user to set the blank value in fdwvalue # field in option model is_valid_added_options = is_valid_changed_options = False if 'fdwoptions' in data and 'added' in data['fdwoptions']: is_valid_added_options, data['fdwoptions']['added'] = \ validate_options( data['fdwoptions']['added'], 'fdwoption', 'fdwvalue') if 'fdwoptions' in data and 'changed' in data['fdwoptions']: is_valid_changed_options, data['fdwoptions']['changed'] = \ validate_options( data['fdwoptions']['changed'], 'fdwoption', 'fdwvalue') sql = render_template( "/".join([self.template_path, 'update.sql']), data=data, o_data=old_data, is_valid_added_options=is_valid_added_options, is_valid_changed_options=is_valid_changed_options, conn=self.conn) return sql, data['name'] if 'name' in data else old_data['name'] else: for key in ['fdwacl']: if key in data and data[key] is not None: data[key] = parse_priv_to_db(data[key], ['U']) # Allow user to set the blank value in # fdwvalue field in option model is_valid_options = False if 'fdwoptions' in data: is_valid_options, data['fdwoptions'] = validate_options( data['fdwoptions'], 'fdwoption', 'fdwvalue') sql = render_template("/".join([self.template_path, 'create.sql']), data=data, conn=self.conn, is_valid_options=is_valid_options) return sql, data['name']
def sql(self, gid, sid, did, fid, fsid, **kwargs): """ This function will generate sql to show it in sql pane for the selected user mapping node. Args: gid: Server Group ID sid: Server ID did: Database ID fid: Foreign data wrapper ID fsid: Foreign server ID kwargs: """ umid = kwargs.get('umid') json_resp = kwargs.get('json_resp', True) sql = render_template("/".join([self.template_path, self._PROPERTIES_SQL]), umid=umid, conn=self.conn) 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()) if fsid is None and 'fsid' in res['rows'][0]: fsid = res['rows'][0]['fsid'] is_valid_options = False if res['rows'][0]['umoptions'] is not None: res['rows'][0]['umoptions'] = tokenize_options( res['rows'][0]['umoptions'], 'umoption', 'umvalue' ) if len(res['rows'][0]['umoptions']) > 0: is_valid_options = True sql = render_template("/".join([self.template_path, self._PROPERTIES_SQL]), fserid=fsid, conn=self.conn ) status, res1 = self.conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res1) fdw_data = res1['rows'][0] sql = '' sql = render_template("/".join([self.template_path, self._CREATE_SQL]), data=res['rows'][0], fdwdata=fdw_data, is_valid_options=is_valid_options, conn=self.conn) sql += "\n" sql_header = """-- User Mapping : {0} -- DROP USER MAPPING IF EXISTS FOR {0} SERVER {1} """.format(res['rows'][0]['name'], fdw_data['name']) sql = sql_header + sql if not json_resp: return sql.strip('\n') return ajax_response(response=sql.strip('\n'))