-
Notifications
You must be signed in to change notification settings - Fork 563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
supporting gitlab connections #1921
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -38,7 +38,7 @@ func ListVCSConnectionsApi(c *gin.Context) { | |||||||||||||||||||||||
connectionsSlim := lo.Map(connections, func(c models.VCSConnection, i int) gin.H { | ||||||||||||||||||||||||
return gin.H{ | ||||||||||||||||||||||||
"connection_id": c.ID, | ||||||||||||||||||||||||
"vcs": "bitbucket", | ||||||||||||||||||||||||
"vcs": c.VCSType, | ||||||||||||||||||||||||
"connection_name": c.Name, | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
}) | ||||||||||||||||||||||||
|
@@ -64,6 +64,8 @@ func CreateVCSConnectionApi(c *gin.Context) { | |||||||||||||||||||||||
Name string `json:"connection_name"` | ||||||||||||||||||||||||
BitbucketAccessToken string `json:"bitbucket_access_token"` | ||||||||||||||||||||||||
BitbucketWebhookSecret string `json:"bitbucket_webhook_secret"` | ||||||||||||||||||||||||
GitlabAccessToken string `json:"gitlab_access_token"` | ||||||||||||||||||||||||
GitlabWebhookSecret string `json:"gitlab_webhook_secret"` | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
var request CreateVCSConnectionRequest | ||||||||||||||||||||||||
|
@@ -72,7 +74,8 @@ func CreateVCSConnectionApi(c *gin.Context) { | |||||||||||||||||||||||
return | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if request.VCS != "bitbucket" { | ||||||||||||||||||||||||
if request.VCS != string(models.DiggerVCSBitbucket) && | ||||||||||||||||||||||||
request.VCS != string(models.DiggerVCSGitlab) { | ||||||||||||||||||||||||
log.Printf("VCS type not supported: %v", request.VCS) | ||||||||||||||||||||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "VCS type not supported"}) | ||||||||||||||||||||||||
return | ||||||||||||||||||||||||
|
@@ -87,34 +90,35 @@ func CreateVCSConnectionApi(c *gin.Context) { | |||||||||||||||||||||||
|
||||||||||||||||||||||||
bitbucketAccessTokenEncrypted, err := utils.AESEncrypt([]byte(secret), request.BitbucketAccessToken) | ||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||
log.Printf("could not encrypt access token: %v", err) | ||||||||||||||||||||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not encrypt access token"}) | ||||||||||||||||||||||||
log.Printf("could not encrypt bitbucket access token: %v", err) | ||||||||||||||||||||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not encrypt bitbucket access token"}) | ||||||||||||||||||||||||
return | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
bitbucketWebhookSecretEncrypted, err := utils.AESEncrypt([]byte(secret), request.BitbucketWebhookSecret) | ||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||
log.Printf("could not encrypt webhook secret: %v", err) | ||||||||||||||||||||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not encrypt webhook secret"}) | ||||||||||||||||||||||||
log.Printf("could not encrypt bitbucket webhook secret: %v", err) | ||||||||||||||||||||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not encrypt bitbucket webhook secret"}) | ||||||||||||||||||||||||
return | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
gitlabAccessTokenEncrypted, err := utils.AESEncrypt([]byte(secret), request.GitlabAccessToken) | ||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||
log.Printf("could not encrypt gitlab access token: %v", err) | ||||||||||||||||||||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not encrypt gitlab access token"}) | ||||||||||||||||||||||||
return | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
gitlabWebhookSecret, err := utils.AESEncrypt([]byte(secret), request.GitlabWebhookSecret) | ||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||
log.Printf("could not encrypt gitlab webhook secret: %v", err) | ||||||||||||||||||||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not encrypt gitlab access token"}) | ||||||||||||||||||||||||
return | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
connection, err := models.DB.CreateVCSConnection( | ||||||||||||||||||||||||
request.Name, | ||||||||||||||||||||||||
0, | ||||||||||||||||||||||||
"", | ||||||||||||||||||||||||
"", | ||||||||||||||||||||||||
"", | ||||||||||||||||||||||||
"", | ||||||||||||||||||||||||
"", | ||||||||||||||||||||||||
"", | ||||||||||||||||||||||||
"", | ||||||||||||||||||||||||
bitbucketAccessTokenEncrypted, | ||||||||||||||||||||||||
bitbucketWebhookSecretEncrypted, | ||||||||||||||||||||||||
org.ID, | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
connection, err := models.DB.CreateVCSConnection(request.Name, models.DiggerVCSType(request.VCS), 0, "", "", "", "", "", "", "", bitbucketAccessTokenEncrypted, bitbucketWebhookSecretEncrypted, gitlabWebhookSecret, gitlabAccessTokenEncrypted, org.ID) | ||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||
log.Printf("") | ||||||||||||||||||||||||
log.Printf("failed to create vcs connection") | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
Comment on lines
+119
to
122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing error handling for CreateVCSConnection The error handling for Apply this fix: connection, err := models.DB.CreateVCSConnection(request.Name, models.DiggerVCSType(request.VCS), 0, "", "", "", "", "", "", "", bitbucketAccessTokenEncrypted, bitbucketWebhookSecretEncrypted, gitlabWebhookSecret, gitlabAccessTokenEncrypted, org.ID)
if err != nil {
log.Printf("failed to create vcs connection")
+ c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not create VCS connection"})
+ return
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
c.JSON(http.StatusCreated, gin.H{ | ||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- Modify "github_app_connections" table | ||
ALTER TABLE "public"."github_app_connections" ADD COLUMN "gitlab_access_token_encrypted" text NULL, ADD COLUMN "gitlab_webhook_secret_encrypted" text NULL; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- Modify "github_app_connections" table | ||
ALTER TABLE "public"."github_app_connections" ADD COLUMN "vcs_type" text NULL DEFAULT 'bitbucket'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error message inconsistency in GitLab webhook secret encryption error
There's an inconsistency in the error message for GitLab webhook secret encryption. The error message reports "Could not encrypt gitlab access token" instead of "Could not encrypt gitlab webhook secret".
Apply this fix:
📝 Committable suggestion