|
|
@@ -1751,27 +1751,10 @@ func NewGitlabAppOAuthIntegrationRepository(
|
|
|
func (repo *GitlabAppOAuthIntegrationRepository) CreateGitlabAppOAuthIntegration(
|
|
|
gi *ints.GitlabAppOAuthIntegration,
|
|
|
) (*ints.GitlabAppOAuthIntegration, error) {
|
|
|
- err := repo.EncryptGitlabAppOAuthIntegrationData(gi, repo.key)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- // if storage backend is not nil, strip out credential data, which will be stored in credential
|
|
|
- // storage backend after write to DB
|
|
|
- // var credentialData = &credentials.GitlabCredential{}
|
|
|
-
|
|
|
- // if repo.storageBackend != nil {
|
|
|
- // credentialData.AppClientID = gi.AppClientID
|
|
|
- // credentialData.AppClientSecret = gi.AppClientSecret
|
|
|
-
|
|
|
- // gi.AppClientID = []byte{}
|
|
|
- // gi.AppClientSecret = []byte{}
|
|
|
- // }
|
|
|
-
|
|
|
if err := repo.db.Create(gi).Error; err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
+
|
|
|
return gi, nil
|
|
|
}
|
|
|
|
|
|
@@ -1782,117 +1765,14 @@ func (repo *GitlabAppOAuthIntegrationRepository) ReadGitlabAppOAuthIntegration(
|
|
|
|
|
|
if err := repo.db.
|
|
|
Order("gitlab_app_o_auth_integrations.id desc").
|
|
|
- Joins("INNER JOIN gitlab_integrations ON gitlab_integrations.id = gitlab_app_o_auth_integrations.integration_id").
|
|
|
- Where("gitlab_app_o_auth_integrations.user_id = ? AND gitlab_app_o_auth_integrations.project_id = ? AND"+
|
|
|
+ Joins("INNER JOIN gitlab_integrations ON gitlab_integrations.id = gitlab_app_o_auth_integrations.gitlab_integration_id").
|
|
|
+ Joins("INNER JOIN o_auth_integrations ON o_auth_integrations.id = gitlab_app_o_auth_integrations.oauth_integration_id").
|
|
|
+ Where("o_auth_integrations.user_id = ? AND o_auth_integrations.project_id = ? AND"+
|
|
|
" gitlab_integrations.id = ? AND gitlab_integrations.deleted_at IS NULL AND"+
|
|
|
- " gitlab_app_o_auth_integrations.deleted_at IS NULL",
|
|
|
+ " gitlab_app_o_auth_integrations.deleted_at IS NULL AND o_auth_integrations.deleted_at IS NULL",
|
|
|
userID, projectID, integrationID).First(&gi).Error; err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
- // if repo.storageBackend != nil {
|
|
|
- // credentialData, err := repo.storageBackend.GetGitlabCredential(gi)
|
|
|
-
|
|
|
- // if err != nil {
|
|
|
- // return nil, err
|
|
|
- // }
|
|
|
-
|
|
|
- // gi.AppClientID = credentialData.AppClientID
|
|
|
-
|
|
|
- // gi.AppClientSecret = credentialData.AppClientSecret
|
|
|
- // }
|
|
|
-
|
|
|
- err := repo.DecryptGitlabAppOAuthIntegrationData(gi, repo.key)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
return gi, nil
|
|
|
}
|
|
|
-
|
|
|
-func (repo *GitlabAppOAuthIntegrationRepository) UpdateGitlabAppOAuthIntegration(
|
|
|
- gi *ints.GitlabAppOAuthIntegration,
|
|
|
-) (*ints.GitlabAppOAuthIntegration, error) {
|
|
|
- err := repo.EncryptGitlabAppOAuthIntegrationData(gi, repo.key)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- // if storage backend is not nil, strip out credential data, which will be stored in credential
|
|
|
- // storage backend after write to DB
|
|
|
- // var credentialData = &credentials.GitlabCredential{}
|
|
|
-
|
|
|
- // if repo.storageBackend != nil {
|
|
|
- // credentialData.AppClientID = gi.AppClientID
|
|
|
- // credentialData.AppClientSecret = gi.AppClientSecret
|
|
|
-
|
|
|
- // gi.AppClientID = []byte{}
|
|
|
- // gi.AppClientSecret = []byte{}
|
|
|
- // }
|
|
|
-
|
|
|
- if err := repo.db.Save(gi).Error; err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- return gi, nil
|
|
|
-}
|
|
|
-
|
|
|
-// EncryptGitlabAppOAuthIntegrationData will encrypt the gitlab app oauth integration data before
|
|
|
-// writing to the DB
|
|
|
-func (repo *GitlabAppOAuthIntegrationRepository) EncryptGitlabAppOAuthIntegrationData(
|
|
|
- gi *ints.GitlabAppOAuthIntegration,
|
|
|
- key *[32]byte,
|
|
|
-) error {
|
|
|
- if len(gi.AccessToken) > 0 {
|
|
|
- cipherData, err := encryption.Encrypt(gi.AccessToken, key)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- gi.AccessToken = cipherData
|
|
|
- }
|
|
|
-
|
|
|
- if len(gi.RefreshToken) > 0 {
|
|
|
- cipherData, err := encryption.Encrypt(gi.RefreshToken, key)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- gi.RefreshToken = cipherData
|
|
|
- }
|
|
|
-
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
-// DecryptAppOAuthGitlabIntegrationData will decrypt the gitlab app oauth integration data before
|
|
|
-// returning it from the DB
|
|
|
-func (repo *GitlabAppOAuthIntegrationRepository) DecryptGitlabAppOAuthIntegrationData(
|
|
|
- gi *ints.GitlabAppOAuthIntegration,
|
|
|
- key *[32]byte,
|
|
|
-) error {
|
|
|
- if len(gi.AccessToken) > 0 {
|
|
|
- plaintext, err := encryption.Decrypt(gi.AccessToken, key)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- gi.AccessToken = plaintext
|
|
|
- }
|
|
|
-
|
|
|
- if len(gi.RefreshToken) > 0 {
|
|
|
- plaintext, err := encryption.Decrypt(gi.RefreshToken, key)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- gi.RefreshToken = plaintext
|
|
|
- }
|
|
|
-
|
|
|
- return nil
|
|
|
-}
|