Skip to content

Commit

Permalink
update to use sfomuseum/go-runtimevar for handling runtimevar URIs; u…
Browse files Browse the repository at this point in the history
…pdate to use aaronland/go-log for wrapping log messages; update vendor deps
  • Loading branch information
sfomuseumbot committed Feb 9, 2023
1 parent 331539f commit 558f491
Show file tree
Hide file tree
Showing 1,003 changed files with 343,487 additions and 4,931 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ bump-version:
find . -name '*.go' | xargs perl -i -p -e 's/github.com\/whosonfirst\/go-webhookd\/$(PREVIOUS)/github.com\/whosonfirst\/go-webhookd\/$(NEW)/g'

cli:
go build -mod vendor -o bin/webhookd cmd/webhookd/main.go
go build -mod vendor -o bin/webhookd-generate-hook cmd/webhookd-generate-hook/main.go
go build -mod vendor -o bin/webhookd-flatten-config cmd/webhookd-flatten-config/main.go
go build -mod vendor -o bin/webhookd-inflate-config cmd/webhookd-inflate-config/main.go
go build -mod vendor -ldflags="-s -w" -o bin/webhookd cmd/webhookd/main.go
go build -mod vendor -ldflags="-s -w" -o bin/webhookd-generate-hook cmd/webhookd-generate-hook/main.go
go build -mod vendor -ldflags="-s -w" -o bin/webhookd-flatten-config cmd/webhookd-flatten-config/main.go
go build -mod vendor -ldflags="-s -w" -o bin/webhookd-inflate-config cmd/webhookd-inflate-config/main.go

local-scan:
/usr/local/bin/sonar-scanner/bin/sonar-scanner -Dsonar.projectKey=go-webhookd -Dsonar.sources=. -Dsonar.host.url=http://localhost:9000 -Dsonar.login=$(TOKEN)
Expand Down
14 changes: 3 additions & 11 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"context"
"encoding/json"
"fmt"
"gocloud.dev/runtimevar"
_ "gocloud.dev/runtimevar/constantvar"
_ "gocloud.dev/runtimevar/filevar"
"io"
_ "log"
"strings"

"github.com/sfomuseum/runtimevar"
)

// type WebhookConfig is a struct containing configuration information for a `webhookd` instance.
Expand Down Expand Up @@ -51,19 +50,12 @@ type WebhookWebhooksConfig struct {
// a valid `gocloud.dev/runtimevar` URI. The value of that URI is expected to be a JSON-encoded `WebhookConfig` string.
func NewConfigFromURI(ctx context.Context, uri string) (*WebhookConfig, error) {

v, err := runtimevar.OpenVariable(ctx, uri)
str_cfg, err := runtimevar.StringVar(ctx, uri)

if err != nil {
return nil, fmt.Errorf("Failed to open config URI, %w", err)
}

latest, err := v.Latest(ctx)

if err != nil {
return nil, fmt.Errorf("Failed to determine latest value for config URI, %w", err)
}

str_cfg := latest.Value.(string)
cfg_fh := strings.NewReader(str_cfg)

return NewConfigFromReader(ctx, cfg_fh)
Expand Down
36 changes: 22 additions & 14 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ package daemon
import (
"context"
"fmt"
"github.com/aaronland/go-http-server"
"github.com/whosonfirst/go-webhookd/v3"
"github.com/whosonfirst/go-webhookd/v3/config"
"github.com/whosonfirst/go-webhookd/v3/dispatcher"
"github.com/whosonfirst/go-webhookd/v3/receiver"
"github.com/whosonfirst/go-webhookd/v3/transformation"
"github.com/whosonfirst/go-webhookd/v3/webhook"
"log"
"net/http"
"net/url"
"strconv"
"strings"
"sync"
"time"

aa_log "github.com/aaronland/go-log/v2"
"github.com/aaronland/go-http-server"
"github.com/whosonfirst/go-webhookd/v3"
"github.com/whosonfirst/go-webhookd/v3/config"
"github.com/whosonfirst/go-webhookd/v3/dispatcher"
"github.com/whosonfirst/go-webhookd/v3/receiver"
"github.com/whosonfirst/go-webhookd/v3/transformation"
"github.com/whosonfirst/go-webhookd/v3/webhook"
)

// type WebhookDaemon is a struct that implements a long-running daemon to listen for and process webhooks.
Expand Down Expand Up @@ -225,6 +227,7 @@ func (d *WebhookDaemon) HandlerFuncWithLogger(logger *log.Logger) (http.HandlerF
wh, ok := d.webhooks[endpoint]

if !ok {
aa_log.Warning(logger, "Endpoint not found, %s", endpoint)
http.Error(rsp, "404 Not found", http.StatusNotFound)
return
}
Expand Down Expand Up @@ -252,10 +255,10 @@ func (d *WebhookDaemon) HandlerFuncWithLogger(logger *log.Logger) (http.HandlerF

switch err.Code {
case webhookd.UnhandledEvent, webhookd.HaltEvent:
logger.Printf("Receiver step (%T) returned non-fatal error and exiting, %v", rcvr, err)
aa_log.Info(logger, "Receiver step (%T) returned non-fatal error and exiting, %v", rcvr, err)
return
default:
logger.Printf("Receiver step (%T) failed, %v", rcvr, err)
aa_log.Error(logger, "Receiver step (%T) failed, %v", rcvr, err)
http.Error(rsp, err.Error(), err.Code)
return
}
Expand All @@ -275,10 +278,10 @@ func (d *WebhookDaemon) HandlerFuncWithLogger(logger *log.Logger) (http.HandlerF

switch err.Code {
case webhookd.UnhandledEvent, webhookd.HaltEvent:
logger.Printf("Transformation step (%T) at offset %d returned non-fatal error and exiting, %v", step, idx, err)
aa_log.Info(logger, "Transformation step (%T) at offset %d returned non-fatal error and exiting, %v", step, idx, err)
return
default:
logger.Printf("Transformation step (%T) at offset %d failed, %v", step, idx, err)
aa_log.Error(logger, "Transformation step (%T) at offset %d failed, %v", step, idx, err)
http.Error(rsp, err.Error(), err.Code)
return
}
Expand Down Expand Up @@ -313,10 +316,10 @@ func (d *WebhookDaemon) HandlerFuncWithLogger(logger *log.Logger) (http.HandlerF

switch err.Code {
case webhookd.UnhandledEvent, webhookd.HaltEvent:
logger.Printf("Dispatch step (%T) at offset %d returned non-fatal error and exiting, %v", d, idx, err)
aa_log.Info(logger, "Dispatch step (%T) at offset %d returned non-fatal error and exiting, %v", d, idx, err)
return
default:
logger.Printf("Dispatch step (%T) at offset %d failed, %v", d, idx, err)
aa_log.Error(logger, "Dispatch step (%T) at offset %d failed, %v", d, idx, err)
ch <- err
}
}
Expand Down Expand Up @@ -351,6 +354,11 @@ func (d *WebhookDaemon) HandlerFuncWithLogger(logger *log.Logger) (http.HandlerF

t2 := time.Since(t1)

aa_log.Debug(logger, "Time to receive: %v", ttr)
aa_log.Debug(logger, "Time to transform: %v", ttt)
aa_log.Debug(logger, "Time to dispatch: %v", ttd)
aa_log.Debug(logger, "Time to process: %v", t2)

rsp.Header().Set("X-Webhookd-Time-To-Receive", fmt.Sprintf("%v", ttr))
rsp.Header().Set("X-Webhookd-Time-To-Transform", fmt.Sprintf("%v", ttt))
rsp.Header().Set("X-Webhookd-Time-To-Dispatch", fmt.Sprintf("%v", ttd))
Expand Down Expand Up @@ -394,7 +402,7 @@ func (d *WebhookDaemon) StartWithLogger(ctx context.Context, logger *log.Logger)

svr := d.server

logger.Printf("webhookd listening for requests on %s\n", svr.Address())
aa_log.Info(logger, "webhookd listening for requests on %s\n", svr.Address())

err = svr.ListenAndServe(ctx, mux)

Expand Down
42 changes: 31 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,46 @@ go 1.18
require (
github.com/aaronland/go-chicken v0.2.2
github.com/aaronland/go-http-server v1.0.0
github.com/aaronland/go-log/v2 v2.0.0
github.com/aaronland/go-roster v1.0.0
github.com/sfomuseum/go-flags v0.10.0
gocloud.dev v0.27.0
github.com/sfomuseum/runtimevar v1.0.4
gocloud.dev v0.28.0
)

require (
github.com/aaronland/go-aws-session v0.1.0 // indirect
github.com/aaronland/go-string v1.0.0 // indirect
github.com/aaronland/go-ucd/v13 v13.0.0 // indirect
github.com/akrylysov/algnhsa v0.12.1 // indirect
github.com/aws/aws-lambda-go v1.13.3 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/aws/aws-sdk-go v1.44.163 // indirect
github.com/aws/aws-sdk-go-v2 v1.17.1 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.3 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.3 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.19 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.25 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.19 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.26 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.19 // indirect
github.com/aws/aws-sdk-go-v2/service/ssm v1.33.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.11.25 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.13.8 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.17.5 // indirect
github.com/aws/smithy-go v1.13.4 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/googleapis/gax-go/v2 v2.4.0 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/net v0.0.0-20220802222814-0bcc04d9c69b // indirect
golang.org/x/sys v0.0.0-20220731174439-a90be440212d // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
google.golang.org/api v0.91.0 // indirect
google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 // indirect
google.golang.org/grpc v1.48.0 // indirect
github.com/google/wire v0.5.0 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.103.0 // indirect
google.golang.org/genproto v0.0.0-20221201204527-e3fa12d562f3 // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
)
Loading

0 comments on commit 558f491

Please sign in to comment.