Skip to content
This repository has been archived by the owner on Nov 6, 2019. It is now read-only.

Commit

Permalink
Merge pull request #106 from manifoldco/add-payload-logging
Browse files Browse the repository at this point in the history
Add Health Check for the GH Callback Server.
  • Loading branch information
jelmersnoeck authored Aug 13, 2018
2 parents 4daf8eb + 3c5fde6 commit 6679095
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Added

- Added a health check for the GitHub Callback Server.
- Added logging to indicate GH Callback Server requests.

## [0.1.2] - 2018-07-16

### Fixed
Expand Down
12 changes: 12 additions & 0 deletions docs/kube/github-policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ spec:
requests:
cpu: 100m
memory: 10Mi
readinessProbe:
httpGet:
path: /_healthz
port: 8080
initialDelaySeconds: 3
periodSeconds: 3
livenessProbe:
httpGet:
path: /_healthz
port: 8080
initialDelaySeconds: 5
periodSeconds: 3

---

Expand Down
10 changes: 10 additions & 0 deletions internal/githubrepository/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type callbackHook struct {
func (s *callbackServer) start(address string) {
hdlr := mux.NewRouter()
hdlr.HandleFunc("/payload/{owner}/{name}", s.payloadHandler)
hdlr.HandleFunc("/_healtz", s.healthzHandler)

s.srv = &http.Server{
Handler: hdlr,
Expand All @@ -84,17 +85,26 @@ func (s *callbackServer) stop(ctx context.Context) error {
return s.srv.Shutdown(ctx)
}

func (s *callbackServer) healthzHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK!"))
}

func (s *callbackServer) payloadHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
log.Printf("Handling payload for %s/%s", vars["owner"], vars["name"])

cbHook, ok := s.hookForRepo(vars["owner"], vars["name"])
if !ok {
log.Printf("No repository found for %s/%s", vars["owner"], vars["name"])
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("404 Not Found"))
return
}

payload, err := github.ValidatePayload(r, []byte(cbHook.hook.Secret))
if err != nil {
log.Printf("Could not validate payload for %s/%s: %s", vars["owner"], vars["name"], err)
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
Expand Down

0 comments on commit 6679095

Please sign in to comment.