Skip to content

Commit

Permalink
Merge pull request #64 from eurofurence/issue-33-flesh-out
Browse files Browse the repository at this point in the history
Issue 33 flesh out
  • Loading branch information
Jumpy-Squirrel authored May 26, 2024
2 parents 6883eea + 8cd5b1c commit 13e024e
Show file tree
Hide file tree
Showing 46 changed files with 656 additions and 550 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '^1.21.2'
go-version: '^1.22.2'

- name: Build
run: go build -v ./...
Expand Down
9 changes: 3 additions & 6 deletions cmd/reg-room-service/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"log"
"os"

"github.com/urfave/cli/v2"
Expand All @@ -15,9 +14,7 @@ var (
)

func main() {
// TODO perform initialization

app := &cli.App{
application := &cli.App{
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Expand All @@ -41,7 +38,7 @@ func main() {
},
}

if err := app.Run(os.Args); err != nil {
log.Fatal(err)
if err := application.Run(os.Args); err != nil {
os.Exit(1)
}
}
2 changes: 1 addition & 1 deletion docs/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go_live:
staff:
start_iso_datetime: 1995-06-29T11:11:11+02:00
booking_code: Dithmarschen
staff_role: staff
group: staff
security:
cors:
disable: false
Expand Down
19 changes: 15 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ type (
Database DatabaseConfig `yaml:"database"`
Security SecurityConfig `yaml:"security"`
Logging LoggingConfig `yaml:"logging"`
GoLive map[string]any `yaml:"go_live"` // TODO do we want to keep the countdown functionality
GoLive GoLiveConfig `yaml:"go_live"`
}

// ServiceConfig contains configuration values
// for service related tasks. E.g. URL to payment provider adapter.
// for service related tasks. E.g. URL to attendee service.
ServiceConfig struct {
PublicBookingCode string `yaml:"public_booking_code"`
AttendeeServiceURL string `yaml:"attendee_service_url"`
}

// ServerConfig contains all values for
// http releated configuration.
ServerConfig struct {
BaseAddress string `yaml:"address"`
Port string `yaml:"port"`
Port int `yaml:"port"`
ReadTimeout int `yaml:"read_timeout_seconds"`
WriteTimeout int `yaml:"write_timeout_seconds"`
IdleTimeout int `yaml:"idle_timeout_seconds"`
Expand Down Expand Up @@ -93,6 +93,17 @@ type (
Style LogStyle `yaml:"style"`
Severity string `yaml:"severity"`
}

GoLiveConfig struct {
Public GoLiveConfigPerGroup `yaml:"public"`
Staff GoLiveConfigPerGroup `yaml:"staff"`
}

GoLiveConfigPerGroup struct {
StartISODatetime string `yaml:"start_iso_datetime"`
BookingCode string `yaml:"booking_code"`
Group string `yaml:"group"`
}
)

// UnmarshalFromYamlConfiguration decodes yaml data from an `io.Reader` interface.
Expand Down
7 changes: 7 additions & 0 deletions internal/config/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package config

func (c *Config) AddDefaults() {
if c.Server.Port == 0 {
c.Server.Port = 8081
}
}
23 changes: 23 additions & 0 deletions internal/config/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package config

import (
"errors"
aulogging "github.com/StephanHCB/go-autumn-logging"
)

func (c *Config) Validate() error {
ok := true

if c.Server.Port <= 1024 || c.Server.Port > 65535 {
aulogging.Logger.NoCtx().Warn().Print("server.port out of range")
ok = false
}

// TODO more validation

if ok {
return nil
} else {
return errors.New("configuration validation error, see log output for details")
}
}
126 changes: 0 additions & 126 deletions internal/logging/logging.go

This file was deleted.

28 changes: 0 additions & 28 deletions internal/logging/logging_test.go

This file was deleted.

6 changes: 4 additions & 2 deletions internal/repository/downstreams/attendeeservice/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ var (
type AttendeeService interface {
// ListMyRegistrationIds which attendee ids belong to the current user?
//
// If your request was made by an admin or with the api token, this will fail and should not be called.
// Admin and api token can view all groups and rooms anyway.
// If your request was made with an api token, this will fail and should not be called.
//
// Admins are treated like normal users for this request, and will also only receive badge numbers
// they have personally registered.
//
// Forwards the jwt from the request.
ListMyRegistrationIds(ctx context.Context) ([]int64, error)
Expand Down
85 changes: 85 additions & 0 deletions internal/repository/downstreams/attendeeservice/mock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package attendeeservice

import (
"context"
"errors"
"github.com/eurofurence/reg-room-service/internal/repository/downstreams"
"github.com/eurofurence/reg-room-service/internal/web/common"
)

type Mock interface {
AttendeeService

Reset()
Unavailable()
SetupRegistered(subject string, badgeNo int64, status Status)
}

type MockImpl struct {
IdsBySubject map[string][]int64
StatusById map[int64]Status
IsUnavailable bool
}

func NewMock() Mock {
instance := &MockImpl{}
instance.Reset()
return instance
}

func (m *MockImpl) ListMyRegistrationIds(ctx context.Context) ([]int64, error) {
if m.IsUnavailable {
return make([]int64, 0), downstreams.ErrDownStreamUnavailable
}

claimsPtr := ctx.Value(common.CtxKeyClaims{})
if claimsPtr == nil {
// no auth -> no badge numbers, but also not an error
return make([]int64, 0), nil
}
claims, ok := claimsPtr.(*common.AllClaims)
if !ok {
return make([]int64, 0), errors.New("internal error - found invalid data type in context - this indicates a bug")
}

subject := claims.Subject
if subject == "" {
return make([]int64, 0), errors.New("invalid authentication in context, lacks subject - probably indicates a bug")
}

ids, ok := m.IdsBySubject[subject]
if !ok {
// not known -> no badge numbers, but also not an error
return make([]int64, 0), nil
}

return ids, nil
}

func (m *MockImpl) GetStatus(ctx context.Context, id int64) (Status, error) {
if m.IsUnavailable {
return StatusDeleted, downstreams.ErrDownStreamUnavailable
}

status, ok := m.StatusById[id]
if !ok {
return StatusDeleted, nil
}

return status, nil
}

func (m *MockImpl) Reset() {
m.IdsBySubject = make(map[string][]int64)
m.StatusById = make(map[int64]Status)
m.IsUnavailable = false
}

func (m *MockImpl) Unavailable() {
m.IsUnavailable = true
}

func (m *MockImpl) SetupRegistered(subject string, badgeNo int64, status Status) {
m.IdsBySubject[subject] = []int64{badgeNo}
m.StatusById[badgeNo] = status
}
Loading

0 comments on commit 13e024e

Please sign in to comment.