Skip to content

Commit

Permalink
Adds InsecureSkipVerify config option. (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
maietta committed Jun 18, 2022
1 parent d554e38 commit 9b6e215
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 3 deletions.
105 changes: 105 additions & 0 deletions alternative.txt
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
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

}

}
}

}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
7 changes: 7 additions & 0 deletions middlewares/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package middlewares

import (
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
"html/template"
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 9b6e215

Please sign in to comment.