diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6ce56154..931df72a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -27,7 +27,6 @@ stages: variables: GO111MODULE: 'on' GOFLAGS: '-mod=vendor' -# PATH: '$PATH:$CI_PROJECT_DIR/bin' Go Dependencies: needs: [ ] @@ -68,7 +67,7 @@ Binary: - k8s:shared - arch:amd64 script: - - go build -o ./bin/rest-api-${GOARCH} github.com/monetrapp/rest-api/cmd/api + - make build cache: key: go-${CI_COMMIT_SHA} paths: diff --git a/pkg/controller/plaid_webhook.go b/pkg/controller/plaid_webhook.go index 7d7f9163..dc8698ae 100644 --- a/pkg/controller/plaid_webhook.go +++ b/pkg/controller/plaid_webhook.go @@ -1,12 +1,37 @@ package controller import ( + "net/http" "net/url" + "strings" "github.com/kataras/iris/v12/context" ) +type PlaidWebhook struct { + WebhookType string `json:"webhook_type"` + WebhookCode string `json:"webhook_code"` + ItemId string `json:"item_id"` + Error map[string]interface{} `json:"error"` + NewWebhookURL string `json:"new_webhook_url"` + NewTransactions int64 `json:"new_transactions"` + RemovedTransactions []string `json:"removed_transactions"` +} + func (c *Controller) handlePlaidWebhook(ctx *context.Context) { + verification := ctx.GetHeader("Plaid-Verification") + if strings.TrimSpace(verification) == "" { + c.returnError(ctx, http.StatusUnauthorized, "unauthorized") + return + } + + // TODO Properly verify webhooks from Plaid. + + var hook PlaidWebhook + if err := ctx.ReadJSON(&hook); err != nil { + c.badRequest(ctx, "malformed JSON") + return + } }