Skip to content

Commit

Permalink
docs: rename repo odk-webhook --> central-webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Jan 24, 2025
1 parent b9895dd commit e2c21e1
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
build_target: build
tag_override: ci
compose_file: compose.yml
compose_service: odkhook
compose_service: webhook
cache_extra_imgs: |
"docker.io/postgis/postgis:17-3.5-alpine"
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*.dll
*.so
*.dylib
**/**/odk-webhook
**/**/odkhook
**/**/central-webhook
**/**/centralwebhook

# Test binary, built with `go test -c`
*.test
Expand Down
4 changes: 2 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2

builds:
- binary: odkhook
- binary: centralwebhook
main: main.go
env:
- CGO_ENABLED=0
Expand All @@ -18,7 +18,7 @@ builds:
- -s -w -X main.version={{.Tag}} -X main.buildTime={{.Date}}

archives:
- name_template: "odkhook_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
- name_template: "centralwebhook_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
wrap_in_directory: false
format: tar.gz
# use zip for windows archives
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o /app/odkhook
RUN CGO_ENABLED=0 GOOS=linux go build -o /app/centralwebhook


# Run the tests in the container
Expand All @@ -24,8 +24,8 @@ RUN useradd -u 1000 nonroot -g 1000
# Deploy the application binary into sratch image
FROM scratch AS release
WORKDIR /app
COPY --from=build /app/odkhook /app/odkhook
COPY --from=build /app/centralwebhook /app/centralwebhook
COPY --from=useradd /etc/group /etc/group
COPY --from=useradd /etc/passwd /etc/passwd
USER nonroot:nonroot
ENTRYPOINT ["/app/odkhook"]
ENTRYPOINT ["/app/centralwebhook"]
46 changes: 39 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ODK Webhook
# Central Webhook

Call a remote API on ODK Central database events:

Expand All @@ -7,18 +7,18 @@ Call a remote API on ODK Central database events:

## Usage

The `odkhook` tool is a service that runs continually, monitoring the
The `centralwebhook` tool is a service that runs continually, monitoring the
ODK Central database for updates and triggering the webhook as appropriate.

### Binary

Download the binary for your platform from the
[releases](https://github.com/hotosm/odk-webhook/releases) page.
[releases](https://github.com/hotosm/central-webhook/releases) page.

Then run with:

```bash
./odkhook \
./centralwebhook \
-db 'postgresql://{user}:{password}@{hostname}/{db}?sslmode=disable' \
-entityUrl 'https://your.domain.com/some/webhook' \
-submissionUrl 'https://your.domain.com/some/webhook'
Expand All @@ -30,12 +30,22 @@ Then run with:
### Docker

```bash
docker run -d ghcr.io/hotosm/odk-webhook:latest \
docker run -d ghcr.io/hotosm/central-webhook:latest \
-db 'postgresql://{user}:{password}@{hostname}/{db}?sslmode=disable' \
-entityUrl 'https://your.domain.com/some/webhook' \
-submissionUrl 'https://your.domain.com/some/webhook'
```

Environment variables are also supported:

```dotenv
CENTRAL_WEBHOOK_DB_URI=postgresql://user:pass@localhost:5432/db_name?sslmode=disable
CENTRAL_WEBHOOK_ENTITY_URL=https://your.domain.com/some/webhook
CENTRAL_WEBHOOK_SUBMISSION_URL=https://your.domain.com/some/webhook
CENTRAL_WEBHOOK_API_KEY=ksdhfiushfiosehf98e3hrih39r8hy439rh389r3hy983y
CENTRAL_WEBHOOK_LOG_LEVEL=DEBUG
```

> [!NOTE]
> Alternatively, add the service to your docker compose stack.
Expand All @@ -51,8 +61,8 @@ import (
"context"
"log/slog"

"github.com/hotosm/odk-webhook/db"
"github.com/hotosm/odk-webhook/webhook"
"github.com/hotosm/central-webhook/db"
"github.com/hotosm/central-webhook/webhook"
)

ctx := context.Background()
Expand All @@ -78,3 +88,25 @@ if err != nil {
> [!NOTE]
> To not provide a webhook for either entities or submissions,
> pass `nil` instead.
## APIs With Authentication

Many APIs will not be public and require some sort of authentication.

There is an optional `-apiKey` flag that can be used to pass
an API key / token provided by the application.

This will be inserted in the `X-API-Key` request header.

No other authentication methods are supported for now, but feel
free to open an issue (or PR!) for a proposal to support other
auth methods.

Example:

```bash
./centralwebhook \
-db 'postgresql://{user}:{password}@{hostname}/{db}?sslmode=disable' \
-entityUrl 'https://your.domain.com/some/webhook' \
-apiKey 'ksdhfiushfiosehf98e3hrih39r8hy439rh389r3hy983y'
```
15 changes: 7 additions & 8 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ networks:
name: fmtm-splitter

services:
odkhook:
image: "ghcr.io/hotosm/odk-webhook:${TAG_OVERRIDE:-ci}"
webhook:
image: "ghcr.io/hotosm/central-webhook:${TAG_OVERRIDE:-ci}"
build:
target: build
container_name: odkhook
container_name: centralwebhook
volumes:
# Mount local files
- ./go.mod:/app/go.mod:ro
Expand All @@ -21,8 +21,7 @@ services:
- ./parser:/app/parser:ro
# environment:
# # Override to use database on host
# ODK_WEBHOOK_DB_URI: postgresql://odk:[email protected]:5434/odk?sslmode=disable
# ODK_WEBHOOK_WEBHOOK_URL:
# CENTRAL_WEBHOOK_DB_URI: postgresql://odk:[email protected]:5434/odk?sslmode=disable
depends_on:
db:
condition: service_healthy
Expand All @@ -36,18 +35,18 @@ services:

db:
image: "postgis/postgis:17-3.5-alpine"
container_name: odkhook-db
container_name: centralwebhook-db
environment:
- POSTGRES_USER=odk
- POSTGRES_PASSWORD=odk
- POSTGRES_DB=odkhook
- POSTGRES_DB=odk
ports:
- "5439:5432"
networks:
- net
restart: "unless-stopped"
healthcheck:
test: pg_isready -U odk -d odkhook
test: pg_isready -U odk -d odk
start_period: 5s
interval: 10s
timeout: 5s
Expand Down
6 changes: 3 additions & 3 deletions db/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
// with username odk and password odk.
//
// The easiest way to ensure this is to run the tests with docker compose:
// docker compose run --rm odkhook
// docker compose run --rm webhook

func TestNotifier(t *testing.T) {
dbUri := os.Getenv("ODK_WEBHOOK_DB_URI")
dbUri := os.Getenv("CENTRAL_WEBHOOK_DB_URI")
if len(dbUri) == 0 {
// Default
dbUri = "postgresql://odk:odk@db:5432/odkhook?sslmode=disable"
dbUri = "postgresql://odk:odk@db:5432/odk?sslmode=disable"
}

is := is.New(t)
Expand Down
14 changes: 7 additions & 7 deletions db/trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import (
// with username odk and password odk.
//
// The easiest way to ensure this is to run the tests with docker compose:
// docker compose run --rm odkhook
// docker compose run --rm webhook

func TestEntityTrigger(t *testing.T) {
dbUri := os.Getenv("ODK_WEBHOOK_DB_URI")
dbUri := os.Getenv("CENTRAL_WEBHOOK_DB_URI")
if len(dbUri) == 0 {
// Default
dbUri = "postgresql://odk:odk@db:5432/odkhook?sslmode=disable"
dbUri = "postgresql://odk:odk@db:5432/odk?sslmode=disable"
}

is := is.New(t)
Expand Down Expand Up @@ -160,10 +160,10 @@ func TestEntityTrigger(t *testing.T) {

// Test a new submission event type
func TestSubmissionTrigger(t *testing.T) {
dbUri := os.Getenv("ODK_WEBHOOK_DB_URI")
dbUri := os.Getenv("CENTRAL_WEBHOOK_DB_URI")
if len(dbUri) == 0 {
// Default
dbUri = "postgresql://odk:odk@db:5432/odkhook?sslmode=disable"
dbUri = "postgresql://odk:odk@db:5432/odk?sslmode=disable"
}

is := is.New(t)
Expand Down Expand Up @@ -304,10 +304,10 @@ func TestSubmissionTrigger(t *testing.T) {

// Test an unsupported event type and ensure nothing is triggered
func TestNoTrigger(t *testing.T) {
dbUri := os.Getenv("ODK_WEBHOOK_DB_URI")
dbUri := os.Getenv("CENTRAL_WEBHOOK_DB_URI")
if len(dbUri) == 0 {
// Default
dbUri = "postgresql://odk:odk@db:5432/odkhook?sslmode=disable"
dbUri = "postgresql://odk:odk@db:5432/odk?sslmode=disable"
}

is := is.New(t)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/hotosm/odk-webhook
module github.com/hotosm/central-webhook

go 1.23.2

Expand Down
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (

"github.com/jackc/pgx/v5/pgxpool"

"github.com/hotosm/odk-webhook/db"
"github.com/hotosm/odk-webhook/parser"
"github.com/hotosm/odk-webhook/webhook"
"github.com/hotosm/central-webhook/db"
"github.com/hotosm/central-webhook/parser"
"github.com/hotosm/central-webhook/webhook"
)

func getDefaultLogger(lvl slog.Level) *slog.Logger {
Expand Down Expand Up @@ -130,10 +130,10 @@ func main() {
ctx := context.Background()

// Read environment variables
defaultDbUri := os.Getenv("ODK_WEBHOOK_DB_URI")
defaultEntityUrl := os.Getenv("ODK_WEBHOOK_ENTITY_URL")
defaultSubmissionUrl := os.Getenv("ODK_WEBHOOK_SUBMISSION_URL")
defaultLogLevel := os.Getenv("ODK_WEBHOOK_LOG_LEVEL")
defaultDbUri := os.Getenv("CENTRAL_WEBHOOK_DB_URI")
defaultEntityUrl := os.Getenv("CENTRAL_WEBHOOK_ENTITY_URL")
defaultSubmissionUrl := os.Getenv("CENTRAL_WEBHOOK_SUBMISSION_URL")
defaultLogLevel := os.Getenv("CENTRAL_WEBHOOK_LOG_LEVEL")

var dbUri string
flag.StringVar(&dbUri, "db", defaultDbUri, "DB host (postgresql://{user}:{password}@{hostname}/{db}?sslmode=disable)")
Expand Down Expand Up @@ -165,7 +165,7 @@ func main() {
flag.PrintDefaults()
os.Exit(1)
}

if entityUrl == "" && submissionUrl == "" {
fmt.Fprintf(os.Stderr, "At least one of entityUrl or submissionUrl is required\n")
flag.PrintDefaults()
Expand Down
8 changes: 4 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ package main

// "github.com/matryer/is"

// "github.com/hotosm/odk-webhook/parser"
// "github.com/hotosm/odk-webhook/db"
// "github.com/hotosm/central-webhook/parser"
// "github.com/hotosm/central-webhook/db"
// )

// func TestSetupWebhook(t *testing.T) {
// dbUri := os.Getenv("ODK_WEBHOOK_DB_URI")
// dbUri := os.Getenv("CENTRAL_WEBHOOK_DB_URI")
// if len(dbUri) == 0 {
// // Default
// dbUri = "postgresql://odk:odk@db:5432/odkhook?sslmode=disable"
// dbUri = "postgresql://odk:odk@db:5432/odk?sslmode=disable"
// }

// is := is.New(t)
Expand Down
Binary file added odkhook
Binary file not shown.
2 changes: 1 addition & 1 deletion webhook/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http"
"time"

"github.com/hotosm/odk-webhook/parser"
"github.com/hotosm/central-webhook/parser"
)

// SendRequest parses the request content JSON from the PostgreSQL notification
Expand Down
2 changes: 1 addition & 1 deletion webhook/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/matryer/is"

"github.com/hotosm/odk-webhook/parser"
"github.com/hotosm/central-webhook/parser"
)

func TestSendRequest(t *testing.T) {
Expand Down

0 comments on commit e2c21e1

Please sign in to comment.