Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/223 loading playbooks from database is missing authentication information #224

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}