Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions backend/server/services/pushapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,32 @@ limitations under the License.
package services

import (
"regexp"
"strings"

"github.com/apache/incubator-devlake/core/dal"
"github.com/apache/incubator-devlake/core/errors"
)

// InsertRow FIXME ...
func InsertRow(table string, rows []map[string]interface{}) (int64, errors.Error) {
if !regexp.MustCompile(`^[a-zA-Z0-9_]+$`).MatchString(table) {
return 0, errors.BadInput.New("table name invalid")
}

if allowedTables := cfg.GetString("PUSH_API_ALLOWED_TABLES"); allowedTables != "" {
allow := false
for _, t := range strings.Split(allowedTables, ",") {
if strings.TrimSpace(t) == table {
allow = true
break
}
}
if !allow {
return 0, errors.Forbidden.New("table name is not in the allowed list")
}
}

err := db.Create(rows, dal.From(table))
if err != nil {
return 0, err
Expand Down
1 change: 1 addition & 0 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ SKIP_SUBTASK_PROGRESS=false
PORT=8080
MODE=release

# PUSH_API_ALLOWED_TABLES=table1,table2
NOTIFICATION_ENDPOINT=
NOTIFICATION_SECRET=

Expand Down
Loading