Skip to content

Commit 581a47c

Browse files
authored
fix(api): integration crypto migration (#5145)
1 parent 2e606fa commit 581a47c

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

engine/api/event/event.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func DeleteEventIntegration(eventIntegrationID int64) {
8686
func ResetEventIntegration(ctx context.Context, db gorp.SqlExecutor, eventIntegrationID int64) error {
8787
brokerConnectionKey := strconv.FormatInt(eventIntegrationID, 10)
8888
brokersConnectionCache.Delete(brokerConnectionKey)
89-
projInt, err := integration.LoadProjectIntegrationByID(db, eventIntegrationID, true)
89+
projInt, err := integration.LoadProjectIntegrationByIDWithClearPassword(db, eventIntegrationID)
9090
if err != nil {
9191
return fmt.Errorf("cannot load project integration id %d and type event: %v", eventIntegrationID, err)
9292
}
@@ -163,7 +163,7 @@ func DequeueEvent(ctx context.Context, db *gorp.DbMap) {
163163
brokerConnectionKey := strconv.FormatInt(eventIntegrationID, 10)
164164
brokerConnection, ok := brokersConnectionCache.Get(brokerConnectionKey)
165165
if !ok {
166-
projInt, err := integration.LoadProjectIntegrationByID(db, eventIntegrationID, true)
166+
projInt, err := integration.LoadProjectIntegrationByIDWithClearPassword(db, eventIntegrationID)
167167
if err != nil {
168168
log.Error(ctx, "Event.DequeueEvent> Cannot load project integration for project %s and id %d and type event: %v", e.ProjectKey, eventIntegrationID, err)
169169
continue

engine/api/integration/dao_project_integration.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ func LoadProjectIntegrationByNameWithClearPassword(db gorp.SqlExecutor, key stri
7575
}
7676

7777
// LoadProjectIntegrationByID returns integration, selecting by its id
78-
func LoadProjectIntegrationByID(db gorp.SqlExecutor, id int64, clearPassword bool) (*sdk.ProjectIntegration, error) {
78+
func LoadProjectIntegrationByID(db gorp.SqlExecutor, id int64) (*sdk.ProjectIntegration, error) {
7979
query := gorpmapping.NewQuery("SELECT * from project_integration WHERE id = $1").Args(id)
8080
pp, err := load(db, query)
8181
return &pp, err
8282
}
8383

84-
func LoadProjectIntegrationByIDWithClearPassword(db gorp.SqlExecutor, id int64, clearPassword bool) (*sdk.ProjectIntegration, error) {
84+
func LoadProjectIntegrationByIDWithClearPassword(db gorp.SqlExecutor, id int64) (*sdk.ProjectIntegration, error) {
8585
query := gorpmapping.NewQuery("SELECT * from project_integration WHERE id = $1").Args(id)
8686
pp, err := loadWithClearPassword(db, query)
8787
return &pp, err
@@ -174,9 +174,9 @@ func UpdateIntegration(db gorp.SqlExecutor, pp sdk.ProjectIntegration) error {
174174
for k, cfg := range givenConfig {
175175
if cfg.Type == sdk.IntegrationConfigTypePassword && cfg.Value == sdk.PasswordPlaceholder {
176176
if oldConfig == nil {
177-
// reload the previous config to encuse we don't store placeholder
177+
// reload the previous config to ensure we don't store placeholder
178178
var err error
179-
oldConfig, err = LoadProjectIntegrationByID(db, pp.ID, true)
179+
oldConfig, err = LoadProjectIntegrationByIDWithClearPassword(db, pp.ID)
180180
if err != nil {
181181
return err
182182
}

engine/api/migrate/refactor_integration_cryto.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,23 @@ func refactorProjectIntegrationCrypto(ctx context.Context, db *gorp.DbMap, id in
198198
return sdk.WrapError(err, "unable to encrypt config PublicConfigurations")
199199
}
200200
projectIntegration.Config = newCfg
201+
202+
// If the existing configuration contains password placeholder as encryptted value,
203+
// let's overdire id because it will fail
204+
for k, v := range projectIntegration.Config {
205+
if v.Type == sdk.IntegrationConfigTypePassword && v.Value == sdk.PasswordPlaceholder {
206+
log.Warning(ctx, "refactorProjectIntegrationCrypto > overriding wrong passwork: project: %d, integration: %s, value: %s", projectIntegration.ProjectID, projectIntegration.Name, k)
207+
v.Value = k
208+
}
209+
projectIntegration.Config[k] = v
210+
}
201211
oldCfg := projectIntegration.Config.Clone()
202212

203213
if err := integration.UpdateIntegration(tx, projectIntegration); err != nil {
204214
return sdk.WithStack(err)
205215
}
206216

207-
newProjectIntegration, err := integration.LoadProjectIntegrationByID(tx, id, true)
217+
newProjectIntegration, err := integration.LoadProjectIntegrationByIDWithClearPassword(tx, id)
208218
if err != nil {
209219
return err
210220
}

engine/api/purge/purge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func DeleteArtifacts(ctx context.Context, db gorp.SqlExecutor, store cache.Store
196196
for _, art := range wnr.Artifacts {
197197
var integrationName string
198198
if art.ProjectIntegrationID != nil && *art.ProjectIntegrationID > 0 {
199-
projectIntegration, err := integration.LoadProjectIntegrationByID(db, *art.ProjectIntegrationID, false)
199+
projectIntegration, err := integration.LoadProjectIntegrationByID(db, *art.ProjectIntegrationID)
200200
if err != nil {
201201
log.Error(ctx, "Cannot load LoadProjectIntegrationByID %s/%d", proj.Key, *art.ProjectIntegrationID)
202202
continue

engine/api/workflow/execute_node_job_run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ func LoadSecrets(db gorp.SqlExecutor, store cache.Store, nodeRun *sdk.WorkflowNo
476476
secrets = append(secrets, ev...)
477477

478478
if pp != nil {
479-
projectIntegration, err := integration.LoadProjectIntegrationByID(db, pp.ID, true)
479+
projectIntegration, err := integration.LoadProjectIntegrationByIDWithClearPassword(db, pp.ID)
480480
if err != nil {
481481
return nil, sdk.WrapError(err, "LoadSecrets> Cannot load integration %d", pp.ID)
482482
}

engine/api/workflow_run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ func (api *API) getDownloadArtifactHandler() service.Handler {
11311131

11321132
var integrationName string
11331133
if art.ProjectIntegrationID != nil && *art.ProjectIntegrationID > 0 {
1134-
projectIntegration, err := integration.LoadProjectIntegrationByID(api.mustDB(), *art.ProjectIntegrationID, false)
1134+
projectIntegration, err := integration.LoadProjectIntegrationByID(api.mustDB(), *art.ProjectIntegrationID)
11351135
if err != nil {
11361136
return sdk.WrapError(err, "cannot load project integration %s/%d", proj.Key, *art.ProjectIntegrationID)
11371137
}
@@ -1199,7 +1199,7 @@ func (api *API) getWorkflowRunArtifactsHandler() service.Handler {
11991199

12001200
var integrationName string
12011201
if art.ProjectIntegrationID != nil && *art.ProjectIntegrationID > 0 {
1202-
projectIntegration, err := integration.LoadProjectIntegrationByID(api.mustDB(), *art.ProjectIntegrationID, false)
1202+
projectIntegration, err := integration.LoadProjectIntegrationByID(api.mustDB(), *art.ProjectIntegrationID)
12031203
if err != nil {
12041204
log.Error(ctx, "Cannot load LoadProjectIntegrationByID %s/%d: err: %v", key, *art.ProjectIntegrationID, err)
12051205
return

0 commit comments

Comments
 (0)