Skip to content

Commit 022089d

Browse files
committed
Merge branch 'main' of https://github.com/apache/incubator-devlake into fix/qdeveloper-iam-role-auth
# Conflicts: # backend/plugins/q_dev/models/migrationscripts/register.go
2 parents 21816e3 + 94f7bca commit 022089d

137 files changed

Lines changed: 10647 additions & 430 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backend/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ RUN python3 -m pip install --no-cache --upgrade pip setuptools && \
149149
python3 -m pip install --upgrade pip
150150

151151
# Setup Python Poetry package manager
152-
RUN curl -sSL https://install.python-poetry.org | python3 -
152+
RUN curl -sSL https://install.python-poetry.org | python3 - --version 2.2.1
153153
ENV PATH="$PATH:/app/.local/bin"
154154

155155
# Build Python plugins, make sure the scripts has execute permission

backend/core/dal/identifier.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package dal
19+
20+
import (
21+
"fmt"
22+
"regexp"
23+
24+
"github.com/apache/incubator-devlake/core/errors"
25+
)
26+
27+
// validIdentifierRegex matches valid SQL identifiers: alphanumeric, underscores, and dots (for schema.table)
28+
var validIdentifierRegex = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_.]*$`)
29+
30+
// ValidateTableName checks that a table name is a safe SQL identifier to prevent SQL injection.
31+
func ValidateTableName(name string) errors.Error {
32+
if name == "" {
33+
return errors.Default.New("table name must not be empty")
34+
}
35+
if !validIdentifierRegex.MatchString(name) {
36+
return errors.Default.New(fmt.Sprintf("invalid table name: %q", name))
37+
}
38+
return nil
39+
}
40+
41+
// ValidateColumnName checks that a column name is a safe SQL identifier to prevent SQL injection.
42+
func ValidateColumnName(name string) errors.Error {
43+
if name == "" {
44+
return errors.Default.New("column name must not be empty")
45+
}
46+
if !validIdentifierRegex.MatchString(name) {
47+
return errors.Default.New(fmt.Sprintf("invalid column name: %q", name))
48+
}
49+
return nil
50+
}

backend/core/models/domainlayer/codequality/cq_file_metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
type CqFileMetrics struct {
2525
domainlayer.DomainEntity
26-
ProjectKey string `gorm:"index;type:varchar(255)"` //domain project key
26+
ProjectKey string `gorm:"index;type:varchar(500)"` //domain project key
2727
FileName string `gorm:"type:varchar(2000)"`
2828
FilePath string
2929
FileLanguage string `gorm:"type:varchar(20)"`

backend/core/models/domainlayer/codequality/cq_issues.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type CqIssue struct {
2727
Rule string `gorm:"type:varchar(255)"`
2828
Severity string `gorm:"type:varchar(100)"`
2929
Component string
30-
ProjectKey string `gorm:"index;type:varchar(100)"` //domain project key
30+
ProjectKey string `gorm:"index;type:varchar(500)"` //domain project key
3131
Line int
3232
Status string `gorm:"type:varchar(20)"`
3333
Message string
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package migrationscripts
19+
20+
import (
21+
"github.com/apache/incubator-devlake/core/context"
22+
"github.com/apache/incubator-devlake/core/errors"
23+
"github.com/apache/incubator-devlake/core/plugin"
24+
)
25+
26+
var _ plugin.MigrationScript = (*increaseCqIssuesProjectKeyLength)(nil)
27+
28+
type increaseCqIssuesProjectKeyLength struct{}
29+
30+
func (script *increaseCqIssuesProjectKeyLength) Up(basicRes context.BasicRes) errors.Error {
31+
db := basicRes.GetDal()
32+
if err := db.ModifyColumnType("cq_issues", "project_key", "varchar(500)"); err != nil {
33+
return err
34+
}
35+
return db.ModifyColumnType("cq_file_metrics", "project_key", "varchar(500)")
36+
}
37+
38+
func (*increaseCqIssuesProjectKeyLength) Version() uint64 {
39+
return 20260317000000
40+
}
41+
42+
func (*increaseCqIssuesProjectKeyLength) Name() string {
43+
return "increase cq_issues and cq_file_metrics project_key length to 500"
44+
}

backend/core/models/migrationscripts/register.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,6 @@ func All() []plugin.MigrationScript {
143143
new(addPipelinePriority),
144144
new(fixNullPriority),
145145
new(modifyCicdDeploymentsToText),
146+
new(increaseCqIssuesProjectKeyLength),
146147
}
147148
}

backend/helpers/pluginhelper/api/scope_generic_helper.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,9 @@ func (gs *GenericScopeApiHelper[Conn, Scope, ScopeConfig]) transactionalDelete(t
565565
}
566566
tx := gs.db.Begin()
567567
for _, table := range tables {
568+
if err := dal.ValidateTableName(table); err != nil {
569+
return errors.Default.Wrap(err, fmt.Sprintf("unsafe table name %q when deleting scope data", table))
570+
}
568571
where, params := generateWhereClause(table)
569572
gs.log.Info("deleting data from table %s with WHERE \"%s\" and params: \"%v\"", table, where, params)
570573
sql := fmt.Sprintf("DELETE FROM %s WHERE %s", table, where)

backend/helpers/srvhelper/scope_service_helper.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ func (scopeSrv *ScopeSrvHelper[C, S, SC]) deleteScopeData(scope plugin.ToolLayer
255255
}
256256
tables := errors.Must1(scopeSrv.getAffectedTables())
257257
for _, table := range tables {
258+
if err := dal.ValidateTableName(table); err != nil {
259+
panic(errors.Default.Wrap(err, fmt.Sprintf("unsafe table name %q when deleting scope data", table)))
260+
}
258261
where, params := generateWhereClause(table)
259262
scopeSrv.log.Info("deleting data from table %s with WHERE \"%s\" and params: \"%v\"", table, where, params)
260263
sql := fmt.Sprintf("DELETE FROM %s WHERE %s", table, where)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package migrationscripts
19+
20+
import (
21+
"github.com/apache/incubator-devlake/core/context"
22+
"github.com/apache/incubator-devlake/core/errors"
23+
"github.com/apache/incubator-devlake/core/plugin"
24+
)
25+
26+
var _ plugin.MigrationScript = (*addRepoURLToSyncOperations)(nil)
27+
28+
type addRepoURLToSyncOperations struct{}
29+
30+
// addRepoURLSyncOpArchived is a snapshot of ArgocdSyncOperation used solely
31+
// for this migration so the live model can evolve independently.
32+
type addRepoURLSyncOpArchived struct {
33+
ConnectionId uint64 `gorm:"primaryKey"`
34+
ApplicationName string `gorm:"primaryKey;type:varchar(255)"`
35+
DeploymentId int64 `gorm:"primaryKey"`
36+
RepoURL string `gorm:"type:varchar(500)"`
37+
}
38+
39+
func (addRepoURLSyncOpArchived) TableName() string {
40+
return "_tool_argocd_sync_operations"
41+
}
42+
43+
func (m *addRepoURLToSyncOperations) Up(basicRes context.BasicRes) errors.Error {
44+
db := basicRes.GetDal()
45+
return db.AutoMigrate(&addRepoURLSyncOpArchived{})
46+
}
47+
48+
func (*addRepoURLToSyncOperations) Version() uint64 {
49+
return 20260331000000
50+
}
51+
52+
func (*addRepoURLToSyncOperations) Name() string {
53+
return "argocd add repo_url to sync operations"
54+
}

backend/plugins/argocd/models/migrationscripts/register.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ func All() []plugin.MigrationScript {
2525
return []plugin.MigrationScript{
2626
new(addInitTables),
2727
new(addImageSupportArtifacts),
28+
new(addRepoURLToSyncOperations),
2829
}
2930
}

0 commit comments

Comments
 (0)