Skip to content

Commit

Permalink
Bugfix/223 loading playbooks from database is missing authentication …
Browse files Browse the repository at this point in the history
…information (#224)
  • Loading branch information
MaartendeKruijf authored Sep 10, 2024
1 parent 9861f79 commit c5e89c9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
9 changes: 7 additions & 2 deletions database/playbook/playbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
validator "soarca/internal/validators"
"soarca/models/api"
"soarca/models/cacao"
"soarca/models/decoder"
)

type IPlaybookRepository interface {
Expand Down Expand Up @@ -63,6 +64,7 @@ func (playbookRepo *PlaybookRepository) GetPlaybooks() ([]cacao.Playbook, error)
for _, playbook := range playbooks {
// get the cacao playbook id and add to the return list
playbook, ok := playbook.(cacao.Playbook)
decoder.SetPlaybookKeysAsId(&playbook)
if !ok {
return nil, errors.New("type assertion failed for cacao.playbook type")
}
Expand All @@ -78,6 +80,7 @@ func (playbookRepo *PlaybookRepository) Create(jsonData *[]byte) (cacao.Playbook
return cacao.Playbook{}, err
}
playbook, ok := client_data.(cacao.Playbook)
decoder.SetPlaybookKeysAsId(&playbook)
if !ok {
// handle incorrect casting
return cacao.Playbook{}, errors.New("failed to cast playbook object")
Expand All @@ -93,8 +96,9 @@ func (playbookRepo *PlaybookRepository) Read(id string) (cacao.Playbook, error)
}

cacaoPlaybook, ok := returnedObject.(cacao.Playbook)
decoder.SetPlaybookKeysAsId(&cacaoPlaybook)
if !ok {
err = errors.New("Could not cast lookup object to cacao.Playbook type")
err = errors.New("could not cast lookup object to cacao.Playbook type")
return cacao.Playbook{}, err
}

Expand All @@ -108,8 +112,9 @@ func (playbookRepo *PlaybookRepository) Update(id string, jsonData *[]byte) (cac
return cacao.Playbook{}, err
}
cacaoPlaybook, ok := client_data.(cacao.Playbook)
decoder.SetPlaybookKeysAsId(&cacaoPlaybook)
if !ok {
err = errors.New("Could not cast lookup object to cacao.Playbook type")
err = errors.New("could not cast lookup object to cacao.Playbook type")
return cacao.Playbook{}, err
}
return cacaoPlaybook, playbookRepo.db.Update(id, client_data)
Expand Down
26 changes: 15 additions & 11 deletions models/decoder/cacao.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,10 @@ func DecodeValidate(data []byte) *cacao.Playbook {
return playbook
}

func decode(data []byte) *cacao.Playbook {
playbook := cacao.NewPlaybook()

if err := json.Unmarshal(data, playbook); err != nil {
log.Error(err)
return nil
}

for key, workflow := range playbook.Workflow {
workflow.ID = key
playbook.Workflow[key] = workflow
func SetPlaybookKeysAsId(playbook *cacao.Playbook) {
for key, step := range playbook.Workflow {
step.ID = key
playbook.Workflow[key] = step
}

for key, target := range playbook.TargetDefinitions {
Expand Down Expand Up @@ -79,6 +72,17 @@ func decode(data []byte) *cacao.Playbook {
step.StepVariables.InsertOrReplace(variable)
}
}
}

func decode(data []byte) *cacao.Playbook {
playbook := cacao.NewPlaybook()

if err := json.Unmarshal(data, playbook); err != nil {
log.Error(err)
return nil
}

SetPlaybookKeysAsId(playbook)

return playbook
}

0 comments on commit c5e89c9

Please sign in to comment.