Skip to content

Commit 5830506

Browse files
committed
Add signature verification of access token
1 parent cbeb55f commit 5830506

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1398
-957
lines changed

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
8+
{
9+
"name": "ISBETMF",
10+
"type": "go",
11+
"request": "launch",
12+
"mode": "auto",
13+
"program": "cmd/isbetmf/main.go",
14+
"args": ["-d"]
15+
}
16+
]
17+
}

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Build stage
2+
FROM golang:1.24.2-alpine AS builder
3+
4+
# Install build tools for CGO
5+
RUN apk add --no-cache gcc musl-dev
6+
7+
WORKDIR /app
8+
9+
# Copy go.mod and go.sum files to download dependencies
10+
COPY go.mod go.sum ./
11+
RUN go mod download
12+
13+
# Copy the rest of the source code
14+
COPY . .
15+
16+
# Build the binary with CGO enabled
17+
# -ldflags="-w -s" strips debug information and symbols, reducing the binary size
18+
RUN go build -ldflags="-w -s" -o /isbetmf ./cmd/isbetmf
19+
20+
# Final stage
21+
FROM alpine:latest
22+
23+
WORKDIR /
24+
COPY --from=builder /isbetmf /isbetmf
25+
COPY www /www
26+
27+
28+
# Expose the port the server runs on
29+
EXPOSE 9991
30+
31+
# Run the binary
32+
ENTRYPOINT ["/isbetmf"]
File renamed without changes.
32 KB
Binary file not shown.

cmd/isbetmf/isbetmf.db-wal

28.2 KB
Binary file not shown.

cmd/isbeserver/main.go renamed to cmd/isbetmf/main.go

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@ import (
77
"log/slog"
88

99
"github.com/gofiber/fiber/v2"
10-
echohandler "github.com/hesusruiz/isbetmf/tmfserver/handler/echo"
10+
"github.com/hesusruiz/isbetmf/pdp"
1111
fiberhandler "github.com/hesusruiz/isbetmf/tmfserver/handler/fiber"
1212
repository "github.com/hesusruiz/isbetmf/tmfserver/repository"
1313
service "github.com/hesusruiz/isbetmf/tmfserver/service"
1414
"github.com/jmoiron/sqlx"
15-
"github.com/labstack/echo/v4"
1615
_ "github.com/mattn/go-sqlite3"
1716
"gitlab.com/greyxor/slogor"
1817
)
1918

2019
func main() {
2120
// Configure slog logger
2221
var debugFlag bool
22+
var verifierServer string
2323
flag.BoolVar(&debugFlag, "d", false, "Enable debug logging")
24+
flag.StringVar(&verifierServer, "verifier", "https://verifier.dome-marketplace.eu", "Full URL of the verifier which signs access tokens")
2425
flag.Parse()
2526

2627
var logLevel slog.Level
@@ -30,11 +31,11 @@ func main() {
3031
logLevel = slog.LevelInfo
3132
}
3233

33-
handler := slogor.NewHandler(os.Stdout, slogor.SetLevel(logLevel))
34+
handler := slogor.NewHandler(os.Stdout, slogor.ShowSource(), slogor.SetLevel(logLevel))
3435
slog.SetDefault(slog.New(handler))
3536

3637
// Connect to the database
37-
db, err := sqlx.Connect("sqlite3", "tmf.db")
38+
db, err := sqlx.Connect("sqlite3", "isbetmf.db")
3839
if err != nil {
3940
slog.Error("failed to connect to database", slog.Any("error", err))
4041
os.Exit(1)
@@ -48,27 +49,31 @@ func main() {
4849
os.Exit(1)
4950
}
5051

52+
// Create the PDP (aka rules engine)
53+
rulesEngine, err := pdp.NewPDP(&pdp.Config{
54+
PolicyFileName: "auth_policies.star",
55+
VerifierServer: verifierServer,
56+
Debug: debugFlag,
57+
})
58+
if err != nil {
59+
slog.Error("failed to create rules engine", slog.Any("error", err))
60+
os.Exit(1)
61+
}
62+
5163
// Create the service
52-
s := service.NewService(db)
64+
s := service.NewService(db, rulesEngine, verifierServer)
65+
66+
app := fiber.New()
67+
68+
// Serve the OpenAPI UI
69+
app.Static("/oapi", "./www/oapiui")
5370

54-
// Create and run the Fiber server
55-
go func() {
56-
app := fiber.New()
57-
h := fiberhandler.NewHandler(s)
58-
h.RegisterRoutes(app)
59-
slog.Info("Fiber server starting", slog.String("port", ":9991"))
60-
app.Listen(":9991")
61-
}()
71+
// Create handler and set the routes for the APIs
72+
h := fiberhandler.NewHandler(s)
73+
h.RegisterRoutes(app)
6274

63-
// Create and run the Echo server
64-
go func() {
65-
e := echo.New()
66-
h := echohandler.NewHandler(s)
67-
h.RegisterRoutes(e)
68-
slog.Info("Echo server starting", slog.String("port", ":9992"))
69-
e.Logger.Fatal(e.Start(":9992"))
70-
}()
75+
// And start the server
76+
slog.Info("TMF API server starting", slog.String("port", ":9991"))
77+
app.Listen("0.0.0.0:9991")
7178

72-
// Wait indefinitely
73-
select {}
7479
}

config/config.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import (
1717

1818
type Config struct {
1919

20-
// DOME operator did
21-
// TODO: set the proper identification when the DOME foundation is created
22-
DOMEOperatorDid string
23-
DOMEOperatorName string
20+
// Server operator did
21+
// TODO: set the proper identification when the legal entity operating the server is created
22+
ServerOperatorDid string
23+
ServerOperatorName string
2424

2525
// Indicates the environment (SBX, DEV2, PRO, LCL) where the proxy is running.
2626
// It is used to determine the DOME host and the database name.
@@ -86,8 +86,10 @@ type Config struct {
8686

8787
// TODO: These are here until the DOME foundation is created and the DOME operator did is set.
8888
const (
89-
DOMEOperatorDid = "did:elsi:VATES-11111111K"
90-
DOMEOperatorName = "DOME Foundation"
89+
ServerOperatorOrganizationIdentifier = "VATES-11111111K"
90+
ServerOperatorDid = "did:elsi:VATES-11111111K"
91+
ServerOperatorName = "ISBE Foundation"
92+
ServerOperatorCountry = "ES"
9193
)
9294

9395
type Environment int

config/errorlocation.txt

Lines changed: 0 additions & 78 deletions
This file was deleted.

config/multimessage.txt

Lines changed: 0 additions & 56 deletions
This file was deleted.

docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
isbetmf:
3+
build: .
4+
ports:
5+
- "9991:9991"
6+
environment:
7+
- MY_ENV_VAR=some_value

0 commit comments

Comments
 (0)