Skip to content
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
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# syntax=docker/dockerfile:1

FROM golang:1.22.2

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY auth ./auth
COPY config ./config
COPY db ./db
COPY docs ./docs
COPY handlers ./handlers
COPY models ./models
COPY services ./services
COPY setup ./setup
COPY utils ./utils
COPY webhooks ./webhooks
COPY data ./data
COPY web-ui ./web-ui
COPY config.yaml key.pem cert.pem main.go rsakey.pem build.sh run.sh ./

RUN CGO_ENABLED=1 GOOS=linux go build -o dingus-server

# Optional:
# To bind to a TCP port, runtime parameters must be supplied to the docker command.
# But we can document in the Dockerfile what ports
# the application is going to listen on by default.
# https://docs.docker.com/reference/dockerfile/#expose
EXPOSE 443

# Run
CMD ["/app/run.sh"]
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,28 @@ This project is an RFID access control system's backend server written in Golang
- `web-ui`: Frontend assets.

## Getting Started
### Docker
#### Build
`docker-compose build`
#### Run Interactive
`docker-compose up`

### Prerequisites
`ctrl-c` to stop.

#### Run in background (Detached)
`docker-compose up -d`
#### Stop
`docker-compose down`

### Native
#### Prerequisites

- [Go](https://go.dev/doc/install) (latest stable version)
- Access to [Wild Apricot API](https://gethelp.wildapricot.com/en/articles/182-using-wildapricot-s-api)
- SSL certificate and key
- GCC for SQLite Go package compilation (requires cgo)

### Setting CGO_ENABLED
#### Setting CGO_ENABLED

To successfully build and run this project, `CGO_ENABLED` must be set to `1`. This allows for the compilation of C code, a requirement for the SQLite package used in the project.

Expand Down
12 changes: 12 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

export WILD_APRICOT_API_KEY=ilyglbbwzai5suuxt4nai0kqx5evvh
export WILD_APRICOT_WEBHOOK_TOKEN=08a7gv08abwDYGd77cxv980asdfy98zxc87
export WILD_APRICOT_SSO_CLIENT_ID=t8jw60pj3f
export WILD_APRICOT_SSO_CLIENT_SECRET=5k8nct39ootl8wt0gkpxe22v8phi5a
export WILD_APRICOT_SSO_REDIRECT_URI=/replaceme
export LOG_LEVEL=INFO
export COOKIE_STORE_SECRET=cookiestoresecret
export CGO_ENABLED=1
export GOOS=linux
/usr/local/go/bin/go build -o dingus-server
5 changes: 5 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
dingus-server:
build: .
ports:
- "443:443"
6 changes: 3 additions & 3 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cert_file: .ssh/id_rsa/dev_pubkey.pem
cert_file: cert.pem
contact_filter_query: "(Status eq Active or Status eq PendingRenewal) and 'Door Key' ne NULL"
database_path: db/data/tagsdb.sqlite
key_file: .ssh/id_rsa/dev_secret.pem
database_path: data/tagsdb.sqlite
key_file: key.pem
tag_id_field_name: Door Key
training_field_name: Safety Training
wild_apricot_account_id: 232582
5 changes: 0 additions & 5 deletions db/data/.gitignore

This file was deleted.

4 changes: 2 additions & 2 deletions models/wildApricotContact.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ func (c *Contact) ExtractContactData(cfg *config.Config) (int, uint32, []string,

trainingLabels, err := c.ExtractTrainingLabels(cfg)
if err != nil {
return 0, 0, nil, fmt.Errorf("error extracting training labels for contact %d: %v", c.Id, err)
err = fmt.Errorf("error extracting training labels for contact %d: %v", c.Id, err)
}

return c.Id, tagID, trainingLabels, nil
return c.Id, tagID, trainingLabels, err
}

func parseTagId(fieldValue FieldValue) (uint32, error) {
Expand Down
12 changes: 12 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

export WILD_APRICOT_API_KEY=ilyglbbwzai5suuxt4nai0kqx5evvh
export WILD_APRICOT_WEBHOOK_TOKEN=08a7gv08abwDYGd77cxv980asdfy98zxc87
export WILD_APRICOT_SSO_CLIENT_ID=t8jw60pj3f
export WILD_APRICOT_SSO_CLIENT_SECRET=5k8nct39ootl8wt0gkpxe22v8phi5a
export WILD_APRICOT_SSO_REDIRECT_URI=/replaceme
export LOG_LEVEL=INFO
export COOKIE_STORE_SECRET=cookiestoresecret
export CGO_ENABLED=1
export GOOS=linux
./dingus-server
4 changes: 3 additions & 1 deletion services/dbService.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ func (s *DBService) ProcessContactsData(contacts []models.Contact) error {
for _, contact := range contacts {
contactId, tagId, trainingLabels, err := contact.ExtractContactData(s.cfg)
if err != nil {
return err
// output the error and save any data that was retrieved.
s.log.Error(err)
}

if contactId != 0 && tagId != 0 {
Expand Down Expand Up @@ -167,6 +168,7 @@ func (s *DBService) ProcessContactsData(contacts []models.Contact) error {
tx.Rollback()
return err
}

return tx.Commit()
}

Expand Down
4 changes: 2 additions & 2 deletions services/wildApricotService.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"rfid-backend/config"
Expand Down Expand Up @@ -47,7 +46,7 @@ func NewWildApricotService(cfg *config.Config, logger *logrus.Logger) *WildApric

func readResponseBody(resp *http.Response) ([]byte, error) {
defer resp.Body.Close()
return ioutil.ReadAll(resp.Body)
return io.ReadAll(resp.Body)
}

func handleHTTPError(resp *http.Response) error {
Expand Down Expand Up @@ -169,6 +168,7 @@ func (s *WildApricotService) GetContacts() ([]models.Contact, error) {
}

s.log.Infof("Parsed %d contacts from response", len(contacts))

return contacts, nil
}

Expand Down
Loading