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
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.23-alpine AS builder
FROM golang:1.25-alpine AS builder

WORKDIR /app

Expand All @@ -8,10 +8,11 @@ RUN go mod verify

COPY . .

RUN cd server && go build -o /app/main .
RUN CGO_ENABLED=0 go build -o /app/main ./server

FROM scratch

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /app/main /app/main

ENTRYPOINT ["/app/main"]
22 changes: 21 additions & 1 deletion server/mongo/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mongo
import (
"context"
"errors"
"strings"

"github.com/botsman/tppVerifier/app/cert"
"github.com/botsman/tppVerifier/app/db"
Expand All @@ -22,10 +23,29 @@ func NewMongoRepo(ctx context.Context, connStr string) (db.TppRepository, error)
if err != nil {
return nil, err
}
db := client.Database(opts.Auth.AuthSource)
dbName, err := extractDatabaseName(connStr)
if err != nil {
return nil, err
}
if dbName == "" {
return nil, errors.New("database name is required in connection string")
}
db := client.Database(dbName)
return &TppMongoRepository{db: db}, nil
}

func extractDatabaseName(connStr string) (string, error) {
opts := options.Client().ApplyURI(connStr)
if opts.Auth != nil && opts.Auth.AuthSource != "" {
return opts.Auth.AuthSource, nil
}
connStrParts := strings.Split(connStr, "/")
if len(connStrParts) < 2 {
return "", errors.New("database name not found in connection string")
}
return connStrParts[len(connStrParts)-1], nil
}

type TppMongoRepository struct {
db *mongo.Database
}
Expand Down
3 changes: 0 additions & 3 deletions tools/tppdb/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,12 @@ func parseRegistry() (<-chan models.TPP, error) {
for _, tpps := range registry {
for _, rawTpp := range tpps {
if rawTpp.CA_OwnerID == "" || rawTpp.Code == "" {
// log.Printf("Skipping TPP with missing CA_OwnerID or Code: %+v\n", rawTpp)
continue
}
if rawTpp.Type == "" {
// log.Printf("Skipping TPP with missing Type: %+v\n", rawTpp)
continue
}
if rawTpp.AuthorizedAt == nil || rawTpp.AuthorizedAt.IsZero() {
// log.Printf("Skipping TPP with missing AuthorizedAt: %+v\n", rawTpp)
continue
}
if !slices.Contains([]string{"PSD_AISP", "PSD_PI", "PSD_EMI"}, rawTpp.Type) {
Expand Down
10 changes: 5 additions & 5 deletions tools/tppdb/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func Run(ctx context.Context, connStr string) error {
// 3. Unzip the file
// 4. Parse the file
// 5. Save the parsed data to the DB
client, err := setupMongoDb(ctx, connStr)
// client, err := setupSqliteDb(ctx, connStr)
if err != nil {
return err
}

getRegistry()
defer deleteRegistry()
Expand All @@ -27,11 +32,6 @@ func Run(ctx context.Context, connStr string) error {
if err != nil {
return err
}
client, err := setupMongoDb(ctx, connStr)
// client, err := setupSqliteDb(ctx, connStr)
if err != nil {
return err
}
defer client.Disconnect(ctx)
return saveTPPs(client, tppChan)
}