mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2026-01-25 15:33:31 +01:00
@@ -17,11 +17,12 @@ type busService struct {
|
||||
apiURL string
|
||||
apiKey string
|
||||
catalystBus *bus.Bus
|
||||
network string
|
||||
}
|
||||
|
||||
func New(apiURL, apikey string, catalystBus *bus.Bus, db *database.Database) error {
|
||||
func New(apiURL, apikey, network string, catalystBus *bus.Bus, db *database.Database) error {
|
||||
|
||||
h := &busService{db: db, apiURL: apiURL, apiKey: apikey, catalystBus: catalystBus}
|
||||
h := &busService{db: db, apiURL: apiURL, apiKey: apikey, network: network, catalystBus: catalystBus}
|
||||
|
||||
if err := catalystBus.SubscribeRequest(h.logRequest); err != nil {
|
||||
return err
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/SecurityBrewery/catalyst/database"
|
||||
)
|
||||
|
||||
func createContainer(ctx context.Context, image, script, data string) (string, string, error) {
|
||||
func createContainer(ctx context.Context, image, script, data, network string) (string, string, error) {
|
||||
cli, err := client.NewClientWithOpts(client.FromEnv)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
@@ -29,10 +29,16 @@ func createContainer(ctx context.Context, image, script, data string) (string, s
|
||||
}
|
||||
|
||||
config := &container.Config{
|
||||
Image: image, Cmd: []string{"/script", data}, WorkingDir: "/home",
|
||||
AttachStderr: true, AttachStdout: true,
|
||||
Image: image,
|
||||
Cmd: []string{"/script", data},
|
||||
WorkingDir: "/home",
|
||||
AttachStderr: true,
|
||||
AttachStdout: true,
|
||||
}
|
||||
resp, err := cli.ContainerCreate(ctx, config, nil, nil, "")
|
||||
hostConfig := &container.HostConfig{
|
||||
NetworkMode: container.NetworkMode(network),
|
||||
}
|
||||
resp, err := cli.ContainerCreate(ctx, config, hostConfig, nil, "")
|
||||
if err != nil {
|
||||
return "", logs, err
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func (h *busService) handleJob(automationMsg *bus.JobMsg) {
|
||||
|
||||
scriptMessage, _ := json.Marshal(automationMsg.Message)
|
||||
|
||||
containerID, logs, err := createContainer(ctx, automation.Image, automation.Script, string(scriptMessage))
|
||||
containerID, logs, err := createContainer(ctx, automation.Image, automation.Script, string(scriptMessage), h.network)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user