Add SkipTLSVerify option for mattermost, allows selfsigned certificates

This commit is contained in:
Wim 2015-10-25 01:00:19 +02:00
parent 43738dbc89
commit 8b6a00d1c5
5 changed files with 30 additions and 14 deletions

View File

@ -59,7 +59,8 @@ port=9999
showjoinpart=true #show irc users joining and parting showjoinpart=true #show irc users joining and parting
#the token you get from the outgoing webhook in mattermost. If empty no token check will be done. #the token you get from the outgoing webhook in mattermost. If empty no token check will be done.
token=yourtokenfrommattermost token=yourtokenfrommattermost
#disable certificate checking (selfsigned certificates)
#SkipTLSVerify=true
``` ```
### mattermost ### mattermost

View File

@ -16,11 +16,12 @@ type Config struct {
Channel string Channel string
} }
Mattermost struct { Mattermost struct {
URL string URL string
Port int Port int
ShowJoinPart bool ShowJoinPart bool
Token string Token string
IconURL string IconURL string
SkipTLSVerify bool
} }
} }

View File

@ -12,3 +12,4 @@ port=9999
showjoinpart=true showjoinpart=true
#token=yourtokenfrommattermost #token=yourtokenfrommattermost
IconURL="http://youricon.png" IconURL="http://youricon.png"
#SkipTLSVerify=true

View File

@ -20,7 +20,8 @@ func NewBridge(name string, config *Config) *Bridge {
b := &Bridge{} b := &Bridge{}
b.Config = config b.Config = config
b.m = matterhook.New(b.Config.Mattermost.URL, b.m = matterhook.New(b.Config.Mattermost.URL,
matterhook.Config{Port: b.Config.Mattermost.Port, Token: b.Config.Mattermost.Token}) matterhook.Config{Port: b.Config.Mattermost.Port, Token: b.Config.Mattermost.Token,
InsecureSkipVerify: b.Config.Mattermost.SkipTLSVerify})
b.i = b.createIRC(name) b.i = b.createIRC(name)
go b.handleMatter() go b.handleMatter()
return b return b
@ -68,7 +69,11 @@ func (b *Bridge) Send(nick string, message string) error {
matterMessage := matterhook.OMessage{IconURL: b.Config.Mattermost.IconURL} matterMessage := matterhook.OMessage{IconURL: b.Config.Mattermost.IconURL}
matterMessage.UserName = nick matterMessage.UserName = nick
matterMessage.Text = message matterMessage.Text = message
b.m.Send(matterMessage) err := b.m.Send(matterMessage)
if err != nil {
log.Println(err)
return err
}
return nil return nil
} }

View File

@ -3,6 +3,7 @@ package matterhook
import ( import (
"bytes" "bytes"
"crypto/tls"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/gorilla/schema" "github.com/gorilla/schema"
@ -39,16 +40,18 @@ type IMessage struct {
// Client for Mattermost. // Client for Mattermost.
type Client struct { type Client struct {
url string url string
In chan IMessage In chan IMessage
Out chan OMessage Out chan OMessage
httpclient *http.Client
Config Config
} }
// Config for client. // Config for client.
type Config struct { type Config struct {
Port int // Port to listen on. Port int // Port to listen on.
Token string // Only allow this token from Mattermost. (Allow everything when empty) Token string // Only allow this token from Mattermost. (Allow everything when empty)
InsecureSkipVerify bool // disable certificate checking
} }
// New Mattermost client. // New Mattermost client.
@ -57,6 +60,11 @@ func New(url string, config Config) *Client {
if c.Port == 0 { if c.Port == 0 {
c.Port = 9999 c.Port = 9999
} }
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: config.InsecureSkipVerify},
}
c.httpclient = &http.Client{Transport: tr}
go c.StartServer() go c.StartServer()
return c return c
} }
@ -124,7 +132,7 @@ func (c *Client) Send(msg OMessage) error {
if err != nil { if err != nil {
return err return err
} }
resp, err := http.Post(c.url, "application/json", bytes.NewReader(buf)) resp, err := c.httpclient.Post(c.url, "application/json", bytes.NewReader(buf))
if err != nil { if err != nil {
return err return err
} }