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

Update to latest version of go-github #157

Merged
merged 1 commit into from Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gopkg.lock

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

58 changes: 19 additions & 39 deletions server/server.go
Expand Up @@ -9,7 +9,6 @@ import (
"strings"
"time"

"bytes"
"io/ioutil"

"github.com/elazarl/go-bindata-assetfs"
Expand All @@ -23,7 +22,7 @@ import (
"github.com/hootsuite/atlantis/run"
"github.com/hootsuite/atlantis/static"
"github.com/hootsuite/atlantis/terraform"
homedir "github.com/mitchellh/go-homedir"
"github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
"github.com/urfave/cli"
"github.com/urfave/negroni"
Expand Down Expand Up @@ -295,51 +294,32 @@ func (s *Server) postEvents(w http.ResponseWriter, r *http.Request) {
githubReqID := "X-Github-Delivery=" + r.Header.Get("X-Github-Delivery")
var payload []byte

// webhook requests can either be application/json or application/x-www-form-urlencoded.
// We accept both to make it easier on users that may choose x-www-form-urlencoded by mistake
// todo: use go-github's ValidatePayload method if https://github.com/google/go-github/pull/693 is merged
if r.Header.Get("Content-Type") == "application/x-www-form-urlencoded" {
// GitHub stores the json payload as a form value
payloadForm := r.FormValue("payload")
if payloadForm == "" {
s.respond(w, logging.Warn, http.StatusBadRequest, "request did not contain expected 'payload' form value")
// If we need to validate the Webhook secret, we can use go-github's
// ValidatePayload method. Otherwise we need to parse the request ourselves.
if len(s.githubWebHookSecret) != 0 {
var err error
if payload, err = gh.ValidatePayload(r, s.githubWebHookSecret); err != nil {
s.respond(w, logging.Warn, http.StatusBadRequest, "webhook request failed secret key validation")
return
}
if len(s.githubWebHookSecret) != 0 {
// github calculates the signature based on the query escaped
// post body. In order to use go-github's ValidatePayload method
// that only accepts an http request we need to override r.Body
// with a value that was the original raw body before it was
// parsed.
rawPayload := fmt.Sprintf("payload=%s", url.QueryEscape(payloadForm))
r.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(rawPayload)))
_, err := gh.ValidatePayload(r, s.githubWebHookSecret)
if err != nil {
s.respond(w, logging.Warn, http.StatusBadRequest, "webhook failed secret key validation")
return
}
}
payload = []byte(payloadForm)
} else {
// else read it as json
if len(s.githubWebHookSecret) != 0 {
switch ct := r.Header.Get("Content-Type"); ct {
case "application/json":
var err error
payload, err = gh.ValidatePayload(r, s.githubWebHookSecret)
if err != nil {
s.respond(w, logging.Warn, http.StatusBadRequest, "webhook failed secret key validation")
if payload, err = ioutil.ReadAll(r.Body); err != nil {
s.respond(w, logging.Warn, http.StatusBadRequest, "could not read body: %s", err)
return
}
} else {
// if we're not validating against the webhook secret then
// we can't use the ValidatePayload method and need to read
// the request body ourselves.
defer r.Body.Close()
var err error
payload, err = ioutil.ReadAll(r.Body)
if err != nil {
s.respond(w, logging.Warn, http.StatusBadRequest, "could not read body: %s", err)
case "application/x-www-form-urlencoded":
// GitHub stores the json payload as a form value
payloadForm := r.FormValue("payload")
if payloadForm == "" {
s.respond(w, logging.Warn, http.StatusBadRequest, "webhook request did not contain expected 'payload' form value")
return
}
payload = []byte(payloadForm)
default:
s.respond(w, logging.Warn, http.StatusBadRequest, fmt.Sprintf("webhook request has unsupported Content-Type %q", ct))
}
}

Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/google/go-github/.travis.yml

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

3 changes: 2 additions & 1 deletion vendor/github.com/google/go-github/example/appengine/app.go

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

32 changes: 32 additions & 0 deletions vendor/github.com/google/go-github/github/github-accessors.go

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

2 changes: 1 addition & 1 deletion vendor/github.com/google/go-github/github/github.go

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

14 changes: 13 additions & 1 deletion vendor/github.com/google/go-github/github/issues.go

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

11 changes: 11 additions & 0 deletions vendor/github.com/google/go-github/github/issues_test.go

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

41 changes: 37 additions & 4 deletions vendor/github.com/google/go-github/github/messages.go

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