Skip to content

Commit

Permalink
Use gocertifi to avoid x509 error on containers
Browse files Browse the repository at this point in the history
  • Loading branch information
agonzalezro committed Jan 24, 2017
1 parent adf1e37 commit 65b9cd0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 42 deletions.
23 changes: 21 additions & 2 deletions adapter/slack.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package adapter

import (
"crypto/tls"
"encoding/json"
"errors"
"fmt"
Expand All @@ -11,6 +12,7 @@ import (
"golang.org/x/net/websocket"

"github.com/agonzalezro/botella/plugin"
"github.com/certifi/gocertifi"
)

const (
Expand Down Expand Up @@ -42,9 +44,21 @@ func (sm SlackMessage) isDirectMessage() bool {
return strings.HasPrefix(sm.Channel, "D")
}

// TODO: this requires refactoring, it's tooooo long
func NewSlack(key string) (*SlackAdapter, error) {
url := fmt.Sprintf(rtmURLformatter, key)
resp, err := http.Get(url)

cert_pool, err := gocertifi.CACerts()
if err != nil {
return nil, err
}

transport := &http.Transport{
TLSClientConfig: &tls.Config{RootCAs: cert_pool},
}
client := http.Client{Transport: transport}

resp, err := client.Get(url)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -75,7 +89,12 @@ func NewSlack(key string) (*SlackAdapter, error) {
return nil, errors.New(p.Error)
}

ws, err := websocket.Dial(p.URL, "", wsURL)
c, err := websocket.NewConfig(p.URL, wsURL)
if err != nil {
return nil, err
}
c.TlsConfig = &tls.Config{RootCAs: cert_pool}
ws, err := websocket.DialConfig(c)
if err != nil {
return nil, err
}
Expand Down
64 changes: 24 additions & 40 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ import:
- package: github.com/Sirupsen/logrus
version: ^0.10.0
- package: github.com/twinj/uuid
- package: github.com/certifi/gocertifi
version: ~2017.1.23

0 comments on commit 65b9cd0

Please sign in to comment.