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

direct ping decode see if this works #4

Merged
merged 1 commit into from
Nov 4, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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