mirror of
https://github.com/alibaba/higress.git
synced 2026-05-21 11:17:28 +08:00
fix: nil guards, safe type assertions, panic prevention, and rate limiter plugin (#3757)
Signed-off-by: Srikanth Patchava <spatchava@meta.com> Signed-off-by: Srikanth Patchava <srpatcha@users.noreply.github.com> Co-authored-by: Srikanth Patchava <srpatcha@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
1c4fe1c9f9
commit
29da03c371
@@ -164,14 +164,14 @@ func (c *DBClient) DescribeTable(table string) ([]map[string]interface{}, error)
|
||||
switch c.dbType {
|
||||
case MYSQL:
|
||||
sql = `
|
||||
select
|
||||
select
|
||||
column_name,
|
||||
column_type,
|
||||
is_nullable,
|
||||
column_key,
|
||||
column_default,
|
||||
extra,
|
||||
column_comment
|
||||
column_comment
|
||||
from information_schema.columns
|
||||
where table_schema = database() and table_name = ?
|
||||
`
|
||||
@@ -179,17 +179,17 @@ func (c *DBClient) DescribeTable(table string) ([]map[string]interface{}, error)
|
||||
|
||||
case POSTGRES:
|
||||
sql = `
|
||||
select
|
||||
select
|
||||
column_name,
|
||||
data_type as column_type,
|
||||
is_nullable,
|
||||
case
|
||||
case
|
||||
when column_default like 'nextval%' then 'auto_increment'
|
||||
when column_default is not null then 'default'
|
||||
else ''
|
||||
end as column_key,
|
||||
column_default,
|
||||
case
|
||||
case
|
||||
when column_default like 'nextval%' then 'auto_increment'
|
||||
else ''
|
||||
end as extra,
|
||||
@@ -202,7 +202,7 @@ func (c *DBClient) DescribeTable(table string) ([]map[string]interface{}, error)
|
||||
|
||||
case CLICKHOUSE:
|
||||
sql = `
|
||||
select
|
||||
select
|
||||
name as column_name,
|
||||
type as column_type,
|
||||
if(is_nullable, 'YES', 'NO') as is_nullable,
|
||||
@@ -217,7 +217,7 @@ func (c *DBClient) DescribeTable(table string) ([]map[string]interface{}, error)
|
||||
|
||||
case SQLITE:
|
||||
sql = `
|
||||
select
|
||||
select
|
||||
name as column_name,
|
||||
type as column_type,
|
||||
not (notnull = 1) as is_nullable,
|
||||
@@ -236,6 +236,10 @@ func (c *DBClient) DescribeTable(table string) ([]map[string]interface{}, error)
|
||||
|
||||
// ListTables List all tables in the connected database.
|
||||
func (c *DBClient) ListTables() ([]string, error) {
|
||||
if err := c.reconnectIfDbEmpty(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var sql string
|
||||
switch c.dbType {
|
||||
case MYSQL:
|
||||
@@ -265,6 +269,10 @@ func (c *DBClient) ListTables() ([]string, error) {
|
||||
tables = append(tables, table)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, fmt.Errorf("error iterating table rows: %w", err)
|
||||
}
|
||||
|
||||
return tables, nil
|
||||
}
|
||||
|
||||
@@ -335,6 +343,10 @@ func (c *DBClient) Query(sql string, args ...interface{}) ([]map[string]interfac
|
||||
results = append(results, rowMap)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, fmt.Errorf("failed to iterate table rows in Query: %w", err)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -792,22 +792,36 @@ func (m *MilvusProvider) ListDocs(ctx context.Context, limit int) ([]schema.Docu
|
||||
fieldName := strings.ToLower(fieldMapping.StandardName)
|
||||
switch fieldName {
|
||||
case "id":
|
||||
if v, err := col.(*entity.ColumnVarChar).Get(i); err == nil {
|
||||
id = v.(string)
|
||||
if typedCol, ok := col.(*entity.ColumnVarChar); ok {
|
||||
if v, err := typedCol.Get(i); err == nil {
|
||||
if s, ok := v.(string); ok {
|
||||
id = s
|
||||
}
|
||||
}
|
||||
}
|
||||
case "content":
|
||||
if v, err := col.(*entity.ColumnVarChar).Get(i); err == nil {
|
||||
content = v.(string)
|
||||
if typedCol, ok := col.(*entity.ColumnVarChar); ok {
|
||||
if v, err := typedCol.Get(i); err == nil {
|
||||
if s, ok := v.(string); ok {
|
||||
content = s
|
||||
}
|
||||
}
|
||||
}
|
||||
case "metadata":
|
||||
if v, err := col.(*entity.ColumnJSONBytes).Get(i); err == nil {
|
||||
if bytes, ok := v.([]byte); ok {
|
||||
_ = json.Unmarshal(bytes, &metadata)
|
||||
if typedCol, ok := col.(*entity.ColumnJSONBytes); ok {
|
||||
if v, err := typedCol.Get(i); err == nil {
|
||||
if bytes, ok := v.([]byte); ok {
|
||||
_ = json.Unmarshal(bytes, &metadata)
|
||||
}
|
||||
}
|
||||
}
|
||||
case "created_at":
|
||||
if v, err := col.(*entity.ColumnInt64).Get(i); err == nil {
|
||||
createdAt = v.(int64)
|
||||
if typedCol, ok := col.(*entity.ColumnInt64); ok {
|
||||
if v, err := typedCol.Get(i); err == nil {
|
||||
if ts, ok := v.(int64); ok {
|
||||
createdAt = ts
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,13 +87,17 @@ func parseConfig(json gjson.Result, config *RequestBlockConfig, log log.Log) err
|
||||
if regexpUrl == "" {
|
||||
continue
|
||||
}
|
||||
var reg *regexp.Regexp
|
||||
var err error
|
||||
if config.caseSensitive {
|
||||
reg := regexp.MustCompile(regexpUrl)
|
||||
config.blockRegExpArray = append(config.blockRegExpArray, reg)
|
||||
reg, err = regexp.Compile(regexpUrl)
|
||||
} else {
|
||||
reg := regexp.MustCompile(strings.ToLower(regexpUrl))
|
||||
config.blockRegExpArray = append(config.blockRegExpArray, reg)
|
||||
reg, err = regexp.Compile(strings.ToLower(regexpUrl))
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid regexp pattern %q: %w", regexpUrl, err)
|
||||
}
|
||||
config.blockRegExpArray = append(config.blockRegExpArray, reg)
|
||||
}
|
||||
for _, item := range json.Get("block_headers").Array() {
|
||||
header := item.String()
|
||||
|
||||
Reference in New Issue
Block a user