diff --git a/alternative.txt b/alternative.txt new file mode 100644 index 0000000..58a2a9e --- /dev/null +++ b/alternative.txt @@ -0,0 +1,105 @@ +package main + +import ( + "context" + "fmt" + "io" + "strings" + + "github.com/docker/docker/api/types" + "github.com/docker/docker/client" +) + +/* + { + Status:destroy + ID:f1a09c48aa893fb68388f1ebeda0ea12dc4df7bcba9a98abab3abb9cee06e9e5 + From:nginx + Type:container + Action:destroy + Actor: { + ID:f1a09c48aa893fb68388f1ebeda0ea12dc4df7bcba9a98abab3abb9cee06e9e5 + Attributes:map[ + chadburn.enabled:true + chadburn.job-exec.test-exec-job.command:uname -a + chadburn.job-exec.test-exec-job.schedule:@every 5s + image:nginx maintainer:NGINX Docker Maintainers + name:festive_tharp + ] + } + Scope:local + Time:1641000210 + TimeNano:1641000210626965000 +*/ + +func main() { + + cli, err := client.NewEnvClient() + if err != nil { + panic(err) + } + + messages, errs := cli.Events(context.Background(), types.EventsOptions{}) + +EventLoop: + for { + select { + case err := <-errs: + if err != nil && err != io.EOF { + panic(err) + } + if err != nil && err == io.EOF { + fmt.Printf("lost connection with Docker. exiting\n") + break EventLoop + } + case message := <-messages: + + if message.Action == "start" || message.Action == "die" { + + container_name := message.Actor.Attributes["name"] + fmt.Println("Registered:", container_name) + + // fmt.Printf("%+v\n\n", message) + + // Get service labels from the event + enabled := message.Actor.Attributes["chadburn.enabled"] + + if enabled == "true" { + + exec_type := "" + exec_cmd := "" + + // Get attributes that start with chadburn.job-* + for k, v := range message.Actor.Attributes { + if strings.HasPrefix(k, "chadburn.job-") { + exec_type = k + exec_cmd = v + fmt.Println(exec_type, "", exec_cmd) + } + } + + fmt.Printf("%+v\n\n", message) + + if message.Actor.Attributes["chadburn.job-exec"] == "true" { + // This job is executed inside of a running container. + } else if message.Actor.Attributes["chadburn.job-run"] == "true" { + // Runs a command inside of a new container, using a specific image. + } else if message.Actor.Attributes["chadburn.job-local"] == "true" { + // Runs the command inside of the host running Chadburn. + } else if message.Actor.Attributes["chadburn.job-service-run"] == "true" { + // Runs the command inside a new "run-once" service, for running inside a swarm + } + + } + + } + + if message.Action == "stop" || message.Action == "die" || message.Action == "destroy" { + // Dereigster the service + + } + + } + } + +} \ No newline at end of file diff --git a/go.mod b/go.mod index 02e53be..ce1c39b 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,6 @@ require ( github.com/docker/docker v1.4.2-0.20191101170500-ac7306503d23 github.com/pkg/errors v0.9.1 // indirect golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect - golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect gopkg.in/warnings.v0 v0.1.2 // indirect ) diff --git a/go.sum b/go.sum index f37a148..49a9cd3 100644 --- a/go.sum +++ b/go.sum @@ -164,8 +164,6 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 h1:GZokNIeuVkl3aZHJchRrr13WCsols02MLUcz1U9is6M= -golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/middlewares/mail.go b/middlewares/mail.go index 5b166fb..3606d2a 100644 --- a/middlewares/mail.go +++ b/middlewares/mail.go @@ -2,6 +2,7 @@ package middlewares import ( "bytes" + "crypto/tls" "encoding/json" "fmt" "html/template" @@ -23,6 +24,7 @@ type MailConfig struct { EmailTo string `gcfg:"email-to" mapstructure:"email-to"` EmailFrom string `gcfg:"email-from" mapstructure:"email-from"` MailOnlyOnError bool `gcfg:"mail-only-on-error" mapstructure:"mail-only-on-error"` + InsecureSkipVerify bool `gcfg:"insecure-skip-verify" mapstructure:"insecure-skip-verify"` } // NewMail returns a Mail middleware if the given configuration is not empty @@ -94,6 +96,11 @@ func (m *Mail) sendMail(ctx *core.Context) error { return err } + // InsecureSkipVerify is used to skip the certificate verification + if m.InsecureSkipVerify == true { + d.TLSConfig = &tls.Config{InsecureSkipVerify: true} + } + return nil }