Skip to content

Commit

Permalink
refactor(be): change params for store method
Browse files Browse the repository at this point in the history
chore(fe): remove passphrase from key settings because it is not implemented

fix(be): boltdb migration
  • Loading branch information
fiftin committed Jan 29, 2022
1 parent 84471a4 commit d3d002a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 22 deletions.
4 changes: 2 additions & 2 deletions api/tasks/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func AddTaskToPool(d db.Store, taskObj db.Task, userID *int, projectID int) (new

if tpl.Type == db.TemplateBuild { // get next version for task if it is a Build
var builds []db.TaskWithTpl
builds, err = d.GetTemplateTasks(tpl, db.RetrieveQueryParams{Count: 1})
builds, err = d.GetTemplateTasks(tpl.ProjectID, tpl.ID, db.RetrieveQueryParams{Count: 1})
if err != nil {
return
}
Expand Down Expand Up @@ -153,7 +153,7 @@ func GetTasksList(w http.ResponseWriter, r *http.Request, limit uint64) {
var tasks []db.TaskWithTpl

if tpl != nil {
tasks, err = helpers.Store(r).GetTemplateTasks(tpl.(db.Template), db.RetrieveQueryParams{
tasks, err = helpers.Store(r).GetTemplateTasks(tpl.(db.Template).ProjectID, tpl.(db.Template).ID, db.RetrieveQueryParams{
Count: int(limit),
})
} else {
Expand Down
2 changes: 1 addition & 1 deletion db/Store.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ type Store interface {
CreateTask(task Task) (Task, error)
UpdateTask(task Task) error

GetTemplateTasks(template Template, params RetrieveQueryParams) ([]TaskWithTpl, error)
GetTemplateTasks(projectID int, templateID int, params RetrieveQueryParams) ([]TaskWithTpl, error)
GetProjectTasks(projectID int, params RetrieveQueryParams) ([]TaskWithTpl, error)
GetTask(projectID int, taskID int) (Task, error)
DeleteTaskWithOutputs(projectID int, taskID int) error
Expand Down
2 changes: 1 addition & 1 deletion db/Template.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func FillTemplates(d Store, templates []Template) (err error) {
for i := range templates {
tpl := &templates[i]
var tasks []TaskWithTpl
tasks, err = d.GetTemplateTasks(*tpl, RetrieveQueryParams{Count: 1})
tasks, err = d.GetTemplateTasks(tpl.ProjectID, tpl.ID, RetrieveQueryParams{Count: 1})
if err != nil {
return
}
Expand Down
8 changes: 7 additions & 1 deletion db/bolt/migrations/v2.8.26.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ func (d Migration_2_8_28) getProjectRepositories(projectID string) (map[string]m
repos := make(map[string]map[string]interface{})
err := d.DB.View(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte("project__repository_" + projectID))
if b == nil {
return nil
}
return b.ForEach(func(id, body []byte) error {
r := make(map[string]interface{})
repos[string(id)] = r
Expand All @@ -25,7 +28,10 @@ func (d Migration_2_8_28) getProjectRepositories(projectID string) (map[string]m

func (d Migration_2_8_28) setProjectRepository(projectID string, repoID string, repo map[string]interface{}) error {
return d.DB.Update(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte("project__repository_" + projectID))
b, err := tx.CreateBucketIfNotExists([]byte("project__repository_" + projectID))
if err != nil {
return err
}
j, err := json.Marshal(repo)
if err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions db/bolt/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (d *BoltDb) CreateTaskOutput(output db.TaskOutput) (db.TaskOutput, error) {
return newOutput.(db.TaskOutput), nil
}

func (d *BoltDb) getTasks(projectID int, template *db.Template, params db.RetrieveQueryParams) (tasksWithTpl []db.TaskWithTpl, err error) {
func (d *BoltDb) getTasks(projectID int, templateID *int, params db.RetrieveQueryParams) (tasksWithTpl []db.TaskWithTpl, err error) {
var tasks []db.Task

err = d.getObjects(0, db.TaskProps, params, func(tsk interface{}) bool {
Expand All @@ -38,7 +38,7 @@ func (d *BoltDb) getTasks(projectID int, template *db.Template, params db.Retrie
return false
}

if template != nil && task.TemplateID != template.ID {
if templateID != nil && task.TemplateID != *templateID {
return false
}

Expand All @@ -56,10 +56,10 @@ func (d *BoltDb) getTasks(projectID int, template *db.Template, params db.Retrie
for i, task := range tasks {
tpl, ok := templates[task.TemplateID]
if !ok {
if template == nil {
if templateID == nil {
tpl, _ = d.GetTemplate(task.ProjectID, task.TemplateID)
} else {
tpl = *template
tpl, _ = d.GetTemplate(task.ProjectID, *templateID)
}
templates[task.TemplateID] = tpl
}
Expand Down Expand Up @@ -103,8 +103,8 @@ func (d *BoltDb) GetTask(projectID int, taskID int) (task db.Task, err error) {
return
}

func (d *BoltDb) GetTemplateTasks(template db.Template, params db.RetrieveQueryParams) ([]db.TaskWithTpl, error) {
return d.getTasks(template.ProjectID, &template, params)
func (d *BoltDb) GetTemplateTasks(projectID int, templateID int, params db.RetrieveQueryParams) ([]db.TaskWithTpl, error) {
return d.getTasks(projectID, &templateID, params)
}

func (d *BoltDb) GetProjectTasks(projectID int, params db.RetrieveQueryParams) ([]db.TaskWithTpl, error) {
Expand Down
8 changes: 3 additions & 5 deletions db/sql/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ func (d *SqlDb) CreateTaskOutput(output db.TaskOutput) (db.TaskOutput, error) {
return output, err
}


func (d *SqlDb) getTasks(projectID int, templateID* int, params db.RetrieveQueryParams, tasks *[]db.TaskWithTpl) (err error) {
func (d *SqlDb) getTasks(projectID int, templateID *int, params db.RetrieveQueryParams, tasks *[]db.TaskWithTpl) (err error) {
fields := "task.*"
fields += ", tpl.playbook as tpl_playbook" +
", `user`.name as user_name" +
Expand Down Expand Up @@ -69,7 +68,6 @@ func (d *SqlDb) getTasks(projectID int, templateID* int, params db.RetrieveQuery
return
}


func (d *SqlDb) GetTask(projectID int, taskID int) (task db.Task, err error) {
q := squirrel.Select("task.*").
From("task").
Expand All @@ -96,8 +94,8 @@ func (d *SqlDb) GetTask(projectID int, taskID int) (task db.Task, err error) {
return
}

func (d *SqlDb) GetTemplateTasks(template db.Template, params db.RetrieveQueryParams) (tasks []db.TaskWithTpl, err error) {
err = d.getTasks(template.ProjectID, &template.ID, params, &tasks)
func (d *SqlDb) GetTemplateTasks(projectID int, templateID int, params db.RetrieveQueryParams) (tasks []db.TaskWithTpl, err error) {
err = d.getTasks(projectID, &templateID, params, &tasks)
return
}

Expand Down
12 changes: 6 additions & 6 deletions web2/src/components/KeyForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
:disabled="formSaving || !canEditSecrets"
/>

<v-text-field
v-model="item.login_password.passphrase"
label="Passphrase (Optional)"
v-if="item.type === 'ssh'"
:disabled="formSaving || !canEditSecrets"
/>
<!-- <v-text-field-->
<!-- v-model="item.login_password.passphrase"-->
<!-- label="Passphrase (Optional)"-->
<!-- v-if="item.type === 'ssh'"-->
<!-- :disabled="formSaving || !canEditSecrets"-->
<!-- />-->

<v-textarea
outlined
Expand Down

0 comments on commit d3d002a

Please sign in to comment.