Example #1
0
    def update(self, gid, sid, scid, did, tid, plid=None):
        """
        This function will update policy object
        :param plid: policy id
        :param did: database id
        :param sid: server id
        :param gid: group id
        :param tid: table id
        :param scid: Schema ID
        :return:
        """
        data = request.form if request.form else json.loads(request.data,
                                                            encoding='utf-8')
        try:
            sql, name = row_security_policies_utils.get_sql(
                self.conn,
                data=data,
                scid=scid,
                plid=plid,
                policy_table_id=tid,
                schema=self.schema,
                table=self.table)

            # Most probably this is due to error
            if not isinstance(sql, str):
                return sql
            status, res = self.conn.execute_scalar(sql)
            if not status:
                return internal_server_error(errormsg=res)

            return jsonify(node=self.blueprint.generate_browser_node(
                plid, tid, name, icon="icon-row_security_policy"))

        except Exception as e:
            return internal_server_error(errormsg=str(e))
Example #2
0
    def get_sql_from_diff(self, **kwargs):
        """
        This function is used to get the DDL/DML statements.
        :param kwargs
        :return:
        """
        sid = kwargs.get('sid')
        did = kwargs.get('did')
        scid = kwargs.get('scid')
        tid = kwargs.get('tid')
        oid = kwargs.get('plid')
        data = kwargs.get('data', None)
        drop_req = kwargs.get('drop_req', False)
        target_schema = kwargs.get('target_schema', None)

        if data:
            data['schema'] = self.schema
            data['table'] = self.table
            sql, name = row_security_policies_utils.get_sql(
                self.conn,
                data=data,
                scid=scid,
                plid=oid,
                policy_table_id=tid,
                schema=self.schema,
                table=self.table)

            sql = sql.strip('\n').strip(' ')

        else:
            schema = self.schema
            if target_schema:
                schema = target_schema

            sql = row_security_policies_utils.get_reverse_engineered_sql(
                self.conn,
                schema=schema,
                table=self.table,
                scid=scid,
                plid=oid,
                policy_table_id=tid,
                datlastsysoid=self._DATABASE_LAST_SYSTEM_OID,
                with_header=False)

        drop_sql = ''
        if drop_req:
            drop_sql = '\n' + self.delete(gid=1,
                                          sid=sid,
                                          did=did,
                                          scid=scid,
                                          tid=tid,
                                          plid=oid,
                                          only_sql=True)
        if drop_sql != '':
            sql = drop_sql + '\n\n' + sql
        return sql
Example #3
0
    def get_sql_from_diff(self,
                          gid,
                          sid,
                          did,
                          scid,
                          tid,
                          plid,
                          data=None,
                          diff_schema=None,
                          drop_req=False):

        sql = ''
        if data:
            data['schema'] = self.schema
            data['table'] = self.table
            sql, name = row_security_policies_utils.get_sql(
                self.conn, data, did, scid, tid, plid, self.datlastsysoid,
                self.schema, self.table)

            sql = sql.strip('\n').strip(' ')

        elif diff_schema:
            schema = diff_schema

            sql = row_security_policies_utils.get_reverse_engineered_sql(
                self.conn,
                schema,
                self.table,
                did,
                scid,
                tid,
                plid,
                self.datlastsysoid,
                template_path=None,
                with_header=False)

        drop_sql = ''
        if drop_req:
            drop_sql = '\n' + self.delete(gid=1,
                                          sid=sid,
                                          did=did,
                                          scid=scid,
                                          tid=tid,
                                          plid=plid,
                                          only_sql=True)
        if drop_sql != '':
            sql = drop_sql + '\n\n' + sql
        return sql
Example #4
0
    def msql(self, gid, sid, did, scid, tid, plid=None):
        """
        This function returns modified sql
        """
        data = dict(request.args)

        sql, name = row_security_policies_utils.get_sql(
            self.conn, data, did, scid, tid, plid, self.datlastsysoid,
            self.schema, self.table)
        if not isinstance(sql, str):
            return sql
        sql = sql.strip('\n').strip(' ')

        if sql == '':
            sql = "--modified sql"
        return make_json_response(data=sql, status=200)