Skip to content

Commit 4c9cfb6

Browse files
authored
supporting gitlab connections (#1921)
* gitlab connections
1 parent 2e301b4 commit 4c9cfb6

File tree

11 files changed

+51
-30
lines changed

11 files changed

+51
-30
lines changed

backend/controllers/connections.go

+28-23
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func ListVCSConnectionsApi(c *gin.Context) {
3939
connectionsSlim := lo.Map(connections, func(c models.VCSConnection, i int) gin.H {
4040
return gin.H{
4141
"connection_id": c.ID,
42-
"vcs": "bitbucket",
42+
"vcs": c.VCSType,
4343
"connection_name": c.Name,
4444
}
4545
})
@@ -65,6 +65,8 @@ func CreateVCSConnectionApi(c *gin.Context) {
6565
Name string `json:"connection_name"`
6666
BitbucketAccessToken string `json:"bitbucket_access_token"`
6767
BitbucketWebhookSecret string `json:"bitbucket_webhook_secret"`
68+
GitlabAccessToken string `json:"gitlab_access_token"`
69+
GitlabWebhookSecret string `json:"gitlab_webhook_secret"`
6870
}
6971

7072
var request CreateVCSConnectionRequest
@@ -74,7 +76,8 @@ func CreateVCSConnectionApi(c *gin.Context) {
7476
return
7577
}
7678

77-
if request.VCS != "bitbucket" {
79+
if request.VCS != string(models.DiggerVCSBitbucket) &&
80+
request.VCS != string(models.DiggerVCSGitlab) {
7881
slog.Error("VCS type not supported", "type", request.VCS)
7982
c.JSON(http.StatusBadRequest, gin.H{"error": "VCS type not supported"})
8083
return
@@ -89,36 +92,38 @@ func CreateVCSConnectionApi(c *gin.Context) {
8992

9093
bitbucketAccessTokenEncrypted, err := utils.AESEncrypt([]byte(secret), request.BitbucketAccessToken)
9194
if err != nil {
92-
slog.Error("Could not encrypt access token", "error", err)
93-
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not encrypt access token"})
95+
slog.Error("Could not encrypt bitbucket access token", "error", err)
96+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not encrypt bitbucket access token"})
9497
return
9598
}
9699

97100
bitbucketWebhookSecretEncrypted, err := utils.AESEncrypt([]byte(secret), request.BitbucketWebhookSecret)
98101
if err != nil {
99-
slog.Error("Could not encrypt webhook secret", "error", err)
100-
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not encrypt webhook secret"})
101-
return
102-
}
103-
104-
connection, err := models.DB.CreateVCSConnection(
105-
request.Name,
106-
0,
107-
"",
108-
"",
109-
"",
110-
"",
111-
"",
112-
"",
113-
"",
114-
bitbucketAccessTokenEncrypted,
115-
bitbucketWebhookSecretEncrypted,
116-
org.ID,
117-
)
102+
slog.Error("Could not encrypt bitbucket webhook secret", "error", err)
103+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not encrypt bitbucket webhook secret"})
104+
return
105+
}
106+
107+
gitlabAccessTokenEncrypted, err := utils.AESEncrypt([]byte(secret), request.GitlabAccessToken)
108+
if err != nil {
109+
slog.Error("Could not encrypt gitlab access secret", "error", err)
110+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not encrypt gitlab access token"})
111+
return
112+
}
113+
114+
gitlabWebhookSecret, err := utils.AESEncrypt([]byte(secret), request.GitlabWebhookSecret)
115+
if err != nil {
116+
slog.Error("Could not encrypt gitlab webhook secret", "error", err)
117+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not encrypt gitlab webhook secret"})
118+
return
119+
}
120+
121+
connection, err := models.DB.CreateVCSConnection(request.Name, models.DiggerVCSType(request.VCS), 0, "", "", "", "", "", "", "", bitbucketAccessTokenEncrypted, bitbucketWebhookSecretEncrypted, gitlabWebhookSecret, gitlabAccessTokenEncrypted, org.ID)
118122
if err != nil {
119123
slog.Error("Could not create VCS connection", "error", err)
120124
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not create VCS connection"})
121125
return
126+
122127
}
123128

124129
slog.Info("Created VCS connection", "connectionId", connection.ID, "organisationId", org.ID)

backend/migrations/20250325115901.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Modify "github_app_connections" table
2+
ALTER TABLE "public"."github_app_connections" ADD COLUMN "gitlab_access_token_encrypted" text NULL, ADD COLUMN "gitlab_webhook_secret_encrypted" text NULL;

backend/migrations/20250325134924.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Modify "github_app_connections" table
2+
ALTER TABLE "public"."github_app_connections" ADD COLUMN "vcs_type" text NULL DEFAULT 'bitbucket';

backend/migrations/atlas.sum

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
h1:pGuhEh2gQrZkYbjLCxVK+ZHO3jlFj99jjAO96gKlWlc=
1+
h1:FUyT8bE1jsztutCMQI5+hbieTDYCpac4f1BQk/RksrM=
22
20231227132525.sql h1:43xn7XC0GoJsCnXIMczGXWis9d504FAWi4F1gViTIcw=
33
20240115170600.sql h1:IW8fF/8vc40+eWqP/xDK+R4K9jHJ9QBSGO6rN9LtfSA=
44
20240116123649.sql h1:R1JlUIgxxF6Cyob9HdtMqiKmx/BfnsctTl5rvOqssQw=
@@ -44,3 +44,5 @@ h1:pGuhEh2gQrZkYbjLCxVK+ZHO3jlFj99jjAO96gKlWlc=
4444
20250224152926.sql h1:EjoFpfeoCpk/SjSo2i7sajKCR3t7YCn+1ZgGJrT0L9Y=
4545
20250226185150.sql h1:K7e/3Zy2wSTqKa3iYpIb02GTAniYSXHObTIqOV9aOhM=
4646
20250302190926.sql h1:F3FnaGnZv1Hwmg6W9Nacg5fbdiYbZGgS/mkuogtCso0=
47+
20250325115901.sql h1:yrha7g515WPkFRHfidvtLVWMeQmRD8rzVyWtPbuk0ws=
48+
20250325134924.sql h1:5vywDVuT0FPmQKP75AvxopxOeuKXsTEN00rgQjnA+ss=

backend/models/github.go

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ type VCSConnection struct {
1717
GithubAppUrl string
1818
BitbucketAccessTokenEncrypted string
1919
BitbucketWebhookSecretEncrypted string
20+
GitlabAccessTokenEncrypted string
21+
GitlabWebhookSecretEncrypted string
22+
VCSType DiggerVCSType `gorm:"default:bitbucket"`
2023
OrganisationID uint
2124
Organisation Organisation
2225
}

backend/models/storage.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,10 @@ func (db *Database) GetGithubAppInstallationLink(installationId int64) (*GithubA
514514
return &link, nil
515515
}
516516

517-
func (db *Database) CreateVCSConnection(name string, githubId int64, ClientID string, ClientSecretEncrypted string, WebhookSecretEncrypted string, PrivateKeyEncrypted string, PrivateKeyBase64Encrypted string, Org string, url string, bitbucketAccessTokenEnc string, bitbucketWebhookSecretEnc string, orgId uint) (*VCSConnection, error) {
517+
func (db *Database) CreateVCSConnection(name string, vcsType DiggerVCSType, githubId int64, ClientID string, ClientSecretEncrypted string, WebhookSecretEncrypted string, PrivateKeyEncrypted string, PrivateKeyBase64Encrypted string, Org string, url string, bitbucketAccessTokenEnc string, bitbucketWebhookSecretEnc string, gitlabWebhookSecret string, gitlabAccessToken string, orgId uint) (*VCSConnection, error) {
518518
app := VCSConnection{
519519
Name: name,
520+
VCSType: vcsType,
520521
GithubId: githubId,
521522
ClientID: ClientID,
522523
ClientSecretEncrypted: ClientSecretEncrypted,
@@ -527,6 +528,8 @@ func (db *Database) CreateVCSConnection(name string, githubId int64, ClientID st
527528
GithubAppUrl: url,
528529
BitbucketWebhookSecretEncrypted: bitbucketWebhookSecretEnc,
529530
BitbucketAccessTokenEncrypted: bitbucketAccessTokenEnc,
531+
GitlabWebhookSecretEncrypted: gitlabWebhookSecret,
532+
GitlabAccessTokenEncrypted: gitlabAccessToken,
530533
OrganisationID: orgId,
531534
}
532535
result := db.GormDB.Save(&app)

ee/backend/controllers/github.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (d DiggerEEController) GithubAppConnectionsConfirm(c *gin.Context) {
192192
return
193193
}
194194

195-
_, err = models.DB.CreateVCSConnection(cfg.GetName(), cfg.GetID(), cfg.GetClientID(), clientSecretEnc, webhookSecretEnc, PEMEnc, PEM64Enc, *cfg.Owner.Login, cfg.GetHTMLURL(), "", "", orgId)
195+
_, err = models.DB.CreateVCSConnection(cfg.GetName(), models.DiggerVCSGithub, cfg.GetID(), cfg.GetClientID(), clientSecretEnc, webhookSecretEnc, PEMEnc, PEM64Enc, *cfg.Owner.Login, cfg.GetHTMLURL(), "", "", "", "", orgId)
196196
if err != nil {
197197
log.Printf("failed to create github app connection record: %v", err)
198198
c.String(500, fmt.Sprintf("Failed to create github app record on callback"))

ee/backend/go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ require (
235235
github.com/ryanuber/go-glob v1.0.0 // indirect
236236
github.com/sagikazarmark/locafero v0.4.0 // indirect
237237
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
238+
github.com/samber/slog-gin v1.15.0 // indirect
238239
github.com/segmentio/analytics-go/v3 v3.3.0 // indirect
239240
github.com/segmentio/backo-go v1.0.0 // indirect
240241
github.com/sirupsen/logrus v1.9.3 // indirect

ee/backend/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,8 @@ github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6g
17461746
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
17471747
github.com/samber/lo v1.46.0 h1:w8G+oaCPgz1PoCJztqymCFaKwXt+5cCXn51uPxExFfQ=
17481748
github.com/samber/lo v1.46.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
1749+
github.com/samber/slog-gin v1.15.0 h1:Kqs/ilXd9divtslWjbz5DVptmLlzyntbBiXUAta2SFg=
1750+
github.com/samber/slog-gin v1.15.0/go.mod h1:mPAEinK/g2jPLauuWO11m3Q0Ca7aG4k9XjXjXY8IhMQ=
17491751
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
17501752
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
17511753
github.com/segmentio/analytics-go/v3 v3.3.0 h1:8VOMaVGBW03pdBrj1CMFfY9o/rnjJC+1wyQHlVxjw5o=

go.work.sum

+3-2
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,6 @@ github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbf
766766
github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s=
767767
github.com/alecthomas/kingpin/v2 v2.4.0 h1:f48lwail6p8zpO1bC4TxtqACaGqHYA22qkHjHpqDjYY=
768768
github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE=
769-
github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4=
770-
github.com/alecthomas/kong v0.7.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
771769
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
772770
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
773771
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
@@ -1603,6 +1601,7 @@ golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOM
16031601
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
16041602
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
16051603
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
1604+
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
16061605
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
16071606
golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4=
16081607
golang.org/x/image v0.0.0-20220302094943-723b81ca9867 h1:TcHcE0vrmgzNH1v3ppjcMGbhG5+9fMuvOmUYwNEF4q4=
@@ -1620,6 +1619,7 @@ golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
16201619
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
16211620
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
16221621
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
1622+
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
16231623
golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM=
16241624
golang.org/x/oauth2 v0.15.0/go.mod h1:q48ptWNTY5XWf+JNten23lcvHpLJ0ZSxF5ttTHKVCAM=
16251625
golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o=
@@ -1645,6 +1645,7 @@ golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
16451645
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
16461646
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
16471647
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
1648+
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
16481649
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2 h1:IRJeR9r1pYWsHKTRe/IInb7lYvbBVIqOgsX/u0mbOWY=
16491650
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457 h1:zf5N6UOrA487eEFacMePxjXAJctxKmyjKUsjA11Uzuk=
16501651
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=

libs/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ require (
3131
github.com/hashicorp/terraform-json v0.22.1
3232
github.com/microsoft/azure-devops-go-api/azuredevops v1.0.0-b5
3333
github.com/open-policy-agent/opa v0.66.0
34+
github.com/pkg/errors v0.9.1
3435
github.com/samber/lo v1.39.0
35-
github.com/sirupsen/logrus v1.9.3
3636
github.com/stretchr/testify v1.9.0
3737
github.com/xanzy/go-gitlab v0.106.0
3838
github.com/zclconf/go-cty v1.14.4
@@ -192,7 +192,6 @@ require (
192192
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
193193
github.com/pjbgf/sha1cd v0.3.0 // indirect
194194
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
195-
github.com/pkg/errors v0.9.1 // indirect
196195
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
197196
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
198197
github.com/posener/complete v1.2.3 // indirect
@@ -206,6 +205,7 @@ require (
206205
github.com/russross/blackfriday/v2 v2.1.0 // indirect
207206
github.com/ryanuber/go-glob v1.0.0 // indirect
208207
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
208+
github.com/sirupsen/logrus v1.9.3 // indirect
209209
github.com/skeema/knownhosts v1.2.2 // indirect
210210
github.com/sourcegraph/go-lsp v0.0.0-20200429204803-219e11d77f5d // indirect
211211
github.com/sourcegraph/jsonrpc2 v0.2.0 // indirect

0 commit comments

Comments
 (0)