Skip to content

Commit

Permalink
Merge pull request #4 from k8sdeploy/directPingDecode
Browse files Browse the repository at this point in the history
direct ping decode see if this works
  • Loading branch information
Keloran committed Nov 4, 2021
2 parents fc8c432 + da7db94 commit 433f7ac
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ jobs:
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
build-args: |
version={{version}}
build=${{ github.sha }}
platforms: linux/arm64
file: ./k8s/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
Expand Down
21 changes: 11 additions & 10 deletions internal/tygon/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"net/http"

bugLog "github.com/bugfixes/go-bugfixes/logs"
"github.com/mitchellh/mapstructure"
"github.com/google/go-github/v39/github"
"github.com/mitchellh/mapstructure"
)

func jsonError(w http.ResponseWriter, msg string, errs error) {
Expand All @@ -22,16 +23,11 @@ func jsonError(w http.ResponseWriter, msg string, errs error) {
}

func (t Tygon) ParsePayload(w http.ResponseWriter, r *http.Request) {
var decodedJSON interface{}

if err := json.NewDecoder(r.Body).Decode(&decodedJSON); err != nil {
jsonError(w, "Invalid JSON", err)
return
}
var decodedPing github.Hook

// it's a ping event
if err := mapstructure.Decode(decodedJSON, &t.PingEvent); err == nil {
if err := t.PingEventTriggered(); err != nil {
if err := json.NewDecoder(r.Body).Decode(&decodedPing); err == nil {
if err := t.PingEventTriggered(decodedPing); err != nil {
jsonError(w, "Ping event failed", err)
return
}
Expand All @@ -40,7 +36,12 @@ func (t Tygon) ParsePayload(w http.ResponseWriter, r *http.Request) {
}

w.WriteHeader(http.StatusOK)
bugLog.Infof("Request: %+v", decodedJSON)
var unknownPayload interface{}
if err := json.NewDecoder(r.Body).Decode(&unknownPayload); err != nil {
jsonError(w, "unknown payload", err)
return
}
bugLog.Infof("Request: %+v", unknownPayload)
for name, values := range r.Header {
for _, value := range values {
bugLog.Infof("Header: %s: %s", name, value)
Expand Down
4 changes: 2 additions & 2 deletions internal/tygon/tygon.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func NewTygon(cfg *config.Config) *Tygon {
}
}

func (t *Tygon) PingEventTriggered() error {
func (t *Tygon) PingEventTriggered(p *github.Hook) error {
pingConfig := PingEventConfig{}

if err := mapstructure.Decode(t.PingEvent.Config, &pingConfig); err != nil {
if err := mapstructure.Decode(p.Config, &pingConfig); err != nil {
bugLog.Debugf("failed to decode ping config: %+v", err)
return err
}
Expand Down
2 changes: 1 addition & 1 deletion k8s/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
- name: regcred
containers:
- name: tygon
image: ghcr.io/k8sdeploy/tygon:0.2.0
image: ghcr.io/k8sdeploy/tygon:0.2.1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
Expand Down

0 comments on commit 433f7ac

Please sign in to comment.