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
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ 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
ENV CGO_ENABLED=1
ENV GOOS=linux

RUN go build -o dingus-server

# Optional:
# To bind to a TCP port, runtime parameters must be supplied to the docker command.
Expand All @@ -31,5 +34,7 @@ RUN CGO_ENABLED=1 GOOS=linux go build -o dingus-server
# https://docs.docker.com/reference/dockerfile/#expose
EXPOSE 443



# Run
CMD ["/app/run.sh"]
5 changes: 3 additions & 2 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: dingus
services:
dingus-server:
server:
build: .
ports:
- "443:443"
- "443:443"
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ key_file: key.pem
tag_id_field_name: Door Key
training_field_name: Safety Training
wild_apricot_account_id: 232582
poll_time_mins: 1
29 changes: 18 additions & 11 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ var (
)

type Config struct {
CertFile string `mapstructure:"cert_file" json:"cert_file"`
DatabasePath string `mapstructure:"database_path" json:"database_path"`
KeyFile string `mapstructure:"key_file" json:"key_file"`
TagIdFieldName string `mapstructure:"tag_id_field_name" json:"tag_id_field_name"`
TrainingFieldName string `mapstructure:"training_field_name" json:"training_field_name"`
WildApricotAccountId int `mapstructure:"wild_apricot_account_id" json:"wild_apricot_account_id"`
ContactFilterQuery string `mapstructure:"contact_filter_query" json:"contact_filter_query"`
SSOClientID string `mapstructure:"sso_client_id" json:"sso_client_id"`
SSOClientSecret string `mapstructure:"sso_client_secret" json:"sso_client_secret"`
SSORedirectURI string `mapstructure:"sso_redirect_uri" json:"sso_redirect_uri"`
CookieStoreSecret string `mapstructure:"cookie_store_secret" json:"cookie_store_secret"`
CertFile string `mapstructure:"cert_file" json:"cert_file"`
DatabasePath string `mapstructure:"database_path" json:"database_path"`
KeyFile string `mapstructure:"key_file" json:"key_file"`
TagIdFieldName string `mapstructure:"tag_id_field_name" json:"tag_id_field_name"`
TrainingFieldName string `mapstructure:"training_field_name" json:"training_field_name"`
WildApricotAccountId int `mapstructure:"wild_apricot_account_id" json:"wild_apricot_account_id"`
ContactFilterQuery string `mapstructure:"contact_filter_query" json:"contact_filter_query"`
SSOClientID string `mapstructure:"sso_client_id" json:"sso_client_id"`
SSOClientSecret string `mapstructure:"sso_client_secret" json:"sso_client_secret"`
SSORedirectURI string `mapstructure:"sso_redirect_uri" json:"sso_redirect_uri"`
CookieStoreSecret string `mapstructure:"cookie_store_secret" json:"cookie_store_secret"`
PollTimeMins float32 `mapstructure:"poll_time_mins" json:"poll_time_mins" default:"5.0"`
WildApricotApiKey string
WildApricotWebhookToken string
RFIDFieldName string
Expand Down Expand Up @@ -60,10 +61,16 @@ func loadConfig() interface{} {
}

var cfg Config

// Set default values
cfg.PollTimeMins = 10.0

if err := viper.Unmarshal(&cfg); err != nil {
log.Fatalf("Error unmarshalling config file: %s", err)
}

log.Printf("poll_time_mins: %.1f", cfg.PollTimeMins)

// Resolve relative paths
cfg.CertFile = filepath.Join(projectRoot, cfg.CertFile)
if _, err := os.Stat(cfg.CertFile); os.IsNotExist(err) {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func main() {
waService := services.NewWildApricotService(cfg, logger)
dbService := services.NewDBService(db, cfg, logger)

setup.StartBackgroundDatabaseUpdate(waService, dbService, logger)
setup.StartBackgroundDatabaseUpdate(waService, dbService, cfg, logger)

err = router.RunTLS(":443", cfg.CertFile, cfg.KeyFile)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export WILD_APRICOT_WEBHOOK_TOKEN=08a7gv08abwDYGd77cxv980asdfy98zxc87
export WILD_APRICOT_SSO_CLIENT_ID=654628fgDFc68hH
export WILD_APRICOT_SSO_CLIENT_SECRET=07pb835b7pw3s8r0qrvmtlipuwjtt6
export WILD_APRICOT_SSO_REDIRECT_URI=https://dingus.hackpgh.org/web-ui/home
#export WILD_APRICOT_SSO_REDIRECT_URI=https://localhost/web-ui/home
export LOG_LEVEL=INFO
export COOKIE_STORE_SECRET=cookiestoresecret
export CGO_ENABLED=1
Expand Down
5 changes: 3 additions & 2 deletions setup/setupBackgroundSync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
package setup

import (
"rfid-backend/config"
"rfid-backend/services"
"time"

"github.com/sirupsen/logrus"
)

func StartBackgroundDatabaseUpdate(waService *services.WildApricotService, dbService *services.DBService, logger *logrus.Logger) {
func StartBackgroundDatabaseUpdate(waService *services.WildApricotService, dbService *services.DBService, cfg *config.Config, logger *logrus.Logger) {
go func() {
updateEntireDatabaseFromWildApricot(waService, dbService, logger)
ticker := time.NewTicker(30 * time.Minute)
ticker := time.NewTicker(time.Duration(cfg.PollTimeMins) * time.Minute)
for range ticker.C {
updateEntireDatabaseFromWildApricot(waService, dbService, logger)
}
Expand Down