Skip to content

Commit d67ecf7

Browse files
committed
feat(backup): support integrations task params
1 parent 28dcdbc commit d67ecf7

File tree

9 files changed

+34
-10
lines changed

9 files changed

+34
-10
lines changed

api/projects/integration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func GetIntegration(w http.ResponseWriter, r *http.Request) {
4141

4242
func GetIntegrations(w http.ResponseWriter, r *http.Request) {
4343
project := helpers.GetFromContext(r, "project").(db.Project)
44-
integrations, err := helpers.Store(r).GetIntegrations(project.ID, helpers.QueryParams(r.URL))
44+
integrations, err := helpers.Store(r).GetIntegrations(project.ID, helpers.QueryParams(r.URL), false)
4545

4646
if err != nil {
4747
helpers.WriteError(w, err)

db/Store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ type AccessKeyManager interface {
317317
// IntegrationManager handles integration-related operations
318318
type IntegrationManager interface {
319319
CreateIntegration(integration Integration) (newIntegration Integration, err error)
320-
GetIntegrations(projectID int, params RetrieveQueryParams) ([]Integration, error)
320+
GetIntegrations(projectID int, params RetrieveQueryParams, includeTaskParams bool) ([]Integration, error)
321321
GetIntegration(projectID int, integrationID int) (integration Integration, err error)
322322
UpdateIntegration(integration Integration) error
323323
GetIntegrationRefs(projectID int, integrationID int) (IntegrationReferrers, error)

db/TaskParams.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package db
22

33
type TaskParams struct {
4-
ID int `db:"id" json:"-"`
5-
ProjectID int `db:"project_id" json:"-"`
4+
ID int `db:"id" json:"-" backup:"-"`
5+
ProjectID int `db:"project_id" json:"-" backup:"-"`
66

77
Environment string `db:"environment" json:"environment,omitempty"`
88
Arguments *string `db:"arguments" json:"arguments,omitempty"`
@@ -14,7 +14,8 @@ type TaskParams struct {
1414
// This field available only for Build tasks.
1515
Version *string `db:"version" json:"version,omitempty"`
1616

17-
InventoryID *int `db:"inventory_id" json:"inventory_id,omitempty"`
17+
InventoryID *int `db:"inventory_id" json:"inventory_id,omitempty" backup:"-"`
18+
InventoryName *string `db:"-" json:"-" backup:"inventory_name,omitempty"`
1819

1920
Params MapStringAnyField `db:"params" json:"params,omitempty"`
2021
}

db/bolt/integrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (d *BoltDb) CreateIntegration(integration db.Integration) (db.Integration,
1919
return newIntegration.(db.Integration), err
2020
}
2121

22-
func (d *BoltDb) GetIntegrations(projectID int, params db.RetrieveQueryParams) (integrations []db.Integration, err error) {
22+
func (d *BoltDb) GetIntegrations(projectID int, params db.RetrieveQueryParams, includeTaskParams bool) (integrations []db.Integration, err error) {
2323
err = d.getObjects(projectID, db.IntegrationProps, params, nil, &integrations)
2424
return integrations, err
2525
}

db/bolt/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func (d *BoltDb) deleteTemplate(projectID int, templateID int, tx *bbolt.Tx) (er
217217
}
218218
}
219219

220-
integrations, err := d.GetIntegrations(projectID, db.RetrieveQueryParams{})
220+
integrations, err := d.GetIntegrations(projectID, db.RetrieveQueryParams{}, false)
221221
if err != nil {
222222
return
223223
}

db/sql/integration.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,24 @@ func (d *SqlDb) CreateIntegration(integration db.Integration) (newIntegration db
4646
return
4747
}
4848

49-
func (d *SqlDb) GetIntegrations(projectID int, params db.RetrieveQueryParams) (integrations []db.Integration, err error) {
49+
func (d *SqlDb) GetIntegrations(projectID int, params db.RetrieveQueryParams, includeTaskParams bool) (integrations []db.Integration, err error) {
5050
err = d.getObjects(projectID, db.IntegrationProps, params, nil, &integrations)
51+
52+
if includeTaskParams {
53+
for i := range integrations {
54+
if integrations[i].TaskParamsID == nil {
55+
continue
56+
}
57+
58+
var taskParams db.TaskParams
59+
err = d.getObject(projectID, db.TaskParamsProps, *integrations[i].TaskParamsID, &taskParams)
60+
if err != nil {
61+
return nil, err
62+
}
63+
integrations[i].TaskParams = &taskParams
64+
}
65+
}
66+
5167
return integrations, err
5268
}
5369

db/sql/integration_alias.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (d *SqlDb) GetIntegrationsByAlias(alias string) (res []db.Integration, leve
6767
if aliasObj.IntegrationID == nil {
6868
level = db.IntegrationAliasProject
6969
var projIntegrations []db.Integration
70-
projIntegrations, err = d.GetIntegrations(aliasObj.ProjectID, db.RetrieveQueryParams{})
70+
projIntegrations, err = d.GetIntegrations(aliasObj.ProjectID, db.RetrieveQueryParams{}, false)
7171
if err != nil {
7272
return
7373
}

services/project/backup.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (b *BackupDB) load(projectID int, store db.Store) (err error) {
181181
return
182182
}
183183

184-
b.integrations, err = store.GetIntegrations(projectID, db.RetrieveQueryParams{})
184+
b.integrations, err = store.GetIntegrations(projectID, db.RetrieveQueryParams{}, true)
185185
if err != nil {
186186
return
187187
}
@@ -190,6 +190,7 @@ func (b *BackupDB) load(projectID int, store db.Store) (err error) {
190190
b.integrationMatchers = make(map[int][]db.IntegrationMatcher)
191191
b.integrationExtractValues = make(map[int][]db.IntegrationExtractValue)
192192
for _, o := range b.integrations {
193+
193194
b.integrationAliases[o.ID], err = store.GetIntegrationAliases(projectID, &o.ID)
194195
if err != nil {
195196
return

services/project/restore.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ func (e BackupIntegration) Restore(store db.Store, b *BackupDB) error {
338338
integration.ProjectID = b.meta.ID
339339
integration.AuthSecretID = authSecretID
340340
integration.TemplateID = tpl.ID
341+
if integration.TaskParams != nil {
342+
params := e.TaskParams
343+
if params != nil {
344+
integration.TaskParams.InventoryID = &params.ID
345+
}
346+
}
341347

342348
newIntegration, err := store.CreateIntegration(integration)
343349
if err != nil {

0 commit comments

Comments
 (0)