Skip to content

Commit e7bd958

Browse files
committed
Merge remote-tracking branch 'upstream/main' into versionUpgrade
Signed-off-by: DoDiODev <DoDiDev@proton.me> # Conflicts: # backend/core/models/migrationscripts/register.go # backend/plugins/sonarqube/models/migrationscripts/register.go # docker-compose-dev-postgresql.yml
2 parents d493d78 + eaf86ce commit e7bd958

51 files changed

Lines changed: 2514 additions & 95 deletions

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
@@ -50,7 +50,7 @@ RUN if [ "$(arch)" != "x86_64" ] ; then \
5050
fi
5151

5252
RUN go install github.com/vektra/mockery/v2@v2.53.6
53-
RUN go install github.com/swaggo/swag/cmd/swag@v1.16.1
53+
RUN go install github.com/swaggo/swag/cmd/swag@v1.16.6
5454

5555
COPY --from=debian-amd64 /usr/include /rootfs-amd64/usr/include
5656
COPY --from=debian-amd64 /usr/lib/x86_64-linux-gnu /rootfs-amd64/usr/lib/x86_64-linux-gnu
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 codequality
19+
20+
import (
21+
"time"
22+
23+
"github.com/apache/incubator-devlake/core/models/domainlayer"
24+
)
25+
26+
type CqProjectMetricsHistory struct {
27+
domainlayer.DomainEntity
28+
ProjectKey string `gorm:"index;type:varchar(500)"`
29+
AnalysisDate time.Time `gorm:"index"`
30+
Coverage *float64
31+
Ncloc *int
32+
Bugs *int
33+
ReliabilityRating string `gorm:"type:varchar(5)"`
34+
CodeSmells *int
35+
SqaleRating string `gorm:"type:varchar(5)"`
36+
Complexity *int
37+
CognitiveComplexity *int
38+
Vulnerabilities *int
39+
SecurityRating string `gorm:"type:varchar(5)"`
40+
SecurityHotspots *int
41+
DuplicatedLinesDensity *float64
42+
}
43+
44+
func (CqProjectMetricsHistory) TableName() string {
45+
return "cq_project_metrics_history"
46+
}

backend/core/models/domainlayer/domaininfo/domaininfo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func GetDomainTablesInfo() []dal.Tabler {
5656
&codequality.CqIssue{},
5757
&codequality.CqIssueImpact{},
5858
&codequality.CqProject{},
59+
&codequality.CqProjectMetricsHistory{},
5960
// crossdomain
6061
&crossdomain.Account{},
6162
&crossdomain.BoardRepo{},
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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/models/migrationscripts/archived"
24+
"github.com/apache/incubator-devlake/helpers/migrationhelper"
25+
)
26+
27+
type addCqProjectMetricsHistory struct{}
28+
29+
func (u *addCqProjectMetricsHistory) Up(basicRes context.BasicRes) errors.Error {
30+
return migrationhelper.AutoMigrateTables(
31+
basicRes,
32+
&archived.CqProjectMetricsHistory{},
33+
)
34+
}
35+
36+
func (*addCqProjectMetricsHistory) Version() uint64 {
37+
return 20260707153201
38+
}
39+
40+
func (*addCqProjectMetricsHistory) Name() string {
41+
return "add cq_project_metrics_history domain table"
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 archived
19+
20+
import "time"
21+
22+
type CqProjectMetricsHistory struct {
23+
DomainEntity
24+
ProjectKey string `gorm:"index;type:varchar(500)"`
25+
AnalysisDate time.Time `gorm:"index"`
26+
Coverage *float64
27+
Ncloc *int
28+
Bugs *int
29+
ReliabilityRating string `gorm:"type:varchar(5)"`
30+
CodeSmells *int
31+
SqaleRating string `gorm:"type:varchar(5)"`
32+
Complexity *int
33+
CognitiveComplexity *int
34+
Vulnerabilities *int
35+
SecurityRating string `gorm:"type:varchar(5)"`
36+
SecurityHotspots *int
37+
DuplicatedLinesDensity *float64
38+
}
39+
40+
func (CqProjectMetricsHistory) TableName() string {
41+
return "cq_project_metrics_history"
42+
}

backend/core/models/migrationscripts/register.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,6 @@ func All() []plugin.MigrationScript {
147147
new(addAuthSessions),
148148
new(changeIssueComponentToText),
149149
new(changeCqIssueCodeBlocksComponentToText),
150+
new(addCqProjectMetricsHistory),
150151
}
151152
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 oidchelper
19+
20+
import "strings"
21+
22+
func (c *Config) IsUserAllowed(email string) bool {
23+
if len(c.AllowEmails) == 0 &&
24+
len(c.AllowDomains) == 0 {
25+
return true
26+
}
27+
28+
email = strings.ToLower(strings.TrimSpace(email))
29+
30+
if _, ok := c.AllowEmails[email]; ok {
31+
return true
32+
}
33+
34+
_, domain, ok := strings.Cut(email, "@")
35+
if ok {
36+
if _, ok := c.AllowDomains[domain]; ok {
37+
return true
38+
}
39+
}
40+
41+
return false
42+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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 oidchelper
19+
20+
import "testing"
21+
22+
func TestIsUserAllowed(t *testing.T) {
23+
cases := []struct {
24+
name string
25+
cfg Config
26+
email string
27+
want bool
28+
}{
29+
{
30+
name: "no restrictions",
31+
cfg: Config{},
32+
email: "user@example.com",
33+
want: true,
34+
},
35+
{
36+
name: "allowed email",
37+
cfg: Config{
38+
AllowEmails: map[string]struct{}{
39+
"user@example.com": {},
40+
},
41+
},
42+
email: "user@example.com",
43+
want: true,
44+
},
45+
{
46+
name: "blocked email",
47+
cfg: Config{
48+
AllowEmails: map[string]struct{}{
49+
"user@example.com": {},
50+
},
51+
},
52+
email: "other@example.com",
53+
want: false,
54+
},
55+
{
56+
name: "allowed domain",
57+
cfg: Config{
58+
AllowDomains: map[string]struct{}{
59+
"example.com": {},
60+
},
61+
},
62+
email: "user@example.com",
63+
want: true,
64+
},
65+
{
66+
name: "blocked domain",
67+
cfg: Config{
68+
AllowDomains: map[string]struct{}{
69+
"example.com": {},
70+
},
71+
},
72+
email: "user@other.com",
73+
want: false,
74+
},
75+
{
76+
name: "email case insensitive",
77+
cfg: Config{
78+
AllowEmails: map[string]struct{}{
79+
"user@example.com": {},
80+
},
81+
},
82+
email: "USER@example.com",
83+
want: true,
84+
},
85+
{
86+
name: "domain case insensitive",
87+
cfg: Config{
88+
AllowDomains: map[string]struct{}{
89+
"example.com": {},
90+
},
91+
},
92+
email: "user@EXAMPLE.COM",
93+
want: true,
94+
},
95+
{
96+
name: "invalid email",
97+
cfg: Config{
98+
AllowDomains: map[string]struct{}{
99+
"example.com": {},
100+
},
101+
},
102+
email: "not-an-email",
103+
want: false,
104+
},
105+
}
106+
107+
for _, tc := range cases {
108+
t.Run(tc.name, func(t *testing.T) {
109+
if got := tc.cfg.IsUserAllowed(tc.email); got != tc.want {
110+
t.Errorf(
111+
"IsUserAllowed(%q) = %v, want %v",
112+
tc.email,
113+
got,
114+
tc.want,
115+
)
116+
}
117+
})
118+
}
119+
}

backend/helpers/oidchelper/config.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ type Config struct {
6767
Providers map[string]*ProviderConfig
6868
LogoutRedirect bool
6969

70+
// Optional OIDC authorization restrictions.
71+
// Empty means no restriction.
72+
AllowEmails map[string]struct{}
73+
AllowDomains map[string]struct{}
74+
7075
SessionSecret []byte
7176
SessionTTL time.Duration
7277

@@ -136,6 +141,8 @@ func LoadConfig(basicRes context.BasicRes) (*Config, error) {
136141
SessionTTL: ttl,
137142
CookieDomain: strings.TrimSpace(cfg.GetString("COOKIE_DOMAIN")),
138143
CookieSecure: cookieSecure,
144+
AllowEmails: parseStringSet(cfg.GetString("OIDC_ALLOW_EMAILS")),
145+
AllowDomains: parseStringSet(cfg.GetString("OIDC_ALLOW_DOMAINS")),
139146
}
140147

141148
if !out.OIDCEnabled {
@@ -205,6 +212,23 @@ func parseProviderNames(raw string) []string {
205212
seen[n] = struct{}{}
206213
out = append(out, n)
207214
}
215+
216+
return out
217+
}
218+
219+
func parseStringSet(raw string) map[string]struct{} {
220+
out := make(map[string]struct{})
221+
222+
for _, v := range strings.Split(raw, ",") {
223+
v = strings.ToLower(strings.TrimSpace(v))
224+
225+
if v == "" {
226+
continue
227+
}
228+
229+
out[v] = struct{}{}
230+
}
231+
208232
return out
209233
}
210234

0 commit comments

Comments
 (0)