-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
364 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module soarca | ||
|
||
go 1.22 | ||
go 1.22.0 | ||
|
||
require ( | ||
github.com/eclipse/paho.mqtt.golang v1.4.3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
internal/reporter/downstream_reporter/downstream_reporter.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package downstream_reporter | ||
|
||
import ( | ||
"soarca/models/cacao" | ||
|
||
"github.com/google/uuid" | ||
) | ||
|
||
type IDownStreamReporter interface { | ||
ReportWorkflow(executionId uuid.UUID, playbook cacao.Playbook) error | ||
ReportStep(executionId uuid.UUID, step cacao.Step, stepResults cacao.Variables, err error) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package reporter | ||
|
||
import ( | ||
"errors" | ||
"reflect" | ||
"strconv" | ||
|
||
downstreamReporter "soarca/internal/reporter/downstream_reporter" | ||
"soarca/logger" | ||
"soarca/models/cacao" | ||
"soarca/utils" | ||
|
||
"github.com/google/uuid" | ||
) | ||
|
||
type Empty struct{} | ||
|
||
var component = reflect.TypeOf(Empty{}).PkgPath() | ||
var log *logger.Log | ||
|
||
func init() { | ||
log = logger.Logger(component, logger.Info, "", logger.Json) | ||
} | ||
|
||
// Reporter interfaces | ||
type IWorkflowReporter interface { | ||
// -> Give info to downstream reporters | ||
ReportWorkflow(executionId uuid.UUID, playbook cacao.Playbook) | ||
} | ||
type IStepReporter interface { | ||
// -> Give info to downstream reporters | ||
ReportStep(executionId uuid.UUID, step cacao.Step, returnVars cacao.Variables, err error) | ||
} | ||
|
||
const MaxReporters int = 10 | ||
|
||
// High-level reporter class with injection of specific reporters | ||
type Reporter struct { | ||
reporters []downstreamReporter.IDownStreamReporter | ||
maxReporters int | ||
} | ||
|
||
func New(reporters []downstreamReporter.IDownStreamReporter) *Reporter { | ||
maxReporters, _ := strconv.Atoi(utils.GetEnv("MAX_REPORTERS", strconv.Itoa(MaxReporters))) | ||
instance := Reporter{ | ||
reporters: reporters, | ||
maxReporters: maxReporters, | ||
} | ||
return &instance | ||
} | ||
|
||
func (reporter *Reporter) RegisterReporters(reporters []downstreamReporter.IDownStreamReporter) error { | ||
if (len(reporter.reporters) + len(reporters)) > reporter.maxReporters { | ||
log.Warning("reporter not registered, too many reporters") | ||
return errors.New("attempting to register too many reporters") | ||
} | ||
reporter.reporters = append(reporter.reporters, reporters...) | ||
return nil | ||
} | ||
|
||
func (reporter *Reporter) ReportWorkflow(executionId uuid.UUID, playbook cacao.Playbook) { | ||
log.Trace("reporting workflow") | ||
for _, rep := range reporter.reporters { | ||
err := rep.ReportWorkflow(executionId, playbook) | ||
if err != nil { | ||
log.Warning(err) | ||
} | ||
} | ||
} | ||
|
||
func (reporter *Reporter) ReportStep(executionId uuid.UUID, step cacao.Step, returnVars cacao.Variables, err error) { | ||
log.Trace("reporting step data") | ||
for _, rep := range reporter.reporters { | ||
err := rep.ReportStep(executionId, step, returnVars, err) | ||
if err != nil { | ||
log.Warning(err) | ||
} | ||
} | ||
} |
Oops, something went wrong.