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

Included option to don't verify marathon SSL #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (config *Config) parseFlags() {
flag.StringVar(&config.Marathon.Protocol, "marathon-protocol", "http", "marathon protocol (http or https)")
flag.StringVar(&config.Marathon.Username, "marathon-username", "", "marathon username for basic auth")
flag.StringVar(&config.Marathon.Password, "marathon-password", "", "marathon password for basic auth")
flag.BoolVar(&config.Marathon.NoVerifySSL, "marathon-noverify", false, "don't verify marathon SSL certificates")

// General
flag.StringVar(&config.LogLevel, "log-level", "info", "log level: panic, fatal, error, warn, info, or debug")
Expand Down
10 changes: 6 additions & 4 deletions config/marathon.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
)

type MarathonConfig struct {
Location string
Protocol string
Username string
Password string
Location string
Protocol string
Username string
Password string
NoVerifySSL bool
}

func (m MarathonConfig) Validate() {
Expand All @@ -29,5 +30,6 @@ func (m MarathonConfig) NewMarathon() (marathon.Marathon, error) {
m.Location,
m.Protocol,
url.UserPassword(m.Username, m.Password),
m.NoVerifySSL,
)
}
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bufio"
"bytes"
"crypto/tls"
"net/http"
"os"
"time"
Expand Down Expand Up @@ -61,7 +62,7 @@ func main() {
func SubscribeToEventStream(config *config.Config, m marathon.Marathon, fh *ForwardHandler) {
Reconnect:
for {
resp, err := makeEventStreamRequest(m.Url("/v2/events"))
resp, err := makeEventStreamRequest(m.Url("/v2/events"), m.NoVerifySsl)
defer resp.Body.Close()
reader := bufio.NewReader(resp.Body)
log.Info("connected to /v2/events endpoint")
Expand Down Expand Up @@ -134,7 +135,7 @@ func ServeWebhookReceiver(config *config.Config, fh *ForwardHandler) {
log.Fatal(http.ListenAndServe(config.Web.Listen, nil))
}

func makeEventStreamRequest(url string) (*http.Response, error) {
func makeEventStreamRequest(url string, noVerifySsl bool) (*http.Response, error) {
buffer := make([]byte, 1024)
req, err := http.NewRequest("GET", url, bytes.NewBuffer(buffer))
if err != nil {
Expand All @@ -143,6 +144,13 @@ func makeEventStreamRequest(url string) (*http.Response, error) {
}
req.Header.Set("Accept", "text/event-stream")
client := &http.Client{}
client.Transport = &http.Transport{
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: noVerifySsl,
},
}

resp, err := client.Do(req)
if err != nil {
log.WithError(err).Error("HTTP request for /v2/events failed!")
Expand Down
4 changes: 2 additions & 2 deletions marathon/marathon.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type Marathon struct {
NoVerifySsl bool
}

func NewMarathon(location, protocol string, auth *url.Userinfo) (Marathon, error) {
return Marathon{location, protocol, auth, false}, nil
func NewMarathon(location, protocol string, auth *url.Userinfo, sslVerify bool) (Marathon, error) {
return Marathon{location, protocol, auth, sslVerify}, nil
}

func (m Marathon) Url(path string) string {
Expand Down
8 changes: 4 additions & 4 deletions marathon/marathon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func TestUrl(t *testing.T) {
t.Parallel()

m, _ := NewMarathon("localhost:8080", "http", nil)
m, _ := NewMarathon("localhost:8080", "http", nil, false)
url := m.Url("/v2/apps")

assert.Equal(t, url, "http://localhost:8080/v2/apps")
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestParseVersion(t *testing.T) {
"type": "http_callback"
}
}`)
m, _ := NewMarathon("localhost:8080", "http", nil)
m, _ := NewMarathon("localhost:8080", "http", nil, false)
v, err := m.ParseVersion(infoBlob)
assert.Equal(t, v, "0.11.1")
assert.Nil(t, err)
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestParseApps(t *testing.T) {
]}
`)

m, _ := NewMarathon("localhost:8080", "http", nil)
m, _ := NewMarathon("localhost:8080", "http", nil, false)
apps, err := m.ParseApps(appBlob)
assert.Nil(t, err)
assert.Equal(t, len(apps), 1)
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestParseTasks(t *testing.T) {
}
`)

m, _ := NewMarathon("localhost:8080", "http", nil)
m, _ := NewMarathon("localhost:8080", "http", nil, false)
tasks, err := m.ParseTasks(tasksBlob)
assert.Nil(t, err)
assert.Equal(t, len(tasks), 2)
Expand Down